Commit 965da6db authored by Lubber's avatar Lubber

Merge remote-tracking branch 'origin/develop' into develop

parents fd8b841f 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']}")
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