Commit 313cea69 authored by Manuel's avatar Manuel

[BusinessLogic] changed scripts to add schema information

parent 69817e5a
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_user as user
import tables.add_car as car
import tables.add_offer as offer
import tables.add_travel as travel
import tables.add_hash as add_hash
def add_use_case(use_case: str):
use_case = "car-sharing"
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 = "car-sharing"
# disable ssl warnings :)
requests.packages.urllib3.disable_warnings()
add_use_case(use_case)
user.main(use_case)
car.main(use_case)
offer.main(use_case)
travel.main(use_case)
add_hash.main(use_case)
\ No newline at end of file
# def add_car_layers():
# use_case = "car-sharing"
# layers = [
# {
# "use_case": use_case,
# "name": "doctype_layer",
# "properties": [
# "UniqueID",
# "doctype",
# ],
# "cluster_properties": [
# "doctype",
# ]
# },
# {
# "use_case": use_case,
# "name": "brand_layer",
# "properties": [
# "UniqueID",
# "brand",
# ],
# "cluster_properties": [
# "brand",
# ]
# },
# {
# "use_case": use_case,
# "name": "model_layer",
# "properties": [
# "UniqueID",
# "model",
# ],
# "cluster_properties": [
# "model",
# ]
# },
# {
# "use_case": use_case,
# "name": "colour_layer",
# "properties": [
# "UniqueID",
# "colour",
# ],
# "cluster_properties": [
# "colour",
# ]
# },
# {
# "use_case": use_case,
# "name": "seats_layer",
# "properties": [
# "UniqueID",
# "seats",
# ],
# "cluster_properties": [
# "seats",
# ]
# },
# {
# "use_case": use_case,
# "name": "year_layer",
# "properties": [
# "UniqueID",
# "year",
# ],
# "cluster_properties": [
# "year",
# ]
# },
# ]
# 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
# )
# if response.status_code == 200:
# print(f"Response: {response.status_code}")
# else:
# print(f"Response: {response.status_code}: {response.text}")
import network_constants as nc
from security.token_manager import TokenManager
import requests
def add_table(use_case: str):
'''
take the columns and add the mappings at the server
replace all "/"'s in the internal representation with a "_"
'''
jwt = TokenManager.getInstance().getToken()
use_case = "car-sharing"
columns = [
# "doctype",
"carLicensePlate",
"brand",
"model",
"colour",
"seats",
"year",
"ownerId",
"deleted",
"state",
"observations"
]
columns = { c : c for c in columns }
columns["UniqueID"] = "carLicensePlate"
url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case}/tables"
table = {
"name": "car",
"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 main(use_case: str):
print("CAR")
add_table(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):
'''
take the columns and add the mappings at the server
replace all "/"'s in the internal representation with a "_"
'''
jwt = TokenManager.getInstance().getToken()
# TODO check back with alex
use_case = "car-sharing"
columns = [
# "docType",
"documents",
"connection"
]
columns = { c : c for c in columns }
columns["UniqueID"] = "id"
url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case}/tables"
table = {
"name": "hash",
"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 main(use_case: str):
print("HASH")
add_table(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):
'''
take the columns and add the mappings at the server
replace all "/"'s in the internal representation with a "_"
'''
jwt = TokenManager.getInstance().getToken()
# TODO check back with alex
use_case = "car-sharing"
columns = [
# "docType",
"id",
# "car",
"priceForKm",
"priceForTime",
"startDate",
"endDate",
"deposit",
# "startPlace",
# "endPlaces",
"available",
"deleted",
# "cancelledBy",
"carOwner",
# "checkedBy",
# "finishedBy",
"offererId"
]
columns = { c : c for c in columns }
columns["UniqueID"] = "id"
url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case}/tables"
table = {
"name": "offer",
"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 main(use_case: str):
print("OFFER")
add_table(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):
'''
take the columns and add the mappings at the server
replace all "/"'s in the internal representation with a "_"
'''
jwt = TokenManager.getInstance().getToken()
# TODO check back with alex
use_case = "car-sharing"
columns = [
# "doctype",
"id",
"carLicensePlate",
# "users",
"offerId",
# "startPlace",
# "endPlace",
"startDate",
"endDate",
# "suggestedEndPlaces",
"rentForTime",
"seats",
"totalPrice",
"observations",
# "finishedBy",
"kmTraveled",
"priceBalance",
"depositBalance",
"rewardBalance",
# "score",
# "startedBy",
# "checkedBy",
"status",
# "cancelledBy"
]
columns = { c : c for c in columns }
columns["UniqueID"] = "id"
url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case}/tables"
table = {
"name": "travel",
"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 main(use_case: str):
print("TRAVEL")
add_table(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):
'''
take the columns and add the mappings at the server
replace all "/"'s in the internal representation with a "_"
'''
jwt = TokenManager.getInstance().getToken()
use_case = "car-sharing"
columns = [
# "doctype",
"id", # pk
"balance",
"payerId",
"numberOfTrips",
"sumOfTripsScores"
]
columns = { c : c for c in columns }
columns["UniqueID"] = "id"
url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case}/tables"
table = {
"name": "user",
"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 main(use_case: str):
print("USER")
add_table(use_case)
\ No newline at end of file
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 = "smart-energy"
# 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 sys
import os
from pathlib import Path
from typing import Dict, Any
import network_constants as nc
from security.token_manager import TokenManager
import requests
modules_path = '../../../modules/'
if os.path.exists(modules_path):
sys.path.insert(1, modules_path)
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()
import network_constants as nc
from security.token_manager import TokenManager
columns = [
"Customer",
"Postcode",
"Timestamp",
"Solar_Production_kWh",
"Energy_Consumption_kWh",
"Heating_Consumption_kWh",
"Price_AUD/MWh",
"Total_Demand_MWh",
"Latitude",
"Longitude"
]
def add_by_layers():
use_case = "smart-energy"
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",
......@@ -31,6 +62,7 @@ def add_by_layers():
},
{
"use_case": use_case,
"table": table_name,
"name": "Energy_Consumption_Layer",
"properties": [
"UniqueID",
......@@ -44,6 +76,7 @@ def add_by_layers():
]
},{
"use_case": use_case,
"table": table_name,
"name": "Heating_Consumption_Layer",
"properties": [
"UniqueID",
......@@ -57,6 +90,7 @@ def add_by_layers():
]
},{
"use_case": use_case,
"table": table_name,
"name": "Price_Layer",
"properties": [
"UniqueID",
......@@ -70,6 +104,7 @@ def add_by_layers():
]
},{
"use_case": use_case,
"table": table_name,
"name": "Demand_Layer",
"properties": [
"UniqueID",
......@@ -83,6 +118,7 @@ def add_by_layers():
]
},{
"use_case": use_case,
"table": table_name,
"name": "Position_Layer",
"properties": [
"UniqueID",
......@@ -112,43 +148,12 @@ def add_by_layers():
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"]
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"
print(url+": "+str(response.status_code))
response = requests.post(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
json = columns
)
def main(use_case: str):
print("SMART-ENERGY")
if response.status_code == 200:
print(f"Response: {response.status_code}")
return True
else:
print(f"Response: {response.status_code}: {response.text}")
return False
table_name = "smart-energy"
if __name__ == "__main__":
if add_by_schema():
add_by_layers()
\ No newline at end of file
add_table(use_case, table_name)
add_layers(use_case, table_name)
\ No newline at end of file
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_car_layers():
use_case = "car-sharing"
layers = [
{
"use_case": use_case,
"name": "doctype_layer",
"properties": [
"UniqueID",
"doctype",
],
"cluster_properties": [
"doctype",
]
},
{
"use_case": use_case,
"name": "brand_layer",
"properties": [
"UniqueID",
"brand",
],
"cluster_properties": [
"brand",
]
},
{
"use_case": use_case,
"name": "model_layer",
"properties": [
"UniqueID",
"model",
],
"cluster_properties": [
"model",
]
},
{
"use_case": use_case,
"name": "colour_layer",
"properties": [
"UniqueID",
"colour",
],
"cluster_properties": [
"colour",
]
},
{
"use_case": use_case,
"name": "seats_layer",
"properties": [
"UniqueID",
"seats",
],
"cluster_properties": [
"seats",
]
},
{
"use_case": use_case,
"name": "year_layer",
"properties": [
"UniqueID",
"year",
],
"cluster_properties": [
"year",
]
},
]
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
)
if response.status_code == 200:
print(f"Response: {response.status_code}")
else:
print(f"Response: {response.status_code}: {response.text}")
def add_car_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 = "car-sharing"
columns = [
"doctype",
"carLicensePlate",
"brand",
"model",
"colour",
"seats",
"year",
"ownerId",
"deleted",
"state",
"observations"
]
columns = { c : c for c in columns }
columns["UniqueID"] = "carLicensePlate"
url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case}/schema"
response = requests.post(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
json = columns
)
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__":
if add_car_schema():
add_car_layers()
\ 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