You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.4 KiB
42 lines
1.4 KiB
4 years ago
|
from services import post_services, get_services
|
||
|
|
||
|
'''
|
||
|
API Functions
|
||
|
======================================================================
|
||
|
These functions are what are exposed/referenced in the swagger.yml
|
||
|
file -- they are essentially wrapper functions. The main work is done
|
||
|
in the files in the /services/ folder.
|
||
|
These functions are acting as very light controllers essentially.
|
||
|
'''
|
||
|
|
||
|
# The each value represents a light meter.
|
||
|
READINGS = [0, 0, 0]
|
||
|
|
||
|
def post_a_reading(light_meter, the_reading):
|
||
|
if light_meter == 1:
|
||
|
READINGS[0] = the_reading.get("reading")
|
||
|
elif light_meter == 2:
|
||
|
READINGS[1] = the_reading.get("reading")
|
||
|
elif light_meter == 3:
|
||
|
READINGS[2] = the_reading.get("reading")
|
||
|
return post_services.add_latest_reading(light_meter,the_reading)
|
||
|
|
||
|
def get_latest(light_meter):
|
||
|
# YOU ARE UP TO HERE. NEED TO REFACTOR BACK INTO DATABASE FUNCTION
|
||
|
# BELOW THIS FUNCTION. YAML FILE NEEDS CLEANING UP TOO.
|
||
|
if light_meter == 1:
|
||
|
return READINGS[0]
|
||
|
elif light_meter == 2:
|
||
|
return READINGS[1]
|
||
|
elif light_meter == 3:
|
||
|
return READINGS[2]
|
||
|
|
||
|
def get_latest_reading(light_meter):
|
||
|
return get_services.get_in_mem_reading(light_meter)
|
||
|
|
||
|
def get_all_readings(light_meter):
|
||
|
return get_services.get_all_readings_from_table(light_meter)
|
||
|
|
||
|
def get_all_readings_for_every_meter():
|
||
|
return get_services.get_all_readings_from_database()
|