Skip to content

Instantly share code, notes, and snippets.

@novemberalpha
Created May 18, 2017 18:49
Show Gist options
  • Save novemberalpha/211e3d35ed7c9be834d41a9201f244d5 to your computer and use it in GitHub Desktop.
Save novemberalpha/211e3d35ed7c9be834d41a9201f244d5 to your computer and use it in GitHub Desktop.
A recipe generator version to create recipes for the PFC1
import json
import operator
### Set parameters #############################################################
recipe_name = 'Tangerine-air-flush-cooling-2'
recipe_format = 'simple'
cycles = 7 # cycles
day_length = 12 # hours
light_intensity = 1 # 1 for on, 0 for off
night_length = 12 # hours
day_air_temperature = 27 # C
night_air_temperature = 22 # C
day_air_humidity = 60 # %
night_air_humidity = 40 # %
air_flush_on_number_per_day = 16 # times / day
air_flush_on_day_length = 10 # minutes
air_flush_on_number_per_night = 8 # times / night
air_flush_on_night_length = 10 # minutes
ph = None # pH
nutrient_a_number_per_day = None # times / day
nutrient_a_volume = 5 # mL
nutrient_b_number_per_day = None # times / day
nutrient_b_volume = 5 # mL
################################################################################
# Generate recipe
recipe = {}
recipe['_id'] = recipe_name
recipe['format'] = recipe_format
recipe['operations'] = []
if ph is not None:
recipe['operations'].append([0, 'water_potential_hydrogen', ph])
for i in range(cycles):
# Set day & night start times
day_start_time = (day_length + night_length) * 3600 * i
night_start_time = day_start_time + day_length * 3600
# Set day parameters
recipe['operations'].append([day_start_time, 'light_intensity', light_intensity])
if day_air_temperature != None:
recipe['operations'].append([day_start_time, 'air_temperature', day_air_temperature])
if day_air_humidity != None:
recipe['operations'].append([day_start_time, 'air_humidity', day_air_humidity])
# Set air flush
if air_flush_on_number_per_day != None:
for i in range(air_flush_on_number_per_day):
time = day_start_time + day_length * 3600 / air_flush_on_number_per_day * i
recipe['operations'].append([time, 'air_flush_on', 0]) # Air flush firmware only turns on for new value duation if new value is different than prev
recipe['operations'].append([time + 10, 'air_flush_on', air_flush_on_day_length]) # Send real value after setting flush to 0 for 10 sec
recipe['operations'].append([time + 20, 'air_flush_on', 0]) # Kludge for when arduino resets, don't resend values
# Set nutrient a
if nutrient_a_number_per_day != None:
for i in range(nutrient_a_number_per_day):
time = day_start_time + day_length * 3600 / nutrient_a_number_per_day * i
recipe['operations'].append([time, 'nutrient_flora_duo_a', 0]) # Pump firmware only doses volume if new value is different than prev
recipe['operations'].append([time + 10, 'nutrient_flora_duo_a', nutrient_a_volume]) # Send real value after setting volume to 0 for 10 sec
recipe['operations'].append([time + 20, 'nutrient_flora_duo_a', 0]) # Kludge for when arduino resets, don't resend values
# Set nutrient b
if nutrient_b_number_per_day != None:
for i in range(nutrient_b_number_per_day):
time = day_start_time + day_length * 3600 / nutrient_b_number_per_day * i
recipe['operations'].append([time, 'nutrient_flora_duo_b', 0]) # Pump firmware only doses volume if new value is different than prev
recipe['operations'].append([time + 10, 'nutrient_flora_duo_b', nutrient_b_volume]) # Send real value after setting volume to 0 for 10 sec
recipe['operations'].append([time + 20, 'nutrient_flora_duo_b', 0]) # Kludge for when arduino resets, don't resend values
# Set night parameters
recipe['operations'].append([night_start_time, 'light_intensity', 0])
if night_air_temperature is not None:
recipe['operations'].append([night_start_time, 'air_temperature', night_air_temperature])
if night_air_humidity != None:
recipe['operations'].append([night_start_time, 'air_humidity', night_air_humidity])
if air_flush_on_number_per_night != None:
for i in range(air_flush_on_number_per_night):
time = night_start_time + night_length * 3600 / air_flush_on_number_per_night * i
recipe['operations'].append([time, 'air_flush_on', 0]) # Air flush only sets new value if different than prev
recipe['operations'].append([time + 10, 'air_flush_on', air_flush_on_night_length]) # Send real value after setting flush to 0 for 10 sec
recipe['operations'].append([time + 20, 'air_flush_on', 0]) # Kludge for when arduino resets, don't resend values
# Sort recipe so timeseries is linear
recipe['operations'] = sorted(recipe['operations'], key=operator.itemgetter(0))
# Write recipe to file
f = open('{}.json'.format(recipe_name), 'w')
f.write(json.dumps(recipe, indent=4, sort_keys=True))
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment