## ------------------------------------------------------------------------- ## This code is for checking Voltage Violations with ANSI C84.1 standard: ## [114V] ---- [120V] ---- [126V] +/-5% ## Ask the user which standard? ## Input file >> CSV of Timestamp and Simulated Measured Service Voltage ## Output >> Voltage Violations Events, If no Voltage Violations detected, No # WARNING: ## Service Voltage used for Range A of ANSI C84.1 Nominal Voltage = 120V ## ------------------------------------------------------------------------- import pandas as pd import numpy as np def ansic84(): ''' handles ansic84 ''' ideal = minLimit = maxLimit = 120 maxLimit += ideal * 0.05 minLimit -= ideal * 0.05 dev = {} f = input("enter file name: ") try: csv = pd.read_csv(f,skiprows=range(0,7),error_bad_lines=False) csv.rename({'# timestamp':'timestamp'},axis='columns',inplace=True) # change values for i in csv.columns[1:]: csv[i] = csv[i].str.replace('d','j') csv[i] = csv[i].apply(lambda x:np.complex(x).real) csv[i] = pd.to_numeric(csv[i]) dev[i+'_min'] = csv[csv[i]<=minLimit] # check for values below minLimit dev[i+'_max'] = csv[csv[i]>=maxLimit] # check for values above maxLimit if dev[i+'_min'].empty: dev[i+'_min'] = 'NO WARNING' if dev[i+'_max'].empty: dev[i+'_max'] = 'NO WARNING' # print( dev[i+'_max']) for k,v in dev.items(): print(f'{"-"*20}{k}{"-"*20}') print(v) print(f"ideal: {ideal} ; max: {maxLimit} ; min: {minLimit}") except Exception as e: print(e) print("-"*5+">Error occured\nexiting...") exit() return def main(): stds = {1:'ANSIC84'} funcs = {'ANSIC84':ansic84} print("enter your desired standard:") std = int(input("[1] - ANSI C84\n[2] - XX\n")) if not std in stds: print("-"*5+">Not a supported standard\nexiting...") exit() print(f"you entered {std} : {stds[std]}") ''' call ansi ''' std = stds[std] funcs[std]() if __name__=="__main__": main() exit() ## ---------------------------------------------------------------------------