Commit cca89882 authored by cst's avatar cst
Browse files

add logger import

parent 5bf65ed1
from web.helpers.db import Db
from web.helpers.utils import Utils
from web.helpers.scaling import Scaling
from itertools import groupby
import arrow
from web.helpers.processing import Scale, Calculate, Convert
class LoggerPostHandler:
def __init__(self):
pass
def get_validation_rules(self):
rules = [
{'name': 'id', 'required': True, 'type': str},
{'name': 'values', 'required': True, 'type': dict, 'action': 'append'}
]
return rules
def handle(self, model):
values = []
sql = """
select sp.id
from sampling_points sp
where sp.logger_id = %(id)s
"""
sp = Db.fetchone(sql, model)
for m in model["values"]:
v = {}
v["sampling_point_id"] = sp["id"]
v["begin_position"] = m["fromTime"]
v["end_position"] = m["toTime"]
v["value"] = m["value"]
v["verification_flag"] = 3
v["validation_flag"] = 1 if m["validity"] >= 75 else -1
values.append(v)
return values
\ No newline at end of file
from flask import Blueprint
from web.helpers.user import User
from .observations_post_handler import *
from web.api.imports.observations.observations_post_handler import ObservationsPostHandler
from web.api.imports.observations.logger_post_handler import LoggerPostHandler
from web.helpers.model_binder import ModelBinder as Binder
from werkzeug.exceptions import InternalServerError
......@@ -21,3 +22,20 @@ def observations_get():
return Responses.plain("Created", 201)
except Exception as e:
raise InternalServerError(description=str(e))
@obs.route("/imports/logger", methods=['POST'])
@User.basicauth_required
def logger_get():
loggerHandler = LoggerPostHandler()
obsHandler = ObservationsPostHandler()
loggerModel = Binder.bind_and_validate(loggerHandler.get_validation_rules())
try:
obsModel = loggerHandler.handle(loggerModel)
obsHandler.handle(obsModel)
return Responses.plain("Created", 201)
except Exception as e:
raise InternalServerError(description=str(e))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment