def testNOACMetricForModelWithCrossingPoint(self): self.assertEqual( metrics.NOAC_metric(self.models['WITH_CROSSING_POINT']), 7 )
def testNOACMetricForModelWithCycles(self): self.assertEqual( metrics.NOAC_metric(self.models['WITH_CYCLES']), 16 )
def testNOACMetricForComplexModel(self): self.assertEqual( metrics.NOAC_metric(self.models['COMPLEX']), 21 )
def testNOACMetricForSimpleModel(self): self.assertEqual( metrics.NOAC_metric(self.models['SIMPLE']), 8 )
def check_diagrams_metics(diag_a, diag_b, do_print=True): group = {} try: if do_print: print("\n\tTNSE_metric: \ndiag_a:{}\ndiag_b:{}".format( metrics.TNSE_metric(diag_a), metrics.TNSE_metric(diag_b))) group["TNSE_metric"] = { "diag_a": metrics.TNSE_metric(diag_a), "diag_b": metrics.TNSE_metric(diag_b) } except: print("\nCan not calculate TNSE_metric for one or both diagrams") try: if do_print: print("\n\tTNIE_metric: \ndiag_a:{}\ndiag_b:{}".format( metrics.TNIE_metric(diag_a), metrics.TNIE_metric(diag_b))) group["TNIE_metric"] = { "diag_a": metrics.TNIE_metric(diag_a), "diag_b": metrics.TNIE_metric(diag_b) } except: print("\nCan not calculate TNIE_metric for one or both diagrams") try: if do_print: print("\n\tTNEE_metric: \ndiag_a:{}\ndiag_b:{}".format( metrics.TNEE_metric(diag_a), metrics.TNEE_metric(diag_b))) group["TNEE_metric"] = { "diag_a": metrics.TNEE_metric(diag_a), "diag_b": metrics.TNEE_metric(diag_b) } except: print("\nCan not calculate TNEE_metric for one or both diagrams") try: if do_print: print("\n\tTNE_metric: \ndiag_a:{}\ndiag_b:{}".format( metrics.TNE_metric(diag_a), metrics.TNE_metric(diag_b))) group["TNE_metric"] = { "diag_a": metrics.TNE_metric(diag_a), "diag_b": metrics.TNE_metric(diag_b) } except: print("\nCan not calculate TNE_metric for one or both diagrams") try: if do_print: print("\n\tNOA_metric: \ndiag_a:{}\ndiag_b:{}".format( metrics.NOA_metric(diag_a), metrics.NOA_metric(diag_b))) group["NOA_metric"] = { "diag_a": metrics.NOA_metric(diag_a), "diag_b": metrics.NOA_metric(diag_b) } except: print("\nCan not calculate NOA_metric for one or both diagrams") try: if do_print: print("\n\tNOAC_metric: \ndiag_a:{}\ndiag_b:{}".format( metrics.NOAC_metric(diag_a), metrics.NOAC_metric(diag_b))) group["NOAC_metric"] = { "diag_a": metrics.NOAC_metric(diag_a), "diag_b": metrics.NOAC_metric(diag_b) } except: print("\nCan not calculate NOAC_metric for one or both diagrams") try: if do_print: print("\n\tNOAJS_metric: \ndiag_a:{}\ndiag_b:{}".format( metrics.NOAJS_metric(diag_a), metrics.NOAJS_metric(diag_b))) group["NOAJS_metric"] = { "diag_a": metrics.NOAJS_metric(diag_a), "diag_b": metrics.NOAJS_metric(diag_b) } except: print("\nCan not calculate NOAJS_metric for one or both diagrams") try: if do_print: print("\n\tNumberOfNodes_metric: \ndiag_a:{}\ndiag_b:{}".format( metrics.NumberOfNodes_metric(diag_a), metrics.NumberOfNodes_metric(diag_b))) group["NumberOfNodes_metric"] = { "diag_a": metrics.NumberOfNodes_metric(diag_a), "diag_b": metrics.NumberOfNodes_metric(diag_b) } except: print( "\nCan not calculate NumberOfNodes_metric for one or both diagrams" ) try: if do_print: print("\n\tGatewayHeterogenity_metric: \ndiag_a:{}\ndiag_b:{}". format(metrics.GatewayHeterogenity_metric(diag_a), metrics.GatewayHeterogenity_metric(diag_b))) group["GatewayHeterogenity_metric"] = { "diag_a": metrics.GatewayHeterogenity_metric(diag_a), "diag_b": metrics.GatewayHeterogenity_metric(diag_b) } except: print( "\nCan not calculate GatewayHeterogenity_metric for one or both diagrams" ) try: if do_print: print( "\n\tCoefficientOfNetworkComplexity_metric: \ndiag_a:{}\ndiag_b:{}" .format(metrics.CoefficientOfNetworkComplexity_metric(diag_a), metrics.CoefficientOfNetworkComplexity_metric(diag_b))) group["CoefficientOfNetworkComplexity_metric"] = { "diag_a": metrics.CoefficientOfNetworkComplexity_metric(diag_a), "diag_b": metrics.CoefficientOfNetworkComplexity_metric(diag_b) } except: print( "\nCan not calculate CoefficientOfNetworkComplexity_metric for one or both diagrams" ) try: if do_print: print("\n\tAverageGatewayDegree_metric: \ndiag_a:{}\ndiag_b:{}". format(metrics.AverageGatewayDegree_metric(diag_a), metrics.AverageGatewayDegree_metric(diag_b))) group["AverageGatewayDegree_metric"] = { "diag_a": metrics.AverageGatewayDegree_metric(diag_a), "diag_b": metrics.AverageGatewayDegree_metric(diag_b) } except: print( "\nCan not calculate AverageGatewayDegree_metric for one or both diagrams" ) try: if do_print: print("\n\tDurfeeSquare_metric: \ndiag_a:{}\ndiag_b:{}".format( metrics.DurfeeSquare_metric(diag_a), metrics.DurfeeSquare_metric(diag_b))) group["DurfeeSquare_metric"] = { "diag_a": metrics.DurfeeSquare_metric(diag_a), "diag_b": metrics.DurfeeSquare_metric(diag_b) } except: print( "\nCan not calculate DurfeeSquare_metric for one or both diagrams") try: if do_print: print("\n\tPerfectSquare_metric: \ndiag_a:{}\ndiag_b:{}".format( metrics.PerfectSquare_metric(diag_a), metrics.PerfectSquare_metric(diag_b))) group["PerfectSquare_metric"] = { "diag_a": metrics.PerfectSquare_metric(diag_a), "diag_b": metrics.PerfectSquare_metric(diag_b) } except: print( "\nCan not calculate PerfectSquare_metric for one or both diagrams" ) return group
def test_thesis_models(self): format_three_dec = "{0:.3f}" format_two_dec = "{0:.2f}" names = [ "model1", "model2", "model3", "model4", "model5", "model6", "model7", "model8", "model9", "model10", "model11", "model12", "model13", "model14", "model15", "model16", "model17", "model18", "model19", "model20", "model21", "model22", "model23", "model24", "model25", "model26", "model27", "model28", "model29", "model30", "model31", "model32" ] with open("./output/metrics_part1.csv", "w") as file_one: with open("./output/metrics_part2.csv", "w") as file_two: with open("./output/metrics_min_max.csv", "w") as file_three: # write header file_one.write("Model name,NOA-H,NOA-G,NOA-diff,NOA-prop,NOC-H,NOC-G,NOC-diff,NOC-prop\n") file_two.write("Model name,CNC-H,CNC-G,CNC-diff,Avg-H,Avg-G,Avg-diff,Heter-H,Heter-G,Heter-diff\n") counter = 1 noa_max_diff = None noa_max_diff_index = 0 noa_max_prop = None noa_max_prop_index = 0 noa_min_diff = None noa_min_diff_index = 0 noa_min_prop = None noa_min_prop_index = 0 noa_sum = 0 noc_max_diff = None noc_max_diff_index = 0 noc_max_prop = None noc_max_prop_index = 0 noc_min_diff = None noc_min_diff_index = 0 noc_min_prop = None noc_min_prop_index = 0 noc_sum = 0 cnc_max = None cnc_max_diff = None cnc_max_index = 0 cnc_min = None cnc_min_diff = None cnc_min_index = 0 cnc_diff_sum = 0 avg_max_diff = None avg_max_index = 0 avg_min_diff = None avg_min_index = 0 avg_diff_sum = 0 heter_max_diff = None heter_max_index = 0 heter_min_diff = None heter_min_index = 0 for model_name in names: print(model_name) hand_made_bpmn = diagram.BpmnDiagramGraph() hand_made_bpmn.load_diagram_from_xml_file(self.hand_made_models + model_name + ".bpmn") hand_made_noa = metrics.NOA_metric(hand_made_bpmn) hand_made_noc = metrics.NOAC_metric(hand_made_bpmn) - hand_made_noa hand_made_cnc = metrics.CoefficientOfNetworkComplexity_metric(hand_made_bpmn) if metrics.all_gateways_count(hand_made_bpmn) > 0: hand_made_avg = metrics.AverageGatewayDegree_metric(hand_made_bpmn) else: hand_made_avg = 0 hand_made_heter = int(metrics.GatewayHeterogenity_metric(hand_made_bpmn)) gen_bpmn = diagram.BpmnDiagramGraph() gen_bpmn.load_diagram_from_xml_file(self.generated_models + model_name + ".bpmn") gen_noa = metrics.NOA_metric(gen_bpmn) gen_noc = metrics.NOAC_metric(gen_bpmn) - gen_noa gen_cnc = metrics.CoefficientOfNetworkComplexity_metric(gen_bpmn) if cnc_max is None: cnc_max = gen_cnc elif cnc_max < gen_cnc: cnc_max = gen_cnc if cnc_min is None: cnc_min = gen_cnc elif cnc_min > gen_cnc: cnc_min = gen_cnc if metrics.all_gateways_count(gen_bpmn) > 0: gen_avg = metrics.AverageGatewayDegree_metric(gen_bpmn) else: gen_avg = 0 gen_heter = int(metrics.GatewayHeterogenity_metric(gen_bpmn)) noa_diff = hand_made_noa - gen_noa noa_prop = (noa_diff * 100.0) / hand_made_noa noa_sum += noa_prop if noa_max_diff is None: noa_max_diff = noa_diff noa_max_diff_index = counter elif noa_diff > noa_max_diff: noa_max_diff = noa_diff noa_max_diff_index = counter if noa_max_prop is None: noa_max_prop = noa_diff noa_max_prop_index = counter elif noa_prop > noa_max_prop: noa_max_prop = noa_prop noa_max_prop_index = counter if noa_min_diff is None: noa_min_diff = noa_diff noa_min_diff_index = counter elif noa_diff < noa_min_diff: noa_min_diff = noa_diff noa_min_diff_index = counter if noa_min_prop is None: noa_min_prop = noa_diff noa_min_prop_index = counter elif noa_prop < noa_min_prop: noa_min_prop = noa_prop noa_min_prop_index = counter noc_diff = hand_made_noc - gen_noc noc_prop = (noc_diff * 100.0) / hand_made_noc noc_sum += noc_prop if noc_max_diff is None: noc_max_diff = noc_diff noc_max_diff_index = counter elif noc_diff > noc_max_diff: noc_max_diff = noc_diff noc_max_diff_index = counter if noc_max_prop is None: noc_max_prop = noc_prop noc_max_prop_index = counter elif noc_prop > noc_max_prop: noc_max_prop = noc_prop noc_max_prop_index = counter if noc_min_diff is None: noc_min_diff = noc_diff noc_min_diff_index = counter elif noc_diff < noc_min_diff: noc_min_diff = noc_diff noc_min_diff_index = counter if noc_min_prop is None: noc_min_prop = noc_prop noc_min_prop_index = counter elif noc_prop < noc_min_prop: noc_min_prop = noc_prop noc_min_prop_index = counter cnc_diff = hand_made_cnc - gen_cnc cnc_diff_sum += cnc_diff if cnc_max_diff is None: cnc_max_diff = cnc_diff elif cnc_diff > cnc_max_diff: cnc_max_diff = cnc_diff cnc_max_index = counter if cnc_min_diff is None: cnc_min_diff = cnc_diff elif cnc_diff < cnc_min_diff: cnc_min_diff = cnc_diff cnc_min_index = counter avg_diff = hand_made_avg - gen_avg avg_diff_sum += avg_diff if avg_max_diff is None: avg_max_diff = avg_diff elif avg_diff > avg_max_diff: avg_max_diff = avg_diff avg_max_index = counter if avg_min_diff is None: avg_min_diff = avg_diff elif avg_diff < avg_min_diff: avg_min_diff = avg_diff avg_min_index = counter heter_diff = hand_made_heter - gen_heter if heter_max_diff is None: heter_max_diff = heter_diff elif heter_diff > heter_max_diff: heter_max_diff = heter_diff heter_max_index = counter if heter_min_diff is None: heter_min_diff = heter_diff elif heter_diff < heter_min_diff: heter_min_diff = heter_diff heter_min_index = counter file_one.write("Model " + str(counter) + "," + str(hand_made_noa) + "," + str(gen_noa) + "," + str(noa_diff) + "," + format_two_dec.format(noa_prop) + "\%," + str(hand_made_noc) + "," + str(gen_noc) + "," + str(noc_diff) + "," + format_two_dec.format(noc_prop) + "\%\n") file_two.write("Model " + str(counter) + "," + format_three_dec.format(hand_made_cnc) + "," + format_three_dec.format(gen_cnc) + "," + format_three_dec.format(cnc_diff) + "," + format_three_dec.format(hand_made_avg) + "," + format_three_dec.format(gen_avg) + "," + format_three_dec.format(avg_diff) + "," + str(hand_made_heter) + "," + str(gen_heter) + "," + str(heter_diff) + "\n") counter += 1 file_three.write( "CNC metric: avg=" + format_three_dec.format(cnc_diff_sum / counter) + ", min=" + format_three_dec.format(cnc_min_diff) + ", model: " + str(cnc_min_index) + ", max=" + format_three_dec.format(cnc_max_diff) + ", model: " + str(cnc_max_index) + ", global min: " + format_three_dec.format(cnc_min) + ", global max: " + format_three_dec.format(cnc_max) + "\n") file_three.write( "Average Gateway Degree metric: avg=" + format_three_dec.format(avg_diff_sum / counter) + ", min=" + format_three_dec.format(avg_min_diff) + ", model: " + str(avg_min_index) + ", max=" + format_three_dec.format(avg_max_diff) + ", model: " + str(avg_max_index) + "\n") file_three.write( "Gateway Heterogenity metric: " + "min=" + str(heter_min_diff) + ", model: " + str(heter_min_index) + ", max=" + str(heter_max_diff) + ", model: " + str(heter_max_index) + "\n") file_three.write( "NOA metric (diff): " + "min=" + str(noa_min_diff) + ", model: " + str(noa_min_diff_index) + ", max=" + str(noa_max_diff) + ", model: " + str(noa_max_diff_index) + "\n") file_three.write( "NOA metric (prop): " + "min=" + format_two_dec.format(noa_min_prop) + ", model: " + str(noa_min_prop_index) + ", max=" + format_two_dec.format(noa_max_prop) + ", model: " + str(noa_max_prop_index) + ", average: " + format_two_dec.format(noa_sum / counter) + "\n") file_three.write( "NOC metric (diff): " + "min=" + str(noc_min_diff) + ", model: " + str(noc_min_diff_index) + ", max=" + str(noc_max_diff) + ", model: " + str(noc_max_diff_index) + "\n") file_three.write( "NOC metric (prop): " + "min=" + format_two_dec.format(noc_min_prop) + ", model: " + str(noc_min_prop_index) + ", max=" + format_two_dec.format(noc_max_prop) + ", model: " + str(noc_max_prop_index) + ", average: " + format_two_dec.format(noc_sum / counter) + "\n")