1
0
Fork 0
A REST-API built with Flask and Python. Its main purpose is to receive the readings from the light meters welding booths in the Ritherdon factory and make them available for consumption by the relay-controllers in the gallery.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

42 lines
1.5 KiB

from flask import make_response, abort
from config import db
from models.meters import (Meter1, Meter1Schema, Meter2, Meter2Schema,
Meter3, Meter3Schema)
'''
Post Services Note
======================================================================
The functions in this file are for storing the readings taken from the
light meters in Ritherdon. It you are wanting to retrieve data from
the (this) server, you will need to head to the /get_services.py/ file.
It should be in the same directory as this: /services/.
'''
def add_latest_reading(meter,reading):
if meter == 1:
return add_reading_to_meter1(reading)
elif meter == 2:
return add_reading_to_meter2(reading)
elif meter == 3:
return add_reading_to_meter3(reading)
def add_reading_to_meter1(the_reading):
schema = Meter1Schema()
new_reading = schema.load(the_reading, session=db.session)
db.session.add(new_reading)
db.session.commit()
return make_response("Reading successfully stored in database.", 201)
def add_reading_to_meter2(the_reading):
schema = Meter2Schema()
new_reading = schema.load(the_reading, session=db.session)
db.session.add(new_reading)
db.session.commit()
return make_response("Reading successfully stored database.", 201)
def add_reading_to_meter3(the_reading):
schema = Meter3Schema()
new_reading = schema.load(the_reading, session=db.session)
db.session.add(new_reading)
db.session.commit()
return make_response("Reading successfully stored database.", 201)