Commit f18e7ea3 authored by Alexander Lercher's avatar Alexander Lercher

applied oo

parent ef2f767f
import json import json
class HyperGraph:
def do(): cluster_labels = []
df_nodes = load_values() dest_cluster_labels = []
label_values = []
ret_val = init(df_nodes) def __init__(self):
pass
def classify(self):
df_nodes = self.load_values()
ret_val = self.init(df_nodes)
nodeIds = ret_val['nodeIds'] nodeIds = ret_val['nodeIds']
clusterlabels = ret_val['clusterlabels'] clusterlabels = ret_val['clusterlabels']
destIds = ret_val['destIds'] destIds = ret_val['destIds']
clusterlabels = classify_input(nodeIds, clusterlabels) clusterlabels = self.classify_input(nodeIds, clusterlabels)
labelvals = self.calc_cluster_num(clusterlabels)
labelvals = calc_cluster_num(clusterlabels) cluster = self.cluster_with_labels(nodeIds, clusterlabels, labelvals)
cluster = cluster_with_labels(nodeIds, clusterlabels, labelvals) cluster = self.remove_duplicates(cluster)
cluster = remove_duplicates(cluster) destclusterlabel = self.cluster_dest_ids(labelvals, cluster, destIds)
destclusterlabel = cluster_dest_ids(labelvals, cluster, destIds) self.cluster_labels = clusterlabels
self.dest_cluster_labels = destclusterlabel
self.labelvals = labelvals
def load_values(): def load_values(self):
with open("mult_in_out_large.json", "r") as json_file: with open("mult_in_out_large.json", "r") as json_file:
df_nodes = json.load(json_file) df_nodes = json.load(json_file)
return df_nodes return df_nodes
def init(df_nodes): def init(self, df_nodes):
nodeIds = [] nodeIds = []
clusterlabels = [] clusterlabels = []
destIds = [] destIds = []
...@@ -53,7 +65,7 @@ def init(df_nodes): ...@@ -53,7 +65,7 @@ def init(df_nodes):
'clusterlabels': clusterlabels, 'clusterlabels': clusterlabels,
'destIds': destIds} 'destIds': destIds}
def classify_input(nodeIds, clusterlabels): def classify_input(self, nodeIds, clusterlabels):
"""" classifying Inputs""" """" classifying Inputs"""
"""" Labaling inputs""" """" Labaling inputs"""
for row in range(len(nodeIds)): for row in range(len(nodeIds)):
...@@ -81,7 +93,7 @@ def classify_input(nodeIds, clusterlabels): ...@@ -81,7 +93,7 @@ def classify_input(nodeIds, clusterlabels):
print("NodeIDs: ", len(nodeIds)) print("NodeIDs: ", len(nodeIds))
return clusterlabels return clusterlabels
def calc_cluster_num(clusterlabels): def calc_cluster_num(self, clusterlabels):
"""" Calculating the number of clusters""" """" Calculating the number of clusters"""
labelvals = [] labelvals = []
...@@ -99,7 +111,7 @@ def calc_cluster_num(clusterlabels): ...@@ -99,7 +111,7 @@ def calc_cluster_num(clusterlabels):
return labelvals return labelvals
def cluster_with_labels(nodeIds, clusterlabels, labelvals): def cluster_with_labels(self, nodeIds, clusterlabels, labelvals):
"""" clustering Ids according to their labels""" """" clustering Ids according to their labels"""
cluster = [] cluster = []
...@@ -112,7 +124,7 @@ def cluster_with_labels(nodeIds, clusterlabels, labelvals): ...@@ -112,7 +124,7 @@ def cluster_with_labels(nodeIds, clusterlabels, labelvals):
return cluster return cluster
def remove_duplicates(cluster): def remove_duplicates(self, cluster):
""" Removing duplicating items in cluster""" """ Removing duplicating items in cluster"""
flag = True flag = True
...@@ -137,7 +149,7 @@ def remove_duplicates(cluster): ...@@ -137,7 +149,7 @@ def remove_duplicates(cluster):
return cluster return cluster
def cluster_dest_ids(labelvals, cluster, destIds): def cluster_dest_ids(self, labelvals, cluster, destIds):
"""" Clustering Destination Ids """ """" Clustering Destination Ids """
destclusterlabel = [] destclusterlabel = []
......
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