Commit e690562c authored by Manuel Herold's avatar Manuel Herold

upload script for traces

parent 0f7bfca8
...@@ -29,7 +29,7 @@ def add_use_case(use_case: str): ...@@ -29,7 +29,7 @@ def add_use_case(use_case: str):
print(url+": "+str(response.content)) print(url+": "+str(response.content))
if __name__ == "__main__": if __name__ == "__main__":
use_case = "crowd-journalism" use_case = "crowd-journalism-enum"
# disable ssl warnings :) # disable ssl warnings :)
requests.packages.urllib3.disable_warnings() requests.packages.urllib3.disable_warnings()
......
...@@ -18,6 +18,7 @@ def add_table(use_case: str, table_name: str): ...@@ -18,6 +18,7 @@ def add_table(use_case: str, table_name: str):
columns = { c : c for c in columns } columns = { c : c for c in columns }
columns["UniqueID"] = "userid+videoid" columns["UniqueID"] = "userid+videoid"
columns["objecttype"] = "enum(objecttype)"
table = { table = {
"name": table_name, "name": table_name,
......
...@@ -17,7 +17,8 @@ def add_table(use_case: str, table_name: str): ...@@ -17,7 +17,8 @@ def add_table(use_case: str, table_name: str):
columns = { c : c for c in columns } columns = { c : c for c in columns }
columns["UniqueID"] = "eventid" columns["UniqueID"] = "eventid"
columns["firstTag"] = "tags[0]" columns["firstTag"] = "enum(tags[0])"
columns["objecttype"] = "enum(objecttype)"
table = { table = {
"name": table_name, "name": table_name,
......
...@@ -17,6 +17,10 @@ def add_table(use_case: str, table_name: str): ...@@ -17,6 +17,10 @@ def add_table(use_case: str, table_name: str):
columns = { c : c for c in columns } columns = { c : c for c in columns }
columns["UniqueID"] = "userid+videoid+ownerid" columns["UniqueID"] = "userid+videoid+ownerid"
columns["objecttype"] = "enum(objecttype)"
columns["userid"] = "enum(userid)"
columns["ownerid"] = "enum(ownerid)"
table = { table = {
"name": table_name, "name": table_name,
......
...@@ -5,13 +5,9 @@ def add_table(use_case: str, table_name: str): ...@@ -5,13 +5,9 @@ def add_table(use_case: str, table_name: str):
replace all "/"'s in the internal representation with a "_" replace all "/"'s in the internal representation with a "_"
''' '''
columns = [ columns = {}
# "docType", columns["tag"] = "enum(tag)"
"objecttype", columns["objecttype"] = "enum(objecttype)"
"tag"
]
columns = { c : c for c in columns }
columns["UniqueID"] = "objecttype+tag" columns["UniqueID"] = "objecttype+tag"
table = { table = {
......
...@@ -33,7 +33,10 @@ def add_table(use_case: str, table_name: str): ...@@ -33,7 +33,10 @@ def add_table(use_case: str, table_name: str):
columns["UniqueID"] = "videoid" columns["UniqueID"] = "videoid"
columns["encodedAudio"] = "codec//audio" columns["encodedAudio"] = "codec//audio"
columns["encodedVideo"] = "codec//video" columns["encodedVideo"] = "codec//video"
columns["firstTag"] = "tags[0]"
columns["objecttype"] = "enum(objecttype)"
columns["duration"] = "enum(duration)"
columns["firstTag"] = "enum(tags[0])"
table = { table = {
"name": table_name, "name": table_name,
......
import sys
import os
import json
from pathlib import Path
from typing import Dict, Any
import requests
requests.packages.urllib3.disable_warnings()
modules_paths = ['.', '../../../modules/']
for modules_path in modules_paths:
if os.path.exists(modules_path):
sys.path.insert(1, modules_path)
import network_constants as nc
from security.token_manager import TokenManager
use_case_from = "crowd-journalism"
use_case_to = "crowd-journalism-enum"
# 1. get all tables for the use-case
from db.entities.table import Table
jwt = TokenManager.getInstance().getToken()
url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case_from}/tables"
response = requests.get(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
)
tables = json.loads(response.content)
tables = [Table.from_serializable_dict(row) for row in tables]
print(f"|tables|={len(tables)}")
#2. fetch layers for tables
from db.entities.layer_adapter import LayerAdapter
url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case_from}/layers"
response = requests.get(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
)
layers = json.loads(response.content)
layers = [LayerAdapter.from_serializable_dict(row) for row in layers]
print(f"|layers|={len(layers)}")
# 3. fetch transactions for use-case
url = f"https://articonf1.itec.aau.at:30001/api/use_cases/{use_case_from}/transactions"
response = requests.get(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
)
transactions = json.loads(response.content)
print(f"|transactions|={len(transactions)}")
ignored_fields = ["ApplicationType","docType","UniqueID"]
for table in tables:
for transaction in transactions:
if transaction["table"] != table.name:
continue
data = {
"ApplicationType": use_case_to,
"docType": table.name,
}
if table.name == "video":
data["codec"] = {
"audio": transaction["properties"]["encodedAudio"],
"video": transaction["properties"]["encodedVideo"]
}
data["tags"] = [transaction["properties"]["firstTag"]]
if table.name == "event":
data["tags"] = [transaction["properties"]["firstTag"]]
for key,value in transaction["properties"].items():
if key not in ignored_fields:
data[key] = value
# post the new trace
url = f"https://articonf1.itec.aau.at:30401/api/trace"
response = requests.post(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
json = data
)
print(url+": "+str(response.status_code))
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