Skip to content

Commit

Permalink
Updated microservice tool study website with a spreadsheet on metrics…
Browse files Browse the repository at this point in the history
… used in papers and our updated metrics results
  • Loading branch information
dorawyy committed Sep 21, 2024
1 parent db12ffd commit 6b96ae2
Show file tree
Hide file tree
Showing 33 changed files with 1,546 additions and 364 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import json
import os
import pandas as pd

class DataRepository:
def __init__(self, decompositions_path):
application_src_base = os.path.abspath("../../../code/scripts/metrics/casestudies")
application_src_base = os.path.abspath("./casestudies")

self.data_base = os.path.abspath("../../../code/scripts/metrics/data")
self.data_base = os.path.abspath("./data")

self.base_file_path = os.path.abspath("../../../code/scripts/metrics/data")
self.base_file_path = os.path.abspath("./data")

self.application_src_paths = {
"demo": f"{application_src_base}/demo/src/main/java",
Expand All @@ -21,7 +22,7 @@ def __init__(self, decompositions_path):
self.entropy_output_path = f"{self.data_base}/metrics/entropy.csv"
self.statistics_output_path = f"{self.data_base}/metrics/statistics.csv"

self.config_path = "./config.json"
# self.config_path = "./config.json"

def get_method_list(self, application):
with open(
Expand All @@ -37,10 +38,10 @@ def get_git_log_path(self, application):
return f"{self.base_file_path}/relationship_graphs/{application}/method_level/history.log"

def get_commit_graph_path(self, application):
return f"{self.base_file_path}/relationship_graphs/{application}/method_level/commit_graph.csv"
return f"{self.base_file_path}/relationship_graphs/{application}/class_level/commits.csv"

def get_contributor_graph_path(self, application):
return f"{self.base_file_path}/relationship_graphs/{application}/method_level/contributor_graph.csv"
return f"{self.base_file_path}/relationship_graphs/{application}/class_level/contributors.csv"

def get_decompositions_manifest(self):
manifest_file = open(f"{self.decompositions_path}/manifest.json", "r")
Expand All @@ -57,76 +58,125 @@ def get_visualization_path(
return f"{folder_path}/{granularity.split('_')[0]}_visualization.json"

def write_metrics_to_csv(self, rows):
csv_data = (
"Application,Tool,Partition Count,Decomposition Type,Commits,Contributors,Class Names,"
"Static Structural,Granularity,SMQ,CMQ,CDP,TurboMQ_commits,TurbomMQ_contributors\n"
)
data = []
for row in rows:
if row["tool"] == "mem":
partition_count = row["partition"].split("_")[0] + "_partitions"
variant = row["partition"][2:].replace("_partitions", "")
csv_data += (
f"{row['application']},{row['tool']},{partition_count},{variant},"
f"X,X,X,"
f"{row['structural_static']},{row['granularity']},{row['structural_static-fosci']},X,{row['CDP']},{row['commits']},{row['contributors']}\n"
)
row_data = {
"Application": row["application"],
"Tool": row["tool"],
"Partition Count": partition_count,
"Decomposition Type": variant,
"Commits": "X",
"Contributors": "X",
"Class Names": "X",
"Static Structural": row["structural_static"],
"Granularity": row["granularity"],
"SMQ": row["structural_static-fosci"],
"CMQ": "X",
"CDP": row["CDP"],
"TurboMQ_commits": row["commits"],
"TurbomMQ_contributors": row["contributors"],
}
else:
csv_data += (
f"{row['application']},{row['tool']},{row['partition']},{row['decomposition_type']},"
f"X,X,X,"
f"{row['structural_static']},{row['granularity']},{row['structural_static-fosci']},X,{row['CDP']},{row['commits']},{row['contributors']}\n"
)

out_file = open(self.metrics_output_path, "w")
out_file.write(csv_data)
out_file.close()
row_data ={
"Application": row['application'],
"Tool": row['tool'],
"Partition Count": row['partition'],
"Decomposition Type": row['decomposition_type'],
"Commits": "X",
"Contributors": "X",
"Class Names": "X",
"Static Structural": row['structural_static'],
"Granularity": row['granularity'],
"SMQ": row['structural_static-fosci'],
"CMQ": "X",
"CDP": row['CDP'],
"TurboMQ_commits": row['commits'],
"TurbomMQ_contributors": row['contributors']
}
data.append(row_data)
df = pd.DataFrame(data)
df = df.sort_values(by=['Decomposition Type', 'Tool', 'Application'])
df.to_csv(self.metrics_output_path, index=False)

def write_entropy_to_csv(self, rows):
csv_data = "Application,Tool,Partition Count,Variant,Granularity,Database Entropy,Use Case Entropy, M2M Use Case Entropy, Sarah BCP\n"
data = []
for row in rows:
if row["tool"] == "mem":
partition_count = row["long_partition"].split("_")[0]
variant = row["long_partition"][2:].replace("_partitions", "")
csv_data += (
f"{row['application']},{row['tool']},{partition_count},{variant},"
f"{row['granularity']},"
f"{row['database_entropy']},{row['use_case_entropy']},{row['m2m_use_case_entropy']},{row['sarah_bcp']}\n"
)
row_data ={
"Application": row['application'],
"Tool": row['tool'],
"Partition Count": partition_count,
"Variant": variant,
"Granularity": row['granularity'],
"Database Entropy": row['database_entropy'],
"Use Case Entropy": row['use_case_entropy'],
"M2M Use Case Entropy": row['m2m_use_case_entropy'],
"Sarah BCP": row['sarah_bcp']
}
else:
csv_data += (
f"{row['application']},{row['tool']},{row['partition_count']},{row['variant']},"
f"{row['granularity']},"
f"{row['database_entropy']},{row['use_case_entropy']},{row['m2m_use_case_entropy']},{row['sarah_bcp']}\n"
)

out_file = open(self.entropy_output_path, "w")
out_file.write(csv_data)
out_file.close()
row_data ={
"Application": row['application'],
"Tool": row['tool'],
"Partition Count": row['partition_count'],
"Variant": row['variant'],
"Granularity": row['granularity'],
"Database Entropy": row['database_entropy'],
"Use Case Entropy": row['use_case_entropy'],
"M2M Use Case Entropy": row['m2m_use_case_entropy'],
"Sarah BCP": row['sarah_bcp']
}
data.append(row_data)
df = pd.DataFrame(data)
df = df.sort_values(by=['Variant', 'Tool', 'Application'])
df.to_csv(self.entropy_output_path, index=False)

def write_statistics_to_csv(self, rows):
csv_data = "Application,Tool,Partition Count,Variant,Granularity,NED,Completeness,Actual Partition Count,Min,Max,Mean,Stdev,Median\n"
data = []
for row in rows:
if row["tool"] == "mem":
partition_count = row["long_partition"].split("_")[0]
variant = row["long_partition"][2:].replace("_partitions", "")
csv_data += (
f"{row['application']},{row['tool']},{partition_count},{variant},"
f"{row['granularity']},{row['ned']},"
f"{row['completeness']},{row['actual_partition_count']},"
f"{row['min']},{row['max']},{row['mean']},{row['stdev']},{row['median']}\n"
)
row_data = {
"Application": row['application'],
"Tool": row['tool'],
"Partition Count": partition_count,
"Variant": variant,
"Granularity": row['granularity'],
"NED": row['ned'],
"Completeness": row['completeness'],
"Actual Partition Count": row['actual_partition_count'],
"Min": row['min'],
"Max": row['max'],
"Mean": row['mean'],
"Stdev": row['stdev'],
"Median": row['median']
}
else:
csv_data += (
f"{row['application']},{row['tool']},{row['partition_count']},{row['variant']},"
f"{row['granularity']},{row['ned']},"
f"{row['completeness']},{row['actual_partition_count']},"
f"{row['min']},{row['max']},{row['mean']},{row['stdev']},{row['median']}\n"
)

out_file = open(self.statistics_output_path, "w")
out_file.write(csv_data)
out_file.close()

row_data = {
"Application": row['application'],
"Tool": row['tool'],
"Partition Count": row['partition_count'],
"Variant": row['variant'],
"Granularity": row['granularity'],
"NED": row['ned'],
"Completeness": row['completeness'],
"Actual Partition Count": row['actual_partition_count'],
"Min": row['min'],
"Max": row['max'],
"Mean": row['mean'],
"Stdev": row['stdev'],
"Median": row['median']
}
data.append(row_data)
df = pd.DataFrame(data)
df = df.sort_values(by=['Variant', 'Tool', 'Application'])
df.to_csv(self.statistics_output_path, index=False)

def get_dependency_path(self, application):
return f"{self.data_base}/applications/{application}/dependencies.xml"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ def get_decomposition_folder(self, tool, application, partition_count, variant):

def write_decomposition(self, tool, application, partition_count, variant, granularity, decomposition, filtered=True):
file_path = self.get_decomposition_path(tool, application, partition_count, granularity, variant, filtered)
with open(file_path, "w") as filtered_decomposition_file:
with open(file_path, "w", newline='\n') as filtered_decomposition_file:
for partition_name in decomposition.keys():
old_partition = decomposition[partition_name]
new_partition = list(map(lambda node: {"id": node}, old_partition))
new_partition.sort(key=lambda x: x['id'])
decomposition[partition_name] = new_partition

filtered_decomposition_file.write(json.dumps({"tool": {"decomposition": decomposition}}, indent=4))
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_decomposition_variants(self, tool):
def get_partition_count_options(self, application, tool):
if tool == "mem":
return get_subfolder_names(
f"../../../code/scripts/metrics/data/decompositions/{application}/mem"
f"./data/decompositions/{application}/mem"
)
return list(
filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_file_names(folder_path):

with open(
f"{data_path}/{data_app_name}/mem/{variant}{variant_suffix}/class_decomposition.json",
"w",
"w", newline='\n'
) as decomp_file:
decomp_file.write(
json.dumps({"MEM": {"decomposition": decomp}}, indent=4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from access.manifest import Manifest
from utils.utils import Utils
import numpy as np
import os


class Evaluator:
Expand Down Expand Up @@ -56,7 +57,7 @@ def calculate_cycles(self, edges, decomposition, partition_assignments):

return (interdependent_pairs / total_pairs) * 100

def calculte_ratio_icf_ecf(
def calculate_commit_mq(
self, decomposition, partition_assignments, app_name, granularity
):
internal_changes = {}
Expand All @@ -66,9 +67,11 @@ def calculte_ratio_icf_ecf(
internal_changes[partition_name] = 0
external_changes[partition_name] = 0

filename = os.path.abspath(f"./data/relationship_graphs/{app_name}/class_level/commits.csv")
with open(
f"./data/relationship_graphs/{app_name}/class_level/evolutionary_commits.csv"
filename
) as edge_file:

for line in edge_file.readlines():
row = line.strip().split(",")
source = Utils().shorten_name(row[1], granularity, True)
Expand Down Expand Up @@ -96,7 +99,7 @@ def calculte_ratio_icf_ecf(
cf += (2 * icf) / ((2 * icf) + ecf)

if len(decomposition) == 0:
print(f"WARNING: Decomposition is empty")
print(f"WARNING: Decomposition is empty for file {filename} [calculate_commit_mq]")
return 0
return (cf / len(decomposition)) * 100

Expand All @@ -110,8 +113,9 @@ def calculte_contrib_mq(
internal_changes[partition_name] = 0
external_changes[partition_name] = 0

filename = os.path.abspath(f"./data/relationship_graphs/{app_name}/class_level/contributors.csv")
with open(
f"./data/relationship_graphs/{app_name}/class_level/evolutionary_contributors.csv"
filename
) as edge_file:
for line in edge_file.readlines():
row = line.strip().split(",")
Expand Down Expand Up @@ -140,7 +144,7 @@ def calculte_contrib_mq(
cf += (2 * icf) / ((2 * icf) + ecf)

if len(decomposition) == 0:
print(f"WARNING: Decomposition is empty")
print(f"WARNING: Decomposition is empty for file {filename}[calculte_contrib_mq]")
return 0
return (cf / len(decomposition)) * 100

Expand Down Expand Up @@ -169,7 +173,7 @@ def calculate_normalized_turbomq(
cf += (2 * internal_edges) / ((2 * internal_edges) + external_edges)

if len(decomposition) == 0:
print(f"WARNING: Decomposition is empty")
print(f"WARNING: Decomposition is empty [calculate_normalized_turbomq]")
return 0
return (cf / len(decomposition)) * 100

Expand Down Expand Up @@ -287,7 +291,7 @@ def calculate_turbomq(
fosci_mq = self.calculate_fosci_mq(
edges, decomposition, partition_assignments
)
rei = self.calculte_ratio_icf_ecf(
rei = self.calculate_commit_mq(
decomposition, partition_assignments, application, granularity
)
contrib_mq = self.calculte_contrib_mq(
Expand Down
Loading

0 comments on commit 6b96ae2

Please sign in to comment.