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