1
0
Fork 0
Browse Source

remove in-mem readings and refactor related items.

pull/7/head
Craig Oates 4 years ago
parent
commit
312bcd70a6
  1. 25
      app/api.py
  2. 4
      app/services/get_services.py
  3. 36
      app/swagger.yml

25
app/api.py

@ -9,30 +9,11 @@ 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)
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)
return get_services.get_latest_reading(light_meter)
def get_all_readings(light_meter):
return get_services.get_all_readings_from_table(light_meter)

4
app/services/get_services.py

@ -12,9 +12,7 @@ at Ritherdon, you will need to head to the /post_services.py/ file.
It should be in the same directory at this: /services/.
'''
def get_in_mem_reading(meter):
# Need to refactor in use an in-mem database.
# Currently grabbing from database.
def get_latest_reading(meter):
if meter == 1:
return get_m1_latest()
elif meter == 2:

36
app/swagger.yml

@ -74,7 +74,7 @@ paths:
/readings/latest/{light_meter}:
get:
operationId: api.get_latest_reading
operationId: api.get_latest
tags:
- Request Readings
summary: >-
@ -200,37 +200,3 @@ paths:
schema:
type: object
additionalProperties: True
# This is the in-mem. database URL.
/readings/late/{light_meter}:
get:
operationId: api.get_latest
tags:
- Request Readings
summary: >-
Returns latest from in-mem database.
description: >-
latest in-mem db reading
parameters:
- name: light_meter
in: path
description: >-
This is the Id. of the light meter which you are retrieving
the readings for. The Id. consists of a number between 1-3
at the time of writing.
type: integer
required: True
responses:
200:
description: >-
In-mem db latest value
schema:
type: object
properties:
reading:
type: integer
example: 34
description: >-
This is the actual reading taken from the specified
light meter, at the time specified in this response
body (I.E. JSON object).