Commit 718c4778 authored by Manuel's avatar Manuel

[BusinessLogic] fixed upload script for smart-energy schema

parent ab8cb3d4
......@@ -127,9 +127,11 @@ def add_by_schema():
use_case = "smart-energy"
columns = ["Customer", "Postcode", "Timestamp", "Solar_Production_kWh", "Energy_Consumption_kWh", "Heating_Consumption_kWh", "Price_AUD/MWh", "Total_Demand_MWh", "Latitude", "Longitude"]
columns = [(c.replace("/", "_"), c) for c in columns]
columns.append(("UniqueID", "Customer+Postcode+Timestamp"))
columns = { c.replace("/", "_") : c for c in columns }
columns["UniqueID"] = "Customer+Postcode+Timestamp"
# url = f"https://localhost:5000/api/use-cases/{use_case}/schema"
url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case}/schema"
response = requests.post(
......@@ -142,9 +144,11 @@ def add_by_schema():
if response.status_code == 200:
print(f"Response: {response.status_code}")
return True
else:
print(f"Response: {response.status_code}: {response.text}")
return False
if __name__ == "__main__":
add_by_schema()
add_by_layers()
\ No newline at end of file
if add_by_schema():
add_by_layers()
\ No newline at end of file
......@@ -53,17 +53,13 @@ paths:
in: "body"
required: true
schema:
type: "object"
properties:
mappings:
type: array
items:
type: object
additionalProperties:
type: string
example:
name: name
dough: dough//type
type: object
additionalProperties:
type: string
example:
name: name
dough: dough//type
responses:
'200':
description: "Successful Request"
......
......@@ -15,18 +15,20 @@ def all():
return [schema.to_serializable_dict() for schema in schema_repository.all()]
def add_complete(use_case: str):
data = request.json
if "mappings" not in data:
return Response(status=400, response="Missing fields. Required fields: (mappings).")
mappings = request.json
reference = schema_repository.get_for_use_case(use_case)
if reference != None and len(reference.mappings) > 0:
return Response(status=400, response="Schema already exists.")
schema_repository.delete_for_use_case(use_case)
data["use_case"] = use_case
schema_repository.add(Schema.from_serializable_dict(data))
schema_dict = {
"use_case": use_case,
"mappings": mappings
}
schema_repository.add(Schema.from_serializable_dict(schema_dict))
return Response(status=200)
......
Markdown is supported
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