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
c2ae1d59
Commit
c2ae1d59
authored
Nov 17, 2020
by
Alexander Lercher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added script to add type_label
type_label is in {'high', 'medium', 'low', 'noise'}
parent
6e26b92b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
0 deletions
+64
-0
add_custom_type_label.py
...stage-discovery-microservice/app/add_custom_type_label.py
+64
-0
No files found.
src/data-hub/role-stage-discovery-microservice/app/add_custom_type_label.py
0 → 100644
View file @
c2ae1d59
'''This script adds a type_label of type {high, medium, low} to a json file containing clusters.'''
import
json
import
statistics
as
stat
def
print_min_max
(
layer_filename
):
with
open
(
layer_filename
,
'r'
)
as
layer_file
:
content
=
json
.
loads
(
layer_file
.
read
())
min_
=
1000000
max_
=
-
1000000
for
entry
in
content
:
# print(entry['label'])
if
entry
[
'label'
]
==
'noise'
:
continue
mean
=
stat
.
mean
([
float
(
e
)
for
e
in
entry
[
'label'
]
.
split
(
'--'
)])
cur_val
=
mean
max_
=
max
(
max_
,
cur_val
)
min_
=
min
(
min_
,
cur_val
)
print
(
f
"max: {max_}"
)
print
(
f
"min: {min_}"
)
def
create_type_label
(
layer_filename
,
treshold1
,
treshold2
):
with
open
(
layer_filename
,
'r'
)
as
layer_file
:
content
=
json
.
loads
(
layer_file
.
read
())
for
entry
in
content
:
if
entry
[
'label'
]
==
'noise'
:
entry
[
'type_label'
]
=
'noise'
continue
mean
=
stat
.
mean
([
float
(
e
)
for
e
in
entry
[
'label'
]
.
split
(
'--'
)])
if
mean
>
treshold2
:
entry
[
'type_label'
]
=
'high'
elif
mean
>
treshold1
:
entry
[
'type_label'
]
=
'medium'
else
:
entry
[
'type_label'
]
=
'low'
with
open
(
layer_filename
,
'w'
)
as
layer_file
:
layer_file
.
write
(
json
.
dumps
(
content
))
print_min_max
(
"Solar_Production_Layer.json"
)
create_type_label
(
"Solar_Production_Layer.json"
,
treshold1
=
1.4301666666666666
,
treshold2
=
2.860333333333333
)
print_min_max
(
"User_Demand_Layer.json"
)
create_type_label
(
"User_Demand_Layer.json"
,
treshold1
=
1.8306666666666667
,
treshold2
=
3.6608333333333336
)
def
check_values
():
with
open
(
"Solar_Production_Layer.json"
,
'r'
)
as
layer_file
:
content
=
json
.
loads
(
layer_file
.
read
())
for
e
in
content
:
print
(
f
"{e['label']} : {e['type_label']}"
)
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