Commit 92010bd6 authored by Herry's avatar Herry

added scripts to add articonf users, bityoga data

parent 49040105
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
def add_by_layers():
use_case = "smart-energy"
layers = [
{
"use_case": use_case,
"name": "Solar_Production_Layer",
"properties": [
"Customer",
"PostCode",
"Timestamp",
"Solar_Production_kWh"
],
"cluster_properties": [
"Solar_Production_kWh"
]
},
{
"use_case": use_case,
"name": "Energy_Consumption_Layer",
"properties": [
"Customer",
"PostCode",
"Timestamp",
"Energy_Consumption_kWh"
],
"cluster_properties": [
"Energy_Consumption_kWh"
]
},{
"use_case": use_case,
"name": "Heating_Consumption_Layer",
"properties": [
"Customer",
"PostCode",
"Timestamp",
"Heating_Consumption_kWh"
],
"cluster_properties": [
"Heating_Consumption_kWh"
]
},{
"use_case": use_case,
"name": "Price_Layer",
"properties": [
"Customer",
"PostCode",
"Timestamp",
"Price_AUD_MWh"
],
"cluster_properties": [
"Price_AUD_MWh"
]
},{
"use_case": use_case,
"name": "Demand_Layer",
"properties": [
"Customer",
"PostCode",
"Timestamp",
"Total_Demand_MWh"
],
"cluster_properties": [
"Total_Demand_MWh"
]
},{
"use_case": use_case,
"name": "Position_Layer",
"properties": [
"Customer",
"PostCode",
"Timestamp",
"Latitude",
"Longitude"
],
"cluster_properties": [
"Latitude",
"Longitude",
]
},
]
jwt = TokenManager.getInstance().getToken()
for layer in layers:
url = f"https://localhost:5000/api/layers"
response = requests.post(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
json = layer
)
if response.status_code == 200:
print(f"Response: {response.status_code}")
else:
print(f"Response: {response.status_code}: {response.text}")
def add_by_schema():
'''
take the columns and add the mappings at the server
replace all "/"'s in the internal representation with a "_"
'''
jwt = TokenManager.getInstance().getToken()
print(f"jwt token: {jwt}")
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"]
# url = f"https://{nc.BUSINESS_LOGIC_HOSTNAME}:{nc.BUSINESS_LOGIC_REST_PORT}/api/use-cases/{use_case}/schema/mapping"
url = f"https://localhost:5000/api/use-cases/{use_case}/schema/mapping"
for column in columns:
internal = column.replace("/", "_")
external = column
response = requests.put(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
json = { "internal":internal,"external":external }
)
if response.status_code == 200:
print(f"Response: {response.status_code}")
else:
print(f"Response: {response.status_code}: {response.text}")
if __name__ == "__main__":
add_by_schema()
add_by_layers()
\ No newline at end of file
# add modules folder to interpreter path
import sys
import os
import prance
from pathlib import Path
from typing import Dict, Any
modules_path = '../../modules/'
if os.path.exists(modules_path):
sys.path.insert(1, modules_path)
from services.user_service import UserService
if __name__ == "__main__":
UserService.add("regular@articonf1.itec.aau.at", "GBILLjaZE0Wyea9Y9ByS", role="u")
UserService.add("root@articonf1.itec.aau.at", "CJG6zD0mAjvo5zdVBftY", role="a")
\ 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