Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SMART
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UNI-KLU
SMART
Commits
7e767cc1
Commit
7e767cc1
authored
Dec 18, 2020
by
Alexander Lercher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adapted time slicing for local cluster json files
parent
4d887b0a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
10 deletions
+36
-10
.gitignore
...-stage-discovery-microservice/app/_predictions/.gitignore
+3
-0
run_time_slicing.py
...role-stage-discovery-microservice/app/run_time_slicing.py
+33
-10
No files found.
src/data-hub/role-stage-discovery-microservice/app/_predictions/.gitignore
0 → 100644
View file @
7e767cc1
# ignore this folder because it contains raw jsons for the community-prediction task
**
!.gitignore
\ No newline at end of file
src/data-hub/role-stage-discovery-microservice/app/run_time_slicing.py
View file @
7e767cc1
...
...
@@ -13,7 +13,7 @@ from typing import Tuple, Dict, Any, List
TimeSliceKey
=
Tuple
[
int
,
int
]
# TODO extract information about time features (maybe from table mapping)
TIME_PROPERTY_NAMES
=
[
'
T
imestamp'
]
TIME_PROPERTY_NAMES
=
[
'
t
imestamp'
]
repo
=
Repository
()
...
...
@@ -21,7 +21,8 @@ repo = Repository()
def
convert_to_time_slice_key
(
timestamp
:
str
)
->
TimeSliceKey
:
'''Returns the tuple (year, week_of_year) from a timestamp. This is used as the key for the slicing.'''
# time = datetime.utcfromtimestamp(float(timestamp[0:10]))
time
=
datetime
.
strptime
(
timestamp
,
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
# time = datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S')
time
=
datetime
.
utcfromtimestamp
(
float
(
timestamp
))
(
y
,
w
,
_
)
=
time
.
isocalendar
()
return
(
y
,
w
)
...
...
@@ -55,17 +56,39 @@ def split_clusterset_by_time(layer: Layer, clusters: List[Cluster]) -> Dict[Time
return
time_slices
def
get_layers
():
def
get_layers
()
->
List
[
Layer
]
:
return
repo
.
get_layers
()
def
get_clusters_for_layer
(
use_case
,
use_case_table
,
layer_name
):
return
repo
.
get_clusters_for_layer
(
use_case
,
use_case_table
,
layer_name
)
def
get_clusters_for_layer
(
use_case
,
use_case_table
,
layer_name
)
->
List
[
Cluster
]:
# return repo.get_clusters_for_layer(use_case, use_case_table, layer_name)
json_path
=
f
'_predictions/clusters/{layer_name}.json'
def
get_layer_nodes
(
use_case
,
use_case_table
,
layer_name
):
return
repo
.
get_layer_nodes
(
use_case
,
use_case_table
,
layer_name
)
if
os
.
path
.
exists
(
json_path
):
with
open
(
json_path
,
'r'
)
as
file
:
return
[
Cluster
(
cluster_dict
=
e
,
from_db
=
False
)
for
e
in
json
.
loads
(
file
.
read
())]
return
[]
def
get_layer_nodes
(
use_case
,
use_case_table
,
layer_name
)
->
List
[
dict
]:
# return repo.get_layer_nodes(use_case, use_case_table, layer_name)
return
[]
def
add_time_slice
(
timeslice
):
repo
.
add_time_slice
(
timeslice
)
try
:
# repo.add_time_slice(timeslice)
pass
except
:
print
(
f
"Error while storing time slice in db for {timeslice.layer_name}"
)
try
:
json_path
=
f
'_predictions/timeslices/{timeslice.layer_name}/{timeslice.time}.json'
.
replace
(
', '
,
'_'
)
.
replace
(
'('
,
''
)
.
replace
(
')'
,
''
)
if
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
json_path
)):
os
.
makedirs
(
os
.
path
.
dirname
(
json_path
))
with
open
(
json_path
,
'w'
)
as
file
:
file
.
write
(
json
.
dumps
(
timeslice
.
to_serializable_dict
(
for_db
=
False
)))
except
Exception
as
e
:
print
(
f
"Error while writing json for {timeslice.layer_name}: {e}"
)
def
run_time_slicing
(
selected_use_cases
:
List
[
str
]
=
None
,
selected_use_case_tables
:
List
[
str
]
=
None
,
selected_layer_names
:
List
[
str
]
=
None
):
layers
=
get_layers
()
...
...
@@ -98,5 +121,5 @@ def run_time_slicing(selected_use_cases: List[str] = None, selected_use_case_tab
if
__name__
==
"__main__"
:
repo
.
remove_all_time_slices
()
run_time_slicing
([],[],[])
\ No newline at end of file
# repo.remove_all_time_slices()
run_time_slicing
(
selected_use_cases
=
[
'community-prediction-taxi'
])
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment