Generation

fix invalid codeTue, 03 Sep 2024

def VerifyTCC(): global Tmin, Tmax, Type Type = get_test_data('TestCase', 'Prot_Element') Ratio = get_test_data('TestCase','ratio') F = get_test_data('TestCase','Frequency') TCC_Curve = get_test_data('TestCase', 'Curve') CMEngine = None DevId = None dp_result = [] try: pythoncom.CoInitialize() CMEngine = win32com.client.Dispatch("OMICRON.CMEngAL") CMEngine.DevScanForNew(False) # turns = 120 pickUp = 35 ip_ct = pickUp / int(Ratio) freq = int(F) # IP Address of OMICRON - To be changes accordingly DevId = CMEngine.GetDevIDbyIPAddress(omicron_ip) CMEngine.DevAssociateAppend(DevId) CMEngine.DevLock(DevId) Result = CMEngine.Exec(DevId, "out:bin:cfg?") Result = CMEngine.Exec(DevId, "inp:bin:cfg?") # Configure Standard current Output B (Omicron frontside) CMEngine.Exec(DevId, "amp:route(clr)") CMEngine.Exec(DevId, "amp:def(clr)") # Get Configuration Id for the given configuration string "ser3" cfg_id = '' Result = CMEngine.Exec(DevId, "amp:cfg?") Result = Result.split(";")[0].split(",")[1] for i in range(int(Result)): res = CMEngine.Exec(DevId, "amp:cfg?(" + str(i + 1) + ")") if res.split(",")[7] == Testdrivermap.omc_ct_cfg_str: cfg_id = res.split(",")[1] break CMEngine.Exec(DevId, "amp:route(i(1)," + cfg_id + ")") CMEngine.Exec(DevId, "amp:def(off)") # Configure Standard Low Level Outputs(LL out 1-3) (Omicron backside) CMEngine.Exec(DevId, "amp:def(3,ext,v,1.0,7.071068,0.0,1000.0,0.0,0.0,0.0)") CMEngine.Exec(DevId, "amp:route(v(3),3)") CMEngine.Exec(DevId, "amp:def(off)") # Configure Standard Low Level Outputs(LL out 4-6) (Omicron backside) CMEngine.Exec(DevId, "amp:def(4,ext,v,1.0,7.071068,0.0,1000.0,0.0,0.0,0.0)") CMEngine.Exec(DevId, "amp:route(v(4),4)") CMEngine.Exec(DevId, "amp:def(off)") # Configure maximum amplitude (rms) for v(3) and v(4) CMEngine.Exec(DevId, "amp:range(v(3),7.071068)") CMEngine.Exec(DevId, "amp:range(v(4),7.071068)") Result = CMEngine.Exec(DevId, "inp:bin(1):cfg?") Result = CMEngine.Exec(DevId, "inp:bin(1:1):def(8.0)") Result = CMEngine.Exec(DevId, "inp:bin(1:2):def(8.0)") Result = CMEngine.Exec(DevId, "inp:bin(1:3):def(8.0)") Result = CMEngine.Exec(DevId, "inp:bin(1:4):def(8.0)") Result = CMEngine.Exec(DevId, "inp:bin(1:5):def(8.0)") Result = CMEngine.Exec(DevId, "inp:bin(1:6):def(8.0)") Result = CMEngine.Exec(DevId, "inp:bin(1):cfg?") CMEngine.Exec(DevId, "inp:buf:clr") CMEngine.Exec(DevId, "inp:buf:sam(bin, on)") # CMEngine.Exec(DevId, "out:i(1,2):clr") # CMEngine.Exec(DevId, "out:i(1,2):mix(sig(1))") # CMEngine.Exec(DevId, "out:i(1,2):sig(1):wav(sin)") logger.console("TCC_Curve" + TCC_Curve) global modPercCT, modTripTime, trip_time_pickup percCT = get_test_data(TCC_Curve, "percCT") if not (TCC_Curve.find('IEEE') != -1 or TCC_Curve.find('SEL') != -1 or TCC_Curve.find('IEC') != -1): trip_time_pickup = get_test_data(TCC_Curve, "tripTime100%") modPercCT = [float(ct) for ct in percCT] modTripTime = get_test_data(TCC_Curve, "tripTime") modTripTime = [float(i) for i in modTripTime] else: modPercCT, modTripTime = get_trip_time(TCC_Curve) Tmin, Tmax = calcTminAndTmax(TCC_Curve) # freq = ['60'] * len(modPercCT) IAPhase = [str(round(i * ip_ct, 4)) for i in modPercCT] IBPhase = [str(round(i * ip_ct, 4)) for i in modPercCT] ICPhase = [str(round(i * ip_ct, 4)) for i in modPercCT] lst = [[] for k in range(4)] CMEngine.Exec(DevId, "out:aux:def(30)") CMEngine.Exec(DevId, "out:aux:on") for i in range(len(IAPhase)): # lst[0].append("NA") # lst[1].append(modTripTime[i]) # lst[2].append("NA") logger.console(str(i) + " " + str(IAPhase[i])) # Feedeing Frequency for first step Current # CMEngine.Exec(DevId, "out:i(1,2):f(" + freq[i] + ")") # CMEngine.Exec(DevId, "out:on") time.sleep(0.5) Pre_fault = 20 preFault = Pre_fault / int(Ratio) CMEngine.Exec(DevId, "out:i(1:1):f(" + str(freq) + ")") CMEngine.Exec(DevId, "out:i(1:2):f(" + str(freq) + ")") CMEngine.Exec(DevId, "out:i(1:3):f(" + str(freq) + ")") CMEngine.Exec(DevId, "out:i(1:1):a(" + str(preFault) + ");p(-120)") CMEngine.Exec(DevId, "out:i(1:2):a(" + str(preFault) + ");p(-120)") CMEngine.Exec(DevId, "out:i(1:3):a(" + str(preFault) + ");p(-120)") # CMEngine.Exec(DevId, "out:bin(2):on(1,2, 3)") CMEngine.Exec(DevId, "out:on") time.sleep(5) logger.console("PreFault injected along with the wait time of 5 sec") boolTripA = False boolTripB = False boolTripC = False lst_of_postsFaults = [20 + float(i) for i in Tmax] CMEngine.Exec(DevId, "out:i(1:1):a(0);p(-120)") CMEngine.Exec(DevId, "out:i(1:2):a(0);p(-120)") CMEngine.Exec(DevId, "out:i(1:3):a(0);p(-120)") if Type == "A": CMEngine.Exec(DevId, "out:i(1:1):a(" + IAPhase[i] + ");p(-120)") if Type == "B": CMEngine.Exec(DevId, "out:i(1:2):a(" + IBPhase[i] + ");p(-120)") if Type == "C": CMEngine.Exec(DevId, "out:i(1:3):a(" + ICPhase[i] + ");p(-120)") if Type == "G": CMEngine.Exec(DevId, "out:i(1:1):a(" + IAPhase[i] + ");p(-120)") CMEngine.Exec(DevId, "out:i(1:2):a(0);p(-120)") CMEngine.Exec(DevId, "out:i(1:3):a(0);p(-120)") global tripTime1, tripTime2, tripTime3 tripTime1 = "" tripTime2 = "" tripTime3 = "" data = 111111 Result = CMEngine.Exec(DevId, "seq:begin") Result = CMEngine.Exec(DevId, "inp:buf:sam(bin, off)") Result = CMEngine.Exec(DevId, "inp:buf:clr") Result = CMEngine.Exec(DevId, "inp:buf:sam(bin, on)") CMEngine.Exec(DevId, "out:on") Result = CMEngine.Exec(DevId, "seq:wait((bin(1:1) or bin(1:3) or bin(1:5)), 1)") CMEngine.Exec(DevId, "out:ana:i(1):off") Result = CMEngine.Exec(DevId, "seq:end") Result = CMEngine.Exec(DevId, "seq:exec") startTime = timeit.default_timer() logger.console('start time: ' + str(startTime)) for j in range(1000000): CMEngine.Exec(DevId, "inp: buf:sam(bin, 9)") Result1 = CMEngine.Exec(DevId, "inp: buf:get?") logger.console('Result' + str(Result1)) typ = str(Result1.split(";")[0].split(",")[1]) if typ == 'bin': data = int(Result1.split(";")[0].split(",")[3]) if (30 | data == 31) and not tripTime1: # CMEngine.Exec(DevId, "out:ana:i(1:1):off") tripTime1 = float(Result1.split(";")[0].split(",")[2]) if Type != 'G': delta = str(round(float(tripTime1) * 1, 4)) logger.console("TripTime-A" + delta) lst[0].append(delta) lst[1].append("NA") lst[2].append("NA") break if (27 | data == 31) and not tripTime2: # CMEngine.Exec(DevId, "out:ana:i(1:2):off") tripTime2 = float(Result1.split(";")[0].split(",")[2]) if Type != 'G': delta = str(round(float(tripTime2) * 1, 4)) logger.console("TripTime-B" + delta) lst[1].append(delta) lst[0].append("NA") lst[2].append("NA") break if (15 | data == 31) and not tripTime3: # CMEngine.Exec(DevId, "out:ana:i(1:3):off") tripTime3 = float(Result1.split(";")[0].split(",")[2]) if Type != 'G': delta = str(round(float(tripTime3) * 1, 4)) logger.console("TripTime-C" + delta) lst[2].append(delta) lst[0].append("NA") lst[1].append("NA") break if tripTime1 and tripTime2 and tripTime3: AllPhasetime = timeit.default_timer() threePHTrip = str(round(((AllPhasetime - startTime) * 1000), 3)) lst[3].append(threePHTrip) logger.console("All 3 Phase Tripped") CMEngine.Exec(DevId, "out:ana:i(1:1):off") CMEngine.Exec(DevId, "out:ana:i(1:2):off") CMEngine.Exec(DevId, "out:ana:i(1:3):off") time.sleep(2) delta = str(round(float(tripTime1) * 1, 4)) logger.console("TripTime-A" + delta) lst[0].append(delta) delta = str(round(float(tripTime2) * 1, 4)) logger.console("TripTime-B" + delta) lst[1].append(delta) delta = str(round(float(tripTime3) * 1, 4)) logger.console("TripTime-C" + delta) lst[2].append(delta) break defTimeDelay = timeit.default_timer() if float((defTimeDelay - startTime) * 1) >= (float(lst_of_postsFaults[i])): logger.console("Exceeded elapsed time") CMEngine.Exec(DevId, "out:ana:i(1:1):off") CMEngine.Exec(DevId, "out:ana:i(1:2):off") CMEngine.Exec(DevId, "out:ana:i(1:3):off") CMEngine.Exec(DevId, "out:bin(2):off(1,2,3)") time.sleep(2) if not tripTime1: lst[0].append('No Trip') else: delta = str(round(float(tripTime1) * 1, 4)) logger.console("TripTime-A" + delta) lst[0].append(delta) if not tripTime2: lst[1].append('No Trip') else: delta = str(round(float(tripTime2) * 1, 4)) logger.console("TripTime-B" + delta) lst[1].append(delta) if not tripTime3: lst[2].append('No Trip') else: delta = str(round(float(tripTime3) * 1, 4)) logger.console("TripTime-C" + delta) lst[2].append(delta) break endTime = timeit.default_timer() logger.console('end time: ' + str(endTime)) stepNum = 1 PhARes, PhBRes, PhCRes, OveralRes, phAdeviation, phBdeviation, phCdeviation = verifyResults(TCC_Curve, lst[0], lst[1], lst[2]) TNorm = modTripTime dp_result = [] for i in range(len(TNorm)): temp_dict = {} dp_dict = {} temp_dict["TCC_Curve"] = TCC_Curve temp_dict["Prot_Element"] = Type temp_dict["PickUP"] = pickUp temp_dict["% PickUP"] = modPercCT[i] temp_dict['IP Current'] = float(IAPhase[i]) * 1000 temp_dict['Tnorm'] = str(TNorm[i]) temp_dict['Texp_min'] = str(Tmin[i]) temp_dict['Texp_max'] = str(Tmax[i]) temp_dict['Tact_A'] = lst[0][i] temp_dict['Tact_B'] = lst[1][i] temp_dict['Tact_C'] = lst[2][i] temp_dict['Res_A'] = "NA" temp_dict['Res_B'] = "NA" temp_dict['Res_C'] = "NA" if Type == 'G' or Type == 'A': temp_dict['Res_A'] = PhARes[i] if Type == 'G' or Type == 'B': temp_dict['Res_B'] = PhBRes[i] if Type == 'G' or Type == 'C': temp_dict['Res_C'] = PhCRes[i] if not (phAdeviation) or not (phBdeviation) or not (phCdeviation): temp_dict['Tdev_A'] = 'NA' temp_dict['Tdev_B'] = 'NA' temp_dict['Tdev_C'] = 'NA' else: temp_dict['Tdev_A'] = phAdeviation[i] temp_dict['Tdev_B'] = phBdeviation[i] temp_dict['Tdev_C'] = phCdeviation[i] if OveralRes[i] == 'PASS': temp_dict['DP_Res'] = 'PASS' dp_dict["DP-" + str(stepNum)] = temp_dict dp_result.append(dp_dict) else: temp_dict['DP_Res'] = 'FAIL' dp_dict["DP-" + str(stepNum)] = temp_dict dp_result.append(dp_dict) stepNum += 1 phAPassPercent = 'NA' phBPassPercent = 'NA' phCPassPercent = 'NA' if Type == 'G' or Type == 'A': phAPassPercent = round((PhARes.count('PASS') / len(PhARes) * 100), 3) if Type == 'G' or Type == 'B': phBPassPercent = round((PhBRes.count('PASS') / len(PhBRes) * 100), 3) if Type == 'G' or Type == 'C': phCPassPercent = round((PhCRes.count('PASS') / len(PhCRes) * 100), 3) OverallpassPercent = round((OveralRes.count('PASS') / len(OveralRes) * 100), 3) test_dict = {} dict_percentage = {} dict_percentage['Phase A'] = str(phAPassPercent) dict_percentage['Phase B'] = str(phBPassPercent) dict_percentage['Phase C'] = str(phCPassPercent) dict_percentage['Overall Pass %'] = str(OverallpassPercent) test_dict["OVERALL_%_RESULT"] = dict_percentage test_result_update = TestResultsUpdateZephyr() if "FAIL" in OveralRes: max_retries = 3 retry_count = 0 test_passed = False while retry_count < max_retries and not test_passed: try: logger.console(f"Retrying test case (attempt {retry_count + 1}/{max_retries})") logger.console("TCC_Curve" + TCC_Curve) percCT = get_test_data(TCC_Curve, "percCT") if not (TCC_Curve.find('IEEE') != -1 or TCC_Curve.find('SEL') != -1 or TCC_Curve.find('IEC') != -1): trip_time_pickup = get_test_data(TCC_Curve, "tripTime100%") modPercCT = [float(ct) for ct in percCT] modTripTime = get_test_data(TCC_Curve, "tripTime") modTripTime = [float(i) for i in modTripTime] else: modPercCT, modTripTime = get_trip_time(TCC_Curve) Tmin, Tmax = calcTminAndTmax(TCC_Curve) # freq = ['60'] * len(modPercCT) IAPhase = [str(round(i * ip_ct, 4)) for i in modPercCT] IBPhase = [str(round(i * ip_ct, 4)) for i in modPercCT] ICPhase = [str(round(i * ip_ct, 4)) for i in modPercCT] lst = [[] for k in range(4)] CMEngine.Exec(DevId, "out:aux:def(30)") CMEngine.Exec(DevId, "out:aux:on") for i in range(len(IAPhase)): logger.console(str(i) + " " + str(IAPhase[i])) time.sleep(0.5) Pre_fault = 20 preFault = Pre_fault / int(Ratio) CMEngine.Exec(DevId, "out:i(1:1):f(" + str(freq) + ")") CMEngine.Exec(DevId, "out:i(1:2):f(" + str(freq) + ")") CMEngine.Exec(DevId, "out:i(1:3):f(" + str(freq) + ")") CMEngine.Exec(DevId, "out:i(1:1):a(" + str(preFault) + ");p(-120)") CMEngine.Exec(DevId, "out:i(1:2):a(" + str(preFault) + ");p(-120)") CMEngine.Exec(DevId, "out:i(1:3):a(" + str(preFault) + ");p(-120)") CMEngine.Exec(DevId, "out:on") time.sleep(5) logger.console("PreFault injected along with the wait time of 5 sec") boolTripA = False boolTripB = False boolTripC = False lst_of_postsFaults = [20 + float(i) for i in Tmax] CMEngine.Exec(DevId, "out:i(1:1):a(0);p(-120)") CMEngine.Exec(DevId, "out:i(1:2):a(0);p(-120)") CMEngine.Exec(DevId, "out:i(1:3):a(0);p(-120)") if Type == "A": CMEngine.Exec(DevId, "out:i(1:1):a(" + IAPhase[i] + ");p(-120)") if Type == "B": CMEngine.Exec(DevId, "out:i(1:2):a(" + IBPhase[i] + ");p(-120)") if Type == "C": CMEngine.Exec(DevId, "out:i(1:3):a(" + ICPhase[i] + ");p(-120)") if Type == "G": CMEngine.Exec(DevId, "out:i(1:1):a(" + IAPhase[i] + ");p(-120)") CMEngine.Exec(DevId, "out:i(1:2):a(0);p(-120)") CMEngine.Exec(DevId, "out:i(1:3):a(0);p(-120)") # global tripTime1, tripTime2, tripTime3 tripTime1 = "" tripTime2 = "" tripTime3 = "" data = 111111 Result = CMEngine.Exec(DevId, "seq:begin") Result = CMEngine.Exec(DevId, "inp:buf:sam(bin, off)") Result = CMEngine.Exec(DevId, "inp:buf:clr") Result = CMEngine.Exec(DevId, "inp:buf:sam(bin, on)") CMEngine.Exec(DevId, "out:on") Result = CMEngine.Exec(DevId, "seq:wait((bin(1:1) or bin(1:3) or bin(1:5)), 1)") CMEngine.Exec(DevId, "out:ana:i(1):off") Result = CMEngine.Exec(DevId, "seq:end") Result = CMEngine.Exec(DevId, "seq:exec") startTime = timeit.default_timer() logger.console('start time: ' + str(startTime)) for j in range(1000000): CMEngine.Exec(DevId, "inp: buf:sam(bin, 9)") Result1 = CMEngine.Exec(DevId, "inp: buf:get?") logger.console('Result' + str(Result1)) typ = str(Result1.split(";")[0].split(",")[1]) if typ == 'bin': data = int(Result1.split(";")[0].split(",")[3]) if (30 | data == 31) and not tripTime1: # CMEngine.Exec(DevId, "out:ana:i(1:1):off") tripTime1 = float(Result1.split(";")[0].split(",")[2]) if Type != 'G': delta = str(round(float(tripTime1) * 1, 4)) logger.console("TripTime-A" + delta) lst[0].append(delta) lst[1].append("NA") lst[2].append("NA") break if (27 | data == 31) and not tripTime2: # CMEngine.Exec(DevId, "out:ana:i(1:2):off") tripTime2 = float(Result1.split(";")[0].split(",")[2]) if Type != 'G': delta = str(round(float(tripTime2) * 1, 4)) logger.console("TripTime-B" + delta) lst[1].append(delta) lst[0].append("NA") lst[2].append("NA") break if (15 | data == 31) and not tripTime3: # CMEngine.Exec(DevId, "out:ana:i(1:3):off") tripTime3 = float(Result1.split(";")[0].split(",")[2]) if Type != 'G': delta = str(round(float(tripTime3) * 1, 4)) logger.console("TripTime-C" + delta) lst[2].append(delta) lst[0].append("NA") lst[1].append("NA") break if tripTime1 and tripTime2 and tripTime3: AllPhasetime = timeit.default_timer() threePHTrip = str(round(((AllPhasetime - startTime) * 1000), 3)) lst[3].append(threePHTrip) logger.console("All 3 Phase Tripped") CMEngine.Exec(DevId, "out:ana:i(1:1):off") CMEngine.Exec(DevId, "out:ana:i(1:2):off") CMEngine.Exec(DevId, "out:ana:i(1:3):off") time.sleep(2) delta = str(round(float(tripTime1) * 1, 4)) logger.console("TripTime-A" + delta) lst[0].append(delta) delta = str(round(float(tripTime2) * 1, 4)) logger.console("TripTime-B" + delta) lst[1].append(delta) delta = str(round(float(tripTime3) * 1, 4)) logger.console("TripTime-C" + delta) lst[2].append(delta) break defTimeDelay = timeit.default_timer() if float((defTimeDelay - startTime) * 1) >= (float(lst_of_postsFaults[i])): logger.console("Exceeded elapsed time") CMEngine.Exec(DevId, "out:ana:i(1:1):off") CMEngine.Exec(DevId, "out:ana:i(1:2):off") CMEngine.Exec(DevId, "out:ana:i(1:3):off") CMEngine.Exec(DevId, "out:bin(2):off(1,2,3)") time.sleep(2) if not tripTime1: lst[0].append('No Trip') else: delta = str(round(float(tripTime1) * 1, 4)) logger.console("TripTime-A" + delta) lst[0].append(delta) if not tripTime2: lst[1].append('No Trip') else: delta = str(round(float(tripTime2) * 1, 4)) logger.console("TripTime-B" + delta) lst[1].append(delta) if not tripTime3: lst[2].append('No Trip') else: delta = str(round(float(tripTime3) * 1, 4)) logger.console("TripTime-C" + delta) lst[2].append(delta) break endTime = timeit.default_timer() logger.console('end time: ' + str(endTime)) stepNum = 1 PhARes, PhBRes, PhCRes, OveralRes, phAdeviation, phBdeviation, phCdeviation = verifyResults( TCC_Curve, lst[0], lst[1], lst[2]) TNorm = modTripTime dp_result = [] retry_data = [] for i in range(len(TNorm)): temp_dict_1 = {} temp_dict_2 = {} temp_dict_3 = {} dp_dict_1 = {} dp_dict_2 = {} dp_dict_3 = {} if retry_count == 0: temp_dict_1["TCC_Curve"] = TCC_Curve temp_dict_1["Prot_Element"] = Type temp_dict_1["PickUP"] = pickUp temp_dict_1["% PickUP"] = modPercCT[i] temp_dict_1['IP Current'] = float(IAPhase[i]) * 1000 temp_dict_1['Tnorm'] = str(TNorm[i]) temp_dict_1['Texp_min'] = str(Tmin[i]) temp_dict_1['Texp_max'] = str(Tmax[i]) temp_dict_1['Tact_A_1'] = lst[0][i] temp_dict_1['Tact_B_1'] = lst[1][i] temp_dict_1['Tact_C_1'] = lst[2][i] temp_dict_1['Res_A'] = "NA" temp_dict_1['Res_B'] = "NA" temp_dict_1['Res_C'] = "NA" PhA_1 = {lst[0][i]} PhB_1 = {lst[1][i]} PhC_1 = {lst[2][i]} if Type == 'G' or Type == 'A': temp_dict_1['Res_A'] = PhARes[i] if Type == 'G' or Type == 'B': temp_dict_1['Res_B'] = PhBRes[i] if Type == 'G' or Type == 'C': temp_dict_1['Res_C'] = PhCRes[i] if not (phAdeviation) or not (phBdeviation) or not (phCdeviation): temp_dict_1['Tdev_A'] = 'NA' temp_dict_1['Tdev_B'] = 'NA' temp_dict_1['Tdev_C'] = 'NA' else: temp_dict_1['Tdev_A'] = phAdeviation[i] temp_dict_1['Tdev_B'] = phBdeviation[i] temp_dict_1['Tdev_C'] = phCdeviation[i] if OveralRes[i] == 'PASS': temp_dict_1['DP_Res'] = 'PASS' dp_dict_1["DP-" + str(stepNum)] = temp_dict_1 retry_data.append(dp_dict_1) else: temp_dict_1['DP_Res'] = 'FAIL' dp_dict_1["DP-" + str(stepNum)] = temp_dict_1 retry_data.append(dp_dict_1) stepNum += 1 phAPassPercent = 'NA' phBPassPercent = 'NA' phCPassPercent = 'NA' if Type == 'G' or Type == 'A': phAPassPercent = round((PhARes.count('PASS') / len(PhARes) * 100), 3) if Type == 'G' or Type == 'B': phBPassPercent = round((PhBRes.count('PASS') / len(PhBRes) * 100), 3) if Type == 'G' or Type == 'C': phCPassPercent = round((PhCRes.count('PASS') / len(PhCRes) * 100), 3) OverallpassPercent = round((OveralRes.count('PASS') / len(OveralRes) * 100), 3) # test_dict_1 = {} # dict_percentage_1 = {} # dict_percentage_1['Phase A'] = str(phAPassPercent) # dict_percentage_1['Phase B'] = str(phBPassPercent) # dict_percentage_1['Phase C'] = str(phCPassPercent) # dict_percentage_1['Overall Pass %'] = str(OverallpassPercent) # test_dict_1["OVERALL_%_RESULT"] = dict_percentage_1 retry_data.append(temp_dict_1) # dp_result.append(test_dict_1) retry_result_1 = retry_data logger.console(retry_result_1) # write_to_json(retry_result) # test_result_update = TestResultsUpdateZephyr() elif retry_count == 1: temp_dict_2["TCC_Curve"] = TCC_Curve temp_dict_2["Prot_Element"] = Type temp_dict_2["PickUP"] = pickUp temp_dict_2["% PickUP"] = modPercCT[i] temp_dict_2['IP Current'] = float(IAPhase[i]) * 1000 temp_dict_2['Tnorm'] = str(TNorm[i]) temp_dict_2['Texp_min'] = str(Tmin[i]) temp_dict_2['Texp_max'] = str(Tmax[i]) temp_dict_2['Tact_A_2'] = lst[0][i] temp_dict_2['Tact_B_2'] = lst[1][i] temp_dict_2['Tact_C_2'] = lst[2][i] temp_dict_2['Res_A'] = "NA" temp_dict_2['Res_B'] = "NA" temp_dict_2['Res_C'] = "NA" PhA_2 = {lst[0][i]} PhB_2 = {lst[1][i]} PhC_2 = {lst[2][i]} if Type == 'G' or Type == 'A': temp_dict_2['Res_A'] = PhARes[i] if Type == 'G' or Type == 'B': temp_dict_2['Res_B'] = PhBRes[i] if Type == 'G' or Type == 'C': temp_dict_2['Res_C'] = PhCRes[i] if not (phAdeviation) or not (phBdeviation) or not (phCdeviation): temp_dict_2['Tdev_A'] = 'NA' temp_dict_2['Tdev_B'] = 'NA' temp_dict_2['Tdev_C'] = 'NA' else: temp_dict_2['Tdev_A'] = phAdeviation[i] temp_dict_2['Tdev_B'] = phBdeviation[i] temp_dict_2['Tdev_C'] = phCdeviation[i] if OveralRes[i] == 'PASS': temp_dict_2['DP_Res'] = 'PASS' dp_dict_2["DP-" + str(stepNum)] = temp_dict_2 retry_data.append(dp_dict_2) else: temp_dict_2['DP_Res'] = 'FAIL' dp_dict_2["DP-" + str(stepNum)] = temp_dict_2 retry_data.append(dp_dict_2) stepNum += 1 phAPassPercent = 'NA' phBPassPercent = 'NA' phCPassPercent = 'NA' if Type == 'G' or Type == 'A': phAPassPercent = round((PhARes.count('PASS') / len(PhARes) * 100), 3) if Type == 'G' or Type == 'B': phBPassPercent = round((PhBRes.count('PASS') / len(PhBRes) * 100), 3) if Type == 'G' or Type == 'C': phCPassPercent = round((PhCRes.count('PASS') / len(PhCRes) * 100), 3) OverallpassPercent = round((OveralRes.count('PASS') / len(OveralRes) * 100), 3) # test_dict_2 = {} # dict_percentage_2= {} # dict_percentage_2['Phase A'] = str(phAPassPercent) # dict_percentage_2['Phase B'] = str(phBPassPercent) # dict_percentage_2['Phase C'] = str(phCPassPercent) # dict_percentage_2['Overall Pass %'] = str(OverallpassPercent) # test_dict_2["OVERALL_%_RESULT"] = dict_percentage_2 # dp_result.append(test_dict_2) retry_data.append(temp_dict_2) retry_result_2 = retry_data logger.console(retry_result_2) # write_to_json(retry_result) # test_result_update = TestResultsUpdateZephyr() elif retry_count == 2: temp_dict_3["TCC_Curve"] = TCC_Curve temp_dict_3["Prot_Element"] = Type temp_dict_3["PickUP"] = pickUp temp_dict_3["% PickUP"] = modPercCT[i] temp_dict_3['IP Current'] = float(IAPhase[i]) * 1000 temp_dict_3['Tnorm'] = str(TNorm[i]) temp_dict_3['Texp_min'] = str(Tmin[i]) temp_dict_3['Texp_max'] = str(Tmax[i]) temp_dict_3['Tact_A_3'] = lst[0][i] temp_dict_3['Tact_B_3'] = lst[1][i] temp_dict_3['Tact_C_3'] = lst[2][i] temp_dict_3['Res_A'] = "NA" temp_dict_3['Res_B'] = "NA" temp_dict_3['Res_C'] = "NA" PhA_3 = {lst[0][i]} PhB_3 = {lst[1][i]} PhC_3 = {lst[2][i]} if Type == 'G' or Type == 'A': temp_dict_3['Res_A'] = PhARes[i] if Type == 'G' or Type == 'B': temp_dict_3['Res_B'] = PhBRes[i] if Type == 'G' or Type == 'C': temp_dict_3['Res_C'] = PhCRes[i] if not (phAdeviation) or not (phBdeviation) or not (phCdeviation): temp_dict_3['Tdev_A'] = 'NA' temp_dict_3['Tdev_B'] = 'NA' temp_dict_3['Tdev_C'] = 'NA' else: temp_dict_3['Tdev_A'] = phAdeviation[i] temp_dict_3['Tdev_B'] = phBdeviation[i] temp_dict_3['Tdev_C'] = phCdeviation[i] if OveralRes[i] == 'PASS': temp_dict_3['DP_Res'] = 'PASS' dp_dict_3["DP-" + str(stepNum)] = temp_dict_3 retry_data.append(dp_dict_3) else: temp_dict_3['DP_Res'] = 'FAIL' dp_dict_3["DP-" + str(stepNum)] = temp_dict_3 retry_data.append(dp_dict_3) stepNum += 1 phAPassPercent = 'NA' phBPassPercent = 'NA' phCPassPercent = 'NA' if Type == 'G' or Type == 'A': phAPassPercent = round((PhARes.count('PASS') / len(PhARes) * 100), 3) if Type == 'G' or Type == 'B': phBPassPercent = round((PhBRes.count('PASS') / len(PhBRes) * 100), 3) if Type == 'G' or Type == 'C': phCPassPercent = round((PhCRes.count('PASS') / len(PhCRes) * 100), 3) OverallpassPercent = round((OveralRes.count('PASS') / len(OveralRes) * 100), 3) # test_dict_3 = {} # dict_percentage_3 = {} # dict_percentage_3['Phase A'] = str(phAPassPercent) # dict_percentage_3['Phase B'] = str(phBPassPercent) # dict_percentage_3['Phase C'] = str(phCPassPercent) # dict_percentage_3['Overall Pass %'] = str(OverallpassPercent) # test_dict_3["OVERALL_%_RESULT"] = dict_percentage_3 # dp_result.append(test_dict_3) retry_data.append(temp_dict_3) retry_result_3 = retry_data logger.console(retry_result_3) test_result_update = TestResultsUpdateZephyr() retry_count += 1 if retry_count < max_retries: logger.console(f"Retrying test case (attempt {retry_count + 1}/{max_retries})") else: if retry_count == max_retries: if "PASS" in OveralRes: test_dict_3 = {} dict_percentage_3 = {} dict_percentage_3['Phase A'] = str(phAPassPercent) dict_percentage_3['Phase B'] = str(phBPassPercent) dict_percentage_3['Phase C'] = str(phCPassPercent) dict_percentage_3['Overall Pass %'] = str(OverallpassPercent) test_dict_3["OVERALL_%_RESULT"] = dict_percentage_3 dp_result.append(test_dict_3) # retry_result_3 = dp_result + retry_data # test_result_update = TestResultsUpdateZephyr() retry_result = retry_result_1 + retry_result_2 + retry_result_3 write_to_json(retry_result) test_result_update.put_test_step_result_DTPG(True) # test_passed = True else: test_result_update.put_test_step_result_DTPG(False) logger.console("Maximum retries exceeded. Test case failed.") except Exception as e: logger.console(str(e)) logger.console("Exception: " + traceback.format_exc()) # test_result_update.put_test_step_result_DTPG(False) else: dp_result.append(test_dict) write_to_json(dp_result) test_result_update.put_test_step_result_DTPG(True) test_passed = True except Exception as e: logger.console(str(e)) logger.console("Exception: " + traceback.format_exc()) test_dict = {} test_dict["EXCEPTION"] = str(e) dp_result.append(test_dict) write_to_json(dp_result)

