-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afa582b
commit 4e30833
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import json | ||
import sys | ||
|
||
import numpy as np | ||
import pandas as pd | ||
from sklearn.preprocessing import StandardScaler | ||
|
||
ENCODING = "utf-8" | ||
|
||
|
||
def is_py310(): | ||
return sys.version_info.major == 3 and sys.version_info.minor == 10 | ||
|
||
|
||
def dump_json(filename: str, data): | ||
""" | ||
Dump data into a json file | ||
""" | ||
with open(filename, "w", encoding=ENCODING) as obj: | ||
json.dump(data, obj, ensure_ascii=False, indent=2, sort_keys=True) | ||
|
||
|
||
def load_json(filename: str): | ||
""" | ||
Load data from a json file | ||
""" | ||
with open(filename, encoding=ENCODING) as obj: | ||
return json.load(obj) | ||
|
||
|
||
def convert_adjacency_matrix(adj, node_names): | ||
""" | ||
convert metrics adj to service adj | ||
""" | ||
services = list(set([name.split("_")[0] for name in node_names])) | ||
# print(services) | ||
num_services = len(services) | ||
|
||
service_adj = np.zeros((num_services, num_services)) | ||
|
||
for i in range(adj.shape[0]): | ||
for j in range(adj.shape[0]): | ||
if adj[i][j] == 1: | ||
service_adj[services.index(node_names[i].split("_")[0])][ | ||
services.index(node_names[j].split("_")[0]) | ||
] = 1 | ||
|
||
# remove cycles | ||
for i in range(num_services): | ||
service_adj[i][i] = 0 | ||
|
||
return service_adj, services # services is node_names but for services |