Commit 051f6946 authored by Bogdan's avatar Bogdan

Added paper busineslogic

parent 56b9c64e
......@@ -42,7 +42,7 @@ if __name__ == '__main__':
##################
old_c = None
customersCount = 0
customerCount = 0
rowCount = 0
for row in reader:
......@@ -56,14 +56,16 @@ if __name__ == '__main__':
customerCount +=1
rowCount = 0
old_c = transaction['Customer']
print(f"uploading for {old_c}")
if (customerCount>maxCustomers):
print("\nMAX customers reached")
break
if(rowCount<maxRows):
upload_transaction(transaction)
print(f"uploading for {old_c}")
rowCount+=1
if (customerCount>maxCustomers-1):
print("\nMAX customers reached")
break
import sys
import os
from pathlib import Path
from typing import Dict, Any
import requests
modules_path = '../../../modules/'
if os.path.exists(modules_path):
sys.path.insert(1, modules_path)
import network_constants as nc
from security.token_manager import TokenManager
import tables.add_smart_energy as smart_energy
def add_use_case(use_case: str):
jwt = TokenManager.getInstance().getToken()
url = f"https://articonf1.itec.aau.at:30420/api/use-cases"
response = requests.post(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
json = {"name": use_case}
)
print(url+": "+str(response.status_code))
if __name__ == "__main__":
use_case = "paper"
# disable ssl warnings :)
requests.packages.urllib3.disable_warnings()
add_use_case(use_case)
smart_energy.main(use_case)
\ No newline at end of file
import network_constants as nc
from security.token_manager import TokenManager
import requests
def add_table(use_case: str, table_name: str):
'''
take the columns and add the mappings at the server
replace all "/"'s in the internal representation with a "_"
'''
jwt = TokenManager.getInstance().getToken()
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["UniqueID"] = "Customer+Postcode+Timestamp"
url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case}/tables"
table = {
"name": table_name,
"mappings": columns
}
response = requests.post(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
json = table
)
print(url+": "+str(response.status_code))
def add_layers(use_case:str, table_name: str):
layers = [
{
"use_case": use_case,
"table": table_name,
"name": "Solar_Production_Layer",
"properties": [
"UniqueID",
"Customer",
"Postcode",
"Timestamp",
"Solar_Production_kWh",
"Total_Demand_MWh"
],
"cluster_properties": [
"Solar_Production_kWh",
]
},
{
"use_case": use_case,
"table": table_name,
"name": "Energy_Consumption_Layer",
"properties": [
"UniqueID",
"Customer",
"Postcode",
"Timestamp",
"Energy_Consumption_kWh",
"Total_Demand_MWh"
],
"cluster_properties": [
"Energy_Consumption_kWh"
]
},{
"use_case": use_case,
"table": table_name,
"name": "Heating_Consumption_Layer",
"properties": [
"UniqueID",
"Customer",
"Postcode",
"Timestamp",
"Heating_Consumption_kWh",
"Total_Demand_MWh"
],
"cluster_properties": [
"Heating_Consumption_kWh"
]
},{
"use_case": use_case,
"table": table_name,
"name": "Price_Layer",
"properties": [
"UniqueID",
"Customer",
"Postcode",
"Timestamp",
"Price_AUD_MWh",
"Total_Demand_MWh"
],
"cluster_properties": [
"Price_AUD_MWh"
]
},{
"use_case": use_case,
"table": table_name,
"name": "Demand_Layer",
"properties": [
"UniqueID",
"Customer",
"Postcode",
"Timestamp",
"Total_Demand_MWh"
],
"cluster_properties": [
"Total_Demand_MWh"
]
},{
"use_case": use_case,
"table": table_name,
"name": "Position_Layer",
"properties": [
"UniqueID",
"Customer",
"Postcode",
"Timestamp",
"Latitude",
"Longitude",
"Total_Demand_MWh"
],
"cluster_properties": [
"Latitude",
"Longitude",
]
},
]
jwt = TokenManager.getInstance().getToken()
for layer in layers:
url = f"https://articonf1.itec.aau.at:30420/api/layers"
response = requests.post(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
json = layer
)
print(url+": "+str(response.status_code))
def main(use_case: str):
print("PAPER")
table_name = "paper"
add_table(use_case, table_name)
add_layers(use_case, table_name)
\ No newline at end of file
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