Commit dc6fbe8e authored by Alexander Lercher's avatar Alexander Lercher

[Participation] added community prediction youtube schema

parent 2cacde05
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_table as add_table
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__":
# TODO strategy pattern for all the use cases where add_use_case() etc. is clear duplicate code
# The same for add table, where almost everything is the same (UniqueId, Timestamp for every Layer)
# Only need to get jwt token once in the strategy impl
use_case = "community-prediction-youtube"
# disable ssl warnings :)
requests.packages.urllib3.disable_warnings()
add_use_case(use_case)
add_table.main(use_case=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):
''' Adds the use-case table with all the mappings as dict Internal -> External. '''
jwt = TokenManager.getInstance().getToken()
mapping = { c : c for c in [
# mapping does not change any of the names for these properties
'trending_date',
'title',
'channel_title',
'category_id',
'category_name',
'publish_time',
'tags',
'views',
'likes',
'dislikes',
'comment_count',
'comments_disabled',
'ratings_disabled',
'video_error_or_removed',
'country_code',
'country_id',
'publish_timestamp',
] }
mapping["UniqueID"] = "video_id"
mapping["trend_delay"] = "trend_duration"
mapping["timestamp"] = "trending_timestamp"
url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case}/tables"
table = {
"name": table_name,
"mappings": mapping
}
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):
jwt = TokenManager.getInstance().getToken()
layers = [
{
"name": "CategoryLayer",
"properties": [
"UniqueID",
"category_id",
"category_name",
],
"cluster_properties": [
"category_id"
]
},
{
"name": "ViewsLayer",
"properties": [
"UniqueID",
"views",
],
"cluster_properties": [
"views"
]
},
{
"name": "LikesLayer",
"properties": [
"UniqueID",
"likes",
],
"cluster_properties": [
"likes"
]
},
{
"name": "DislikesLayer",
"properties": [
"UniqueID",
"dislikes",
],
"cluster_properties": [
"dislikes"
]
},
{
"name": "CommentCountLayer",
"properties": [
"UniqueID",
"comment_count",
],
"cluster_properties": [
"comment_count"
]
},
{
"name": "CountryLayer",
"properties": [
"UniqueID",
"country_code",
"country_id",
],
"cluster_properties": [
"country_id"
]
},
{
"name": "TrendDelayLayer",
"properties": [
"UniqueID",
"trend_delay",
],
"cluster_properties": [
"trend_delay"
]
},
]
for layer in layers:
# add basic info to each layer
layer["use_case"] = use_case
layer["table"] = table_name
layer["properties"].append("timestamp")
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, table_name: str = "community-prediction-youtube"):
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