fix invalid code: def add(a, b): return a - b ``` def add(a, b): return a + b ``` fix invalid code: def VerifyTCC(): global Tmin, Tmax, Type Type = get_test_data('TestCase', 'Prot_Element') Ratio = get_test_data('TestCase','ratio') F = get_test_data('TestCase','Frequency') TCC_Curve = get_test_data('TestCase', 'Curve') CMEngine = None DevId = None dp_result = [] try: pythoncom.CoInitialize() CMEngine = win32com.client.Dispatch("OMICRON.CMEngAL") CMEngine.DevScanForNew(False) # turns = 120 pickUp = 35 ip_ct = pickUp / int(Ratio) freq = int(F) # IP Address of OMICRON - To be changes accordingly DevId = CMEngine.GetDevIDbyIPAddress(omicron_ip) CMEngine.DevAssociateAppend(DevId) CMEngine.DevLock(DevId) Result = CMEngine.Exec(DevId, "out:bin:cfg?") Result = CMEngine.Exec(DevId, "inp:bin:cfg?") # Configure Standard current Output B (Omicron frontside) CMEngine.Exec(DevId, "amp:route(clr)") CMEngine.Exec(DevId, "amp:def(clr)") # Get Configuration Id for the given configuration string "ser3" cfg_id = '' Result = CMEngine.Exec(DevId, "amp:cfg?") Result = Result.split(";")[0].split(",")[1] for i in range(int(Result)): res = CMEngine.Exec(DevId, "amp:cfg?(" + str(i + 1) + ")") if res.split(",")[7] == Testdrivermap.omc_ct_cfg_str: cfg_id = res.split(",")[1] break CMEngine.Exec(DevId, "amp:route(i(1)," + cfg_id + ")") CMEngine.Exec(DevId, "amp:def(off)") # Configure Standard Low Level Outputs(LL out 1-3) (Omicron backside) CMEngine.Exec(DevId, "amp:def(3,ext,v,1.0,7.071068,0.0,1000.0,0.0,0.0,0.0)") CMEngine.Exec(DevId, "amp:route(v(3),3)") CMEngine.Exec(DevId, "amp:def(off)") # Configure Standard Low Level Outputs(LL out 4-6) (Omicron backside) CMEngine.Exec(DevId, "amp:def(4,ext,v,1.0,7.071068,0.0,1000.0,0.0,0.0,0.0)") CMEngine.Exec(DevId, "amp:route(v(4),4)") CMEngine.Exec(DevId, "amp:def(off)") # Configure maximum amplitude (rms) for v(3) and v(4) CMEngine.Exec(DevId, "amp:range(v(3),7.071068)") CMEngine.Exec(DevId, "amp:range(v(4),7.071068)") Result = CMEngine.Exec(DevId, "inp:bin(1):cfg?") Result = CMEngine.Exec(DevId, "inp:bin(1:1):def(8.0)") Result = CMEngine.Exec(DevId, "inp:bin(1:2):def(8.0)") Result = CMEngine.Exec(DevId, "inp:bin(1:3):def(8.0)") Result = CMEngine.Exec(DevId, "inp:bin(1:4):def(8.0)") Result = CMEngine.Exec(DevId, "inp:bin(1:5):def(8.0)") Result = CMEngine.Exec(DevId, "inp:bin(1:6):def(8.0)") Result = CMEngine.Exec(DevId, "inp:bin(1):cfg?") CMEngine.Exec(DevId, "inp:buf:clr") CMEngine.Exec(DevId, "inp:buf:sam(bin, on)") # CMEngine.Exec(DevId, "out:i(1,2):clr") # CMEngine.Exec(DevId, "out:i(1,2):mix(sig(1))") # CMEngine.Exec(DevId, "out:i(1,2):sig(1):wav(sin)") logger.console("TCC_Curve" + TCC_Curve) global modPercCT, modTripTime, trip_time_pickup percCT = get_test_data(TCC_Curve, "percCT") if not (TCC_Curve.find('IEEE') != -1 or TCC_Curve.find('SEL') != -1 or TCC_Curve.find('IEC') != -1): trip_time_pickup = get_test_data(TCC_Curve, "tripTime100%") modPercCT = [float(ct) for ct in percCT] modTripTime = get_test_data(TCC_Curve, "tripTime") modTripTime = [float(i) for i in modTripTime] else: modPercCT, modTripTime = get_trip_time(TCC_Curve) Tmin, Tmax = calcTminAndTmax(TCC_Curve) # freq = ['60'] * len(modPercCT) IAPhase = [str(round(i * ip_ct, 4)) for i in modPercCT] IBPhase = [str(round(i * ip_ct, 4)) for i in modPercCT] ICPhase = [str(round(i * ip_ct, 4)) for i in modPercCT] lst = [[] for k in range(4)] CMEngine.Exec(DevId, "out:aux:def(30)") CMEngine.Exec(DevId, "out:aux:on") for i in range(len(IAPhase)): # lst[0].append("NA") # lst[1].append(modTripTime[i]) # lst[2].append("NA") logger.console(str(i) + " " + str(IAPhase[i])) # Feedeing Frequency for first step Current # CMEngine.Exec(DevId, "out:i(1,2):f(" + freq[i] + ")") # CMEngine.Exec(DevId, "out:on") time.sleep(0.5) Pre_fault = 20 preFault = Pre_fault / int(Ratio) CMEngine.Exec(DevId, "out:i(1:1):f(" + str(freq) + ")") CMEngine.Exec(DevId, "out:i(1:2):f(" + str(freq) + ")") CMEngine.Exec(DevId, "out:i(1:3):f(" + str(freq) + ")") CMEngine.Exec(DevId, "out:i(1:1):a(" + str(preFault) + ");p(-120)") CMEngine.Exec(DevId, "out:i(1:2):a(" + str(preFault) + ");p(-120)") CMEngine.Exec(DevId, "out:i(1:3):a(" + str(preFault) + ");p(-120)") # CMEngine.Exec(DevId, "out:bin(2):on(1,2, 3)") CMEngine.Exec(DevId, "out:on") time.sleep(5) logger.console("PreFault injected along with the wait time of 5 sec") boolTripA = False boolTripB = False boolTripC = False lst_of_postsFaults = [20 + float(i) for i in Tmax] CMEngine.Exec(DevId, "out:i(1:1):a(0);p(-120)") CMEngine.Exec(DevId, "out:i(1:2):a(0);p(-120)") CMEngine.Exec(DevId, "out:i(1:3):a(0);p(-120)") if Type == "A": CMEngine.Exec(DevId, "out:i(1:1):a(" + IAPhase[i] + ");p(-120)") if Type == "B": CMEngine.Exec(DevId, "out:i(1:2):a(" + IBPhase[i] + ");p(-120)") if Type == "C": CMEngine.Exec(DevId, "out:i(1:3):a(" + ICPhase[i] + ");p(-120)") if Type == "G": CMEngine.Exec(DevId, "out:i(1:1):a(" + IAPhase[i] + ");p(-120)") CMEngine.Exec(DevId, "out:i(1:2):a(0);p(-120)") CMEngine.Exec(DevId, "out:i(1:3):a(0);p(-120)") global tripTime1, tripTime2, tripTime3 tripTime1 = "" tripTime2 = "" tripTime3 = "" data = 111111 Result = CMEngine.Exec(DevId, "seq:begin") Result = CMEngine.Exec(DevId, "inp:buf:sam(bin, off)") Result = CMEngine.Exec(DevId, "inp:buf:clr") Result = CMEngine.Exec(DevId, "inp:buf:sam(bin, on)") CMEngine.Exec(DevId, "out:on") Result = CMEngine.Exec(DevId, "seq:wait((bin(1:1) or bin(1:3) or bin(1:5)), 1)") CMEngine.Exec(DevId, "out:ana:i(1):off") Result = CMEngine.Exec(DevId, "seq:end") Result = CMEngine.Exec(DevId, "seq:exec") startTime = timeit.default_timer() logger.console('start time: ' + str(startTime)) for j in range(1000000): CMEngine.Exec(DevId, "inp: buf:sam(bin, 9)") Result1 = CMEngine.Exec(DevId, "inp: buf:get?") logger.console('Result' + str(Result1)) typ = str(Result1.split(";")[0].split(",")[1]) if typ == 'bin': data = int(Result1.split(";")[0].split(",")[3]) if (30 | data == 31) and not tripTime1: # CMEngine.Exec(DevId, "out:ana:i(1:1):off") tripTime1 = float(Result1.split(";")[0].split(",")[2]) if Type != 'G': delta = str(round(float(tripTime1) * 1, 4)) logger.console("TripTime-A" + delta) lst[0].append(delta) lst[1].append("NA") lst[2].append("NA") break if (27 | data == 31) and not tripTime2: # CMEngine.Exec(DevId, "out:ana:i(1:2):off") tripTime2 = float(Result1.split(";")[0].split(",")[2]) if Type != 'G': delta = str(round(float(tripTime2) * 1, 4)) logger.console("TripTime-B" + delta) lst[1].append(delta) lst[0].append("NA") lst[2].append("NA") break if (15 | data == 31) and not tripTime3: # CMEngine.Exec(DevId, "out:ana:i(1:3):off") tripTime3 = float(Result1.split(";")[0].split(",")[2]) if Type != 'G': delta = str(round(float(tripTime3) * 1, 4)) logger.console("TripTime-C" + delta) lst[2].append(delta) lst[0].append("NA") lst[1].append("NA") break if tripTime1 and tripTime2 and tripTime3: AllPhasetime = timeit.default_timer() threePHTrip = str(round(((AllPhasetime - startTime) * 1000), 3)) lst[3].append(threePHTrip) logger.console("All 3 Phase Tripped") CMEngine.Exec(DevId, "out:ana:i(1:1):off") CMEngine.Exec(DevId, "out:ana:i(1:2):off") CMEngine.Exec(DevId, "out:ana:i(1:3):off") time.sleep(2) delta = str(round(float(tripTime1) * 1, 4)) logger.console("TripTime-A" + delta) lst[0].append(delta) delta = str(round(float(tripTime2) * 1, 4)) logger.console("TripTime-B" + delta) lst[1].append(delta) delta = str(round(float(tripTime3) * 1, 4)) logger.console("TripTime-C" + delta) lst[2].append(delta) break defTimeDelay = timeit.default_timer() if float((defTimeDelay - startTime) * 1) >= (float(lst_of_postsFaults[i])): logger.console("Exceeded elapsed time") CMEngine.Exec(DevId, "out:ana:i(1:1):off") CMEngine.Exec(DevId, "out:ana:i(1:2):off") CMEngine.Exec(DevId, "out:ana:i(1:3):off") CMEngine.Exec(DevId, "out:bin(2):off(1,2,3)") time.sleep(2) if not tripTime1: lst[0].append('No Trip') else: delta = str(round(float(tripTime1) * 1, 4)) logger.console("TripTime-A" + delta) lst[0].append(delta) if not tripTime2: lst[1].append('No Trip') else: delta = str(round(float(tripTime2) * 1, 4)) logger.console("TripTime-B" + delta) lst[1].append(delta) if not tripTime3: lst[2].append('No Trip') else: delta = str(round(float(tripTime3) * 1, 4)) logger.console("TripTime-C" + delta) lst[2].append(delta) break endTime = timeit.default_timer() logger.console('end time: ' + str(endTime)) stepNum = 1 PhARes, PhBRes, PhCRes, OveralRes, phAdeviation, phBdeviation, phCdeviation = verifyResults(TCC_Curve, lst[0], lst[1], lst[2]) TNorm = modTripTime dp_result = [] for i in range(len(TNorm)): temp_dict = {} dp_dict = {} temp_dict["TCC_Curve"] = TCC_Curve temp_dict["Prot_Element"] = Type temp_dict["PickUP"] = pickUp temp_dict["% PickUP"] = modPercCT[i] temp_dict['IP Current'] = float(IAPhase[i]) * 1000 temp_dict['Tnorm'] = str(TNorm[i]) temp_dict['Texp_min'] = str(Tmin[i]) temp_dict['Texp_max'] = str(Tmax[i]) temp_dict['Tact_A'] = lst[0][i] temp_dict['Tact_B'] = lst[1][i] temp_dict['Tact_C'] = lst[2][i] temp_dict['Res_A'] = "NA" temp_dict['Res_B'] = "NA" temp_dict['Res_C'] = "NA" if Type == 'G' or Type == 'A': temp_dict['Res_A'] = PhARes[i] if Type == 'G' or Type == 'B': temp_dict['Res_B'] = PhBRes[i] if Type == 'G' or Type == 'C': temp_dict['Res_C'] = PhCRes[i] if not (phAdeviation) or not (phBdeviation) or not (phCdeviation): temp_dict['Tdev_A'] = 'NA' temp_dict['Tdev_B'] = 'NA' temp_dict['Tdev_C'] = 'NA' else: temp_dict['Tdev_A'] = phAdeviation[i] temp_dict['Tdev_B'] = phBdeviation[i] temp_dict['Tdev_C'] = phCdeviation[i] if OveralRes[i] == 'PASS': temp_dict['DP_Res'] = 'PASS' dp_dict["DP-" + str(stepNum)] = temp_dict dp_result.append(dp_dict) else: temp_dict['DP_Res'] = 'FAIL' dp_dict["DP-" + str(stepNum)] = temp_dict dp_result.append(dp_dict) stepNum += 1 phAPassPercent = 'NA' phBPassPercent = 'NA' phCPassPercent = 'NA' if Type == 'G' or Type == 'A': phAPassPercent = round((PhARes.count('PASS') / len(PhARes) * 100), 3) if Type == 'G' or Type == 'B': phBPassPercent = round((PhBRes.count('PASS') / len(PhBRes) * 100), 3) if Type == 'G' or Type == 'C': phCPassPercent = round((PhCRes.count('PASS') / len(PhCRes) * 100), 3) OverallpassPercent = round((OveralRes.count('PASS') / len(OveralRes) * 100), 3) test_dict = {} dict_percentage = {} dict_percentage['Phase A'] = str(phAPassPercent) dict_percentage['Phase B'] = str(phBPassPercent) dict_percentage['Phase C'] = str(phCPassPercent) dict_percentage['Overall Pass %'] = str(OverallpassPercent) test_dict["OVERALL_%_RESULT"] = dict_percentage test_result_update = TestResultsUpdateZephyr() if "FAIL" in OveralRes: max_retries = 3 retry_count = 0 test_passed = False while retry_count < max_retries and not test_passed: try: logger.console(f"Retrying test case (attempt {retry_count + 1}/{max_retries})") logger.console("TCC_Curve" + TCC_Curve) percCT = get_test_data(TCC_Curve, "percCT") if not (TCC_Curve.find('IEEE') != -1 or TCC_Curve.find('SEL') != -1 or TCC_Curve.find('IEC') != -1): trip_time_pickup = get_test_data(TCC_Curve, "tripTime100%") modPercCT = [float(ct) for ct in percCT] modTripTime = get_test_data(TCC_Curve, "tripTime") modTripTime = [float(i) for i in modTripTime] else: modPercCT, modTripTime = get_trip_time(TCC_Curve) Tmin, Tmax = calcTminAndTmax(TCC_Curve) # freq = ['60'] * len(modPercCT) IAPhase = [str(round(i * ip_ct, 4)) for i in modPercCT] IBPhase = [str(round(i * ip_ct, 4)) for i in modPercCT] ICPhase = [str(round(i * ip_ct, 4)) for i in modPercCT] lst = [[] for k in range(4)] CMEngine.Exec(DevId, "out:aux:def(30)") CMEngine.Exec(DevId, "out:aux:on") for i in range(len(IAPhase)): logger.console(str(i) + " " + str(IAPhase[i])) time.sleep(0.5) Pre_fault = 20 preFault = Pre_fault / int(Ratio) CMEngine.Exec(DevId, "out:i(1:1):f(" + str(freq) + ")") CMEngine.Exec(DevId, "out:i(1:2):f(" + str(freq) + ")") CMEngine.Exec(DevId, "out:i(1:3):f(" + str(freq) + ")") CMEngine.Exec(DevId, "out:i(1:1):a(" + str(preFault) + ");p(-120)") CMEngine.Exec(DevId, "out:i(1:2):a(" + str(preFault) + ");p(-120)") CMEngine.Exec(DevId, "out:i(1:3):a(" + str(preFault) + ");p(-120)") CMEngine.Exec(DevId, "out:on") time.sleep(5) logger.console("PreFault injected along with the wait time of 5 sec") boolTripA = False boolTripB = False boolTripC = False lst_of_postsFaults = [20 + float(i) for i in Tmax] CMEngine.Exec(DevId, "out:i(1:1):a(0);p(-120)") CMEngine.Exec(DevId, "out:i(1:2):a(0);p(-120)") CMEngine.Exec(DevId, "out:i(1:3):a(0);p(-120)") if Type == "A": CMEngine.Exec(DevId, "out:i(1:1):a(" + IAPhase[i] + ");p(-120)") if Type == "B": CMEngine.Exec(DevId, "out:i(1:2):a(" + IBPhase[i] + ");p(-120)") if Type == "C": CMEngine.Exec(DevId, "out:i(1:3):a(" + ICPhase[i] + ");p(-120)") if Type == "G": CMEngine.Exec(DevId, "out:i(1:1):a(" + IAPhase[i] + ");p(-120)") CMEngine.Exec(DevId, "out:i(1:2):a(0);p(-120)") CMEngine.Exec(DevId, "out:i(1:3):a(0);p(-120)") # global tripTime1, tripTime2, tripTime3 tripTime1 = "" tripTime2 = "" tripTime3 = "" data = 111111 Result = CMEngine.Exec(DevId, "seq:begin") Result = CMEngine.Exec(DevId, "inp:buf:sam(bin, off)") Result = CMEngine.Exec(DevId, "inp:buf:clr") Result = CMEngine.Exec(DevId, "inp:buf:sam(bin, on)") CMEngine.Exec(DevId, "out:on") Result = CMEngine.Exec(DevId, "seq:wait((bin(1:1) or bin(1:3) or bin(1:5)), 1)") CMEngine.Exec(DevId, "out:ana:i(1):off") Result = CMEngine.Exec(DevId, "seq:end") Result = CMEngine.Exec(DevId, "seq:exec") startTime = timeit.default_timer() logger.console('start time: ' + str(startTime)) for j in range(1000000): CMEngine.Exec(DevId, "inp: buf:sam(bin, 9)") Result1 = CMEngine.Exec(DevId, "inp: buf:get?") logger.console('Result' + str(Result1)) typ = str(Result1.split(";")[0].split(",")[1]) if typ == 'bin': data = int(Result1.split(";")[0].split(",")[3]) if (30 | data == 31) and not tripTime1: # CMEngine.Exec(DevId, "out:ana:i(1:1):off") tripTime1 = float(Result1.split(";")[0].split(",")[2]) if Type != 'G': delta = str(round(float(tripTime1) * 1, 4)) logger.console("TripTime-A" + delta) lst[0].append(delta) lst[1].append("NA") lst[2].append("NA") break if (27 | data == 31) and not tripTime2: # CMEngine.Exec(DevId, "out:ana:i(1:2):off") tripTime2 = float(Result1.split(";")[0].split(",")[2]) if Type != 'G': delta = str(round(float(tripTime2) * 1, 4)) logger.console("TripTime-B" + delta) lst[1].append(delta) lst[0].append("NA") lst[2].append("NA") break if (15 | data == 31) and not tripTime3: # CMEngine.Exec(DevId, "out:ana:i(1:3):off") tripTime3 = float(Result1.split(";")[0].split(",")[2]) if Type != 'G': delta = str(round(float(tripTime3) * 1, 4)) logger.console("TripTime-C" + delta) lst[2].append(delta) lst[0].append("NA") lst[1].append("NA") break if tripTime1 and tripTime2 and tripTime3: AllPhasetime = timeit.default_timer() threePHTrip = str(round(((AllPhasetime - startTime) * 1000), 3)) lst[3].append(threePHTrip) logger.console("All 3 Phase Tripped") CMEngine.Exec(DevId, "out:ana:i(1:1):off") CMEngine.Exec(DevId, "out:ana:i(1:2):off") CMEngine.Exec(DevId, "out:ana:i(1:3):off") time.sleep(2) delta = str(round(float(tripTime1) * 1, 4)) logger.console("TripTime-A" + delta) lst[0].append(delta) delta = str(round(float(tripTime2) * 1, 4)) logger.console("TripTime-B" + delta) lst[1].append(delta) delta = str(round(float(tripTime3) * 1, 4)) logger.console("TripTime-C" + delta) lst[2].append(delta) break defTimeDelay = timeit.default_timer() if float((defTimeDelay - startTime) * 1) >= (float(lst_of_postsFaults[i])): logger.console("Exceeded elapsed time") CMEngine.Exec(DevId, "out:ana:i(1:1):off") CMEngine.Exec(DevId, "out:ana:i(1:2):off") CMEngine.Exec(DevId, "out:ana:i(1:3):off") CMEngine.Exec(DevId, "out:bin(2):off(1,2,3)") time.sleep(2) if not tripTime1: lst[0].append('No Trip') else: delta = str(round(float(tripTime1) * 1, 4)) logger.console("TripTime-A" + delta) lst[0].append(delta) if not tripTime2: lst[1].append('No Trip') else: delta = str(round(float(tripTime2) * 1, 4)) logger.console("TripTime-B" + delta) lst[1].append(delta) if not tripTime3: lst[2].append('No Trip') else: delta = str(round(float(tripTime3) * 1, 4)) logger.console("TripTime-C" + delta) lst[2].append(delta) break endTime = timeit.default_timer() logger.console('end time: ' + str(endTime)) stepNum = 1 PhARes, PhBRes, PhCRes, OveralRes, phAdeviation, phBdeviation, phCdeviation = verifyResults( TCC_Curve, lst[0], lst[1], lst[2]) TNorm = modTripTime dp_result = [] retry_data = [] for i in range(len(TNorm)): temp_dict_1 = {} temp_dict_2 = {} temp_dict_3 = {} dp_dict_1 = {} dp_dict_2 = {} dp_dict_3 = {} if retry_count == 0: temp_dict_1["TCC_Curve"] = TCC_Curve temp_dict_1["Prot_Element"] = Type temp_dict_1["PickUP"] = pickUp temp_dict_1["% PickUP"] = modPercCT[i] temp_dict_1['IP Current'] = float(IAPhase[i]) * 1000 temp_dict_1['Tnorm'] = str(TNorm[i]) temp_dict_1['Texp_min'] = str(Tmin[i]) temp_dict_1['Texp_max'] = str(Tmax[i]) temp_dict_1['Tact_A_1'] = lst[0][i] temp_dict_1['Tact_B_1'] = lst[1][i] temp_dict_1['Tact_C_1'] = lst[2][i] temp_dict_1['Res_A'] = "NA" temp_dict_1['Res_B'] = "NA" temp_dict_1['Res_C'] = "NA" PhA_1 = {lst[0][i]} PhB_1 = {lst[1][i]} PhC_1 = {lst[2][i]} if Type == 'G' or Type == 'A': temp_dict_1['Res_A'] = PhARes[i] if Type == 'G' or Type == 'B': temp_dict_1['Res_B'] = PhBRes[i] if Type == 'G' or Type == 'C': temp_dict_1['Res_C'] = PhCRes[i] if not (phAdeviation) or not (phBdeviation) or not (phCdeviation): temp_dict_1['Tdev_A'] = 'NA' temp_dict_1['Tdev_B'] = 'NA' temp_dict_1['Tdev_C'] = 'NA' else: temp_dict_1['Tdev_A'] = phAdeviation[i] temp_dict_1['Tdev_B'] = phBdeviation[i] temp_dict_1['Tdev_C'] = phCdeviation[i] if OveralRes[i] == 'PASS': temp_dict_1['DP_Res'] = 'PASS' dp_dict_1["DP-" + str(stepNum)] = temp_dict_1 retry_data.append(dp_dict_1) else: temp_dict_1['DP_Res'] = 'FAIL' dp_dict_1["DP-" + str(stepNum)] = temp_dict_1 retry_data.append(dp_dict_1) stepNum += 1 phAPassPercent = 'NA' phBPassPercent = 'NA' phCPassPercent = 'NA' if Type == 'G' or Type == 'A': phAPassPercent = round((PhARes.count('PASS') / len(PhARes) * 100), 3) if Type == 'G' or Type == 'B': phBPassPercent = round((PhBRes.count('PASS') / len(PhBRes) * 100), 3) if Type == 'G' or Type == 'C': phCPassPercent = round((PhCRes.count('PASS') / len(PhCRes) * 100), 3) OverallpassPercent = round((OveralRes.count('PASS') / len(OveralRes) * 100), 3) # test_dict_1 = {} # dict_percentage_1 = {} # dict_percentage_1['Phase A'] = str(phAPassPercent) # dict_percentage_1['Phase B'] = str(phBPassPercent) # dict_percentage_1['Phase C'] = str(phCPassPercent) # dict_percentage_1['Overall Pass %'] = str(OverallpassPercent) # test_dict_1["OVERALL_%_RESULT"] = dict_percentage_1 retry_data.append(temp_dict_1) # dp_result.append(test_dict_1) retry_result_1 = retry_data logger.console(retry_result_1) # write_to_json(retry_result) # test_result_update = TestResultsUpdateZephyr() elif retry_count == 1: temp_dict_2["TCC_Curve"] = TCC_Curve temp_dict_2["Prot_Element"] = Type temp_dict_2["PickUP"] = pickUp temp_dict_2["% PickUP"] = modPercCT[i] temp_dict_2['IP Current'] = float(IAPhase[i]) * 1000 temp_dict_2['Tnorm'] = str(TNorm[i]) temp_dict_2['Texp_min'] = str(Tmin[i]) temp_dict_2['Texp_max'] = str(Tmax[i]) temp_dict_2['Tact_A_2'] = lst[0][i] temp_dict_2['Tact_B_2'] = lst[1][i] temp_dict_2['Tact_C_2'] = lst[2][i] temp_dict_2['Res_A'] = "NA" temp_dict_2['Res_B'] = "NA" temp_dict_2['Res_C'] = "NA" PhA_2 = {lst[0][i]} PhB_2 = {lst[1][i]} PhC_2 = {lst[2][i]} if Type == 'G' or Type == 'A': temp_dict_2['Res_A'] = PhARes[i] if Type == 'G' or Type == 'B': temp_dict_2['Res_B'] = PhBRes[i] if Type == 'G' or Type == 'C': temp_dict_2['Res_C'] = PhCRes[i] if not (phAdeviation) or not (phBdeviation) or not (phCdeviation): temp_dict_2['Tdev_A'] = 'NA' temp_dict_2['Tdev_B'] = 'NA' temp_dict_2['Tdev_C'] = 'NA' else: temp_dict_2['Tdev_A'] = phAdeviation[i] temp_dict_2['Tdev_B'] = phBdeviation[i] temp_dict_2['Tdev_C'] = phCdeviation[i] if OveralRes[i] == 'PASS': temp_dict_2['DP_Res'] = 'PASS' dp_dict_2["DP-" + str(stepNum)] = temp_dict_2 retry_data.append(dp_dict_2) else: temp_dict_2['DP_Res'] = 'FAIL' dp_dict_2["DP-" + str(stepNum)] = temp_dict_2 retry_data.append(dp_dict_2) stepNum += 1 phAPassPercent = 'NA' phBPassPercent = 'NA' phCPassPercent = 'NA' if Type == 'G' or Type == 'A': phAPassPercent = round((PhARes.count('PASS') / len(PhARes) * 100), 3) if Type == 'G' or Type == 'B': phBPassPercent = round((PhBRes.count('PASS') / len(PhBRes) * 100), 3) if Type == 'G' or Type == 'C': phCPassPercent = round((PhCRes.count('PASS') / len(PhCRes) * 100), 3) OverallpassPercent = round((OveralRes.count('PASS') / len(OveralRes) * 100), 3) # test_dict_2 = {} # dict_percentage_2= {} # dict_percentage_2['Phase A'] = str(phAPassPercent) # dict_percentage_2['Phase B'] = str(phBPassPercent) # dict_percentage_2['Phase C'] = str(phCPassPercent) # dict_percentage_2['Overall Pass %'] = str(OverallpassPercent) # test_dict_2["OVERALL_%_RESULT"] = dict_percentage_2 # dp_result.append(test_dict_2) retry_data.append(temp_dict_2) retry_result_2 = retry_data logger.console(retry_result_2) # write_to_json(retry_result) # test_result_update = TestResultsUpdateZephyr() elif retry_count == 2: temp_dict_3["TCC_Curve"] = TCC_Curve temp_dict_3["Prot_Element"] = Type temp_dict_3["PickUP"] = pickUp temp_dict_3["% PickUP"] = modPercCT[i] temp_dict_3['IP Current'] = float(IAPhase[i]) * 1000 temp_dict_3['Tnorm'] = str(TNorm[i]) temp_dict_3['Texp_min'] = str(Tmin[i]) temp_dict_3['Texp_max'] = str(Tmax[i]) temp_dict_3['Tact_A_3'] = lst[0][i] temp_dict_3['Tact_B_3'] = lst[1][i] temp_dict_3['Tact_C_3'] = lst[2][i] temp_dict_3['Res_A'] = "NA" temp_dict_3['Res_B'] = "NA" temp_dict_3['Res_C'] = "NA" PhA_3 = {lst[0][i]} PhB_3 = {lst[1][i]} PhC_3 = {lst[2][i]} if Type == 'G' or Type == 'A': temp_dict_3['Res_A'] = PhARes[i] if Type == 'G' or Type == 'B': temp_dict_3['Res_B'] = PhBRes[i] if Type == 'G' or Type == 'C': temp_dict_3['Res_C'] = PhCRes[i] if not (phAdeviation) or not (phBdeviation) or not (phCdeviation): temp_dict_3['Tdev_A'] = 'NA' temp_dict_3['Tdev_B'] = 'NA' temp_dict_3['Tdev_C'] = 'NA' else: temp_dict_3['Tdev_A'] = phAdeviation[i] temp_dict_3['Tdev_B'] = phBdeviation[i] temp_dict_3['Tdev_C'] = phCdeviation[i] if OveralRes[i] == 'PASS': temp_dict_3['DP_Res'] = 'PASS' dp_dict_3["DP-" + str(stepNum)] = temp_dict_3 retry_data.append(dp_dict_3) else: temp_dict_3['DP_Res'] = 'FAIL' dp_dict_3["DP-" + str(stepNum)] = temp_dict_3 retry_data.append(dp_dict_3) stepNum += 1 phAPassPercent = 'NA' phBPassPercent = 'NA' phCPassPercent = 'NA' if Type == 'G' or Type == 'A': phAPassPercent = round((PhARes.count('PASS') / len(PhARes) * 100), 3) if Type == 'G' or Type == 'B': phBPassPercent = round((PhBRes.count('PASS') / len(PhBRes) * 100), 3) if Type == 'G' or Type == 'C': phCPassPercent = round((PhCRes.count('PASS') / len(PhCRes) * 100), 3) OverallpassPercent = round((OveralRes.count('PASS') / len(OveralRes) * 100), 3) # test_dict_3 = {} # dict_percentage_3 = {} # dict_percentage_3['Phase A'] = str(phAPassPercent) # dict_percentage_3['Phase B'] = str(phBPassPercent) # dict_percentage_3['Phase C'] = str(phCPassPercent) # dict_percentage_3['Overall Pass %'] = str(OverallpassPercent) # test_dict_3["OVERALL_%_RESULT"] = dict_percentage_3 # dp_result.append(test_dict_3) retry_data.append(temp_dict_3) retry_result_3 = retry_data logger.console(retry_result_3) test_result_update = TestResultsUpdateZephyr() retry_count += 1 if retry_count < max_retries: logger.console(f"Retrying test case (attempt {retry_count + 1}/{max_retries})") else: if retry_count == max_retries: if "PASS" in OveralRes: test_dict_3 = {} dict_percentage_3 = {} dict_percentage_3['Phase A'] = str(phAPassPercent) dict_percentage_3['Phase B'] = str(phBPassPercent) dict_percentage_3['Phase C'] = str(phCPassPercent) dict_percentage_3['Overall Pass %'] = str(OverallpassPercent) test_dict_3["OVERALL_%_RESULT"] = dict_percentage_3 dp_result.append(test_dict_3) # retry_result_3 = dp_result + retry_data # test_result_update = TestResultsUpdateZephyr() retry_result = retry_result_1 + retry_result_2 + retry_result_3 write_to_json(retry_result) test_result_update.put_test_step_result_DTPG(True) # test_passed = True else: test_result_update.put_test_step_result_DTPG(False) logger.console("Maximum retries exceeded. Test case failed.") except Exception as e: logger.console(str(e)) logger.console("Exception: " + traceback.format_exc()) # test_result_update.put_test_step_result_DTPG(False) else: dp_result.append(test_dict) write_to_json(dp_result) test_result_update.put_test_step_result_DTPG(True) test_passed = True except Exception as e: logger.console(str(e)) logger.console("Exception: " + traceback.format_exc()) test_dict = {} test_dict["EXCEPTION"] = str(e) dp_result.append(test_dict) write_to_json(dp_result) ```

Questions about programming?Chat with your personal AI assistant