def makeFlowLower(): # 调低之前先试一下调整最大误差母线 print('makeFlowLower') with open('ops.txt', 'a', encoding='utf-8') as fi: fi.write('知识:低潮流已调试不收敛->调低潮流\n') ''' x = followIter() for i in x: r = setBus(x) if r == 'success': return 'success' # 试了没用 ''' f = myutils.readflag() cur = f['cur'] step = f['step'] cur -= step step *= 0.5 f['cur'] = cur f['step'] = step f['goone'] = 1 myutils.writeflag(f) if step < 0.002: with open('ops.txt', 'a', encoding='utf-8') as fi: fi.write('潮流调低步长太小,调节失败\n') return 'steptoosmall' return 'pause'
def getFeatures(): f = myutils.readflag() if len(f) == 0: f['r'] = 1.0 f['cur'] = 0.3 f['lastLoad_list'] = [-1, 0] f['step'] = 0.04 f['markList'] = [] r = f['r'] cur = f['cur'] step = f['step'] b = cur/r f['r'] = cur changemx(b) myutils.writeflag(f) os.system('WMLFRTMsg') with open('ops.txt', 'a', encoding='utf-8') as fi: fi.write('当前潮流水平:%d%%\n' % int(cur * 100)) conv = None if not myutils.getflag(): f['goone'] = -1 myutils.writeflag(f) conv = '不收敛' #return -1 #failure else: conv = '收敛' with open('ops.txt', 'a', encoding='utf-8') as fi: fi.write('当前收敛状态:%s\n' % conv) checked = None if ('findLP1' in f) and (f['findLP1'] != None): checked = '已检查' elif ('findLP1' in f) and (f['findLP1'] == None): checked = '已调节' else: checked = '未检查' with open('ops.txt', 'a', encoding='utf-8') as fi: fi.write('异常母线:%s\n' % checked) #### if checked == '已检查': return '有异常母线' if 'goone' in f: goone = f['goone'] if goone == "fail": return 'fail' if goone == -1: # fail return 'goone=-1' if goone == 0: # success if (r - 1) < 0.001 and (r - 1) > -0.001: print('success') return 'success' return 'goone=0' if goone == 1: # unknown , continue print('goone==1') return 'goone' #'goone':检查 else: return 'goone'
def setBus(busn): # 尝试调单个母线 genList = dict() loadList = dict() mx5 = myutils.readfile('LF.L5') for ind, i in enumerate(mx5): if i[2] != 0: genList[i[1]] = ind mx6 = myutils.readfile('LF.L6') for ind, i in enumerate(mx6): loadList[i[1]] = ind genDis = myutils.readfile('genDis.txt') f = myutils.readflag() markList = f['markList'] lastLoad_list = f['lastLoad_list'] # if busn in genList: # 发电机 linen = genList[busn] ttt = setG(linen) if ttt == "fail": return ttt else: return 'success' if busn in loadList: # 负荷 linen = loadList[busn] if linen == lastLoad_list[0]: lastLoad_list[1] = lastLoad_list[1] + 1 else: lastLoad_list[0] = linen lastLoad_list[1] = 0 f['lastLoad_list'] = lastLoad_list if lastLoad_list[1] > 3: # 已调整负荷附近的发电机多次 ttt = setbyhand(busn) if ttt == 1: markList.append(lastLoad_list[0]) print('append', lastLoad_list[0]) f['markList'] = markList f['goone'] = 1 myutils.writeflag(f) return 'pause' return 1 # continue, try again genid = genDis[lastLoad_list[0] - 1][lastLoad_list[1]] for ind, i in enumerate(mx5): if i[1] == genid: ttt = setG(ind) if ttt == "fail": f['goone'] = ttt myutils.writeflag(f) return ttt break return 'success'
def makeFlowHigher(): with open('ops.txt', 'a', encoding='utf-8') as fi: fi.write('知识:低潮流已收敛无异常母线->调高潮流\n') f = myutils.readflag() cur = f['cur'] step = f['step'] cur += step if cur > 1: cur = 1.0 f['cur'] = cur f['goone'] = 1 myutils.writeflag(f) return 'pause'
def findLP1(): # 查找异常母线 with open('ops.txt', 'a', encoding='utf-8') as fi: fi.write('检查异常母线\n') genList = dict() loadList = dict() mx5 = myutils.readfile('LF.L5') for ind, i in enumerate(mx5): if i[2] != 0: genList[i[1]] = ind mx6 = myutils.readfile('LF.L6') for ind, i in enumerate(mx6): loadList[i[1]] = ind genDis = myutils.readfile('genDis.txt') # init end f = myutils.readflag() markList = f['markList'] ### lp1 = myutils.readfile('LF.LP1', coding='gb2312') n = 0 loadsdown = [] loadsup = [] loadssum = 0 abss = [] for i in lp1: if len(i) == 4: loadssum += i[1] n += 1 # gen = None val = 1 mx5 = myutils.readfile('LF.L5') if n * 0.85 > loadssum: for i in lp1: if len(i) == 4: if i[1] < val and (i[0] in genList): gen = genList[i[0]] val = i[1] P = mx5[gen][3] r = (P + 0.5) / P if P < 0: r = -1 mx5[gen][3] = mx5[gen][3] * r mx5[gen][4] = mx5[gen][4] * r writefile('LF.L5', mx5) print('0.85', gen) f['findLP1'] = [-2, 1] myutils.writeflag(f) with open('ops.txt', 'a', encoding='utf-8') as fi: fi.write('分区母线电压较低,提高发电机电压0.5个标幺值\n') return 'pause' # gen = None val = 0 if n * 1.15 < loadssum: for i in lp1: if len(i) == 4: if i[1] > val and (i[0] in genList) and mx5[genList[i[0]]][3] > 0.1: gen = genList[i[0]] val = i[1] if gen == None: pass ########## gao !!!!!!!!!!!!!! else: P = mx5[gen][3] r = (P - 0.5) / P if r < 0: r = 0.5 mx5[gen][3] = mx5[gen][3] * r mx5[gen][4] = mx5[gen][4] * r myutils.writefile('LF.L5', mx5) print('1.15', gen) f['findLP1'] = [-2, 1] myutils.writeflag(f) with open('ops.txt', 'a', encoding='utf-8') as fi: fi.write('分区母线电压较高,降低发电机电压0.5个标幺值\n') return 'pause' # fixtype = -1 fixline = 0 fixnum = 1.0 for i in lp1: if len(i) == 4: if abs(i[1] - 1) > 0.1: curtype = -2 if i[0] in genList: curtype = 1 if i[0] in loadList: curtype = 0 if i[0] in markList: continue if curtype >= fixtype: if abs(i[1] - 1) > abs(fixnum - 1): fixline = i[0] fixtype = curtype fixnum = i[1] # if fixtype == -1: f['findLP1'] = [-1, 1] myutils.writeflag(f) return 'pause' print('ssss%s-%s' % (fixnum, fixline)) with open('ops.txt', 'a', encoding='utf-8') as fi: fi.write('发现电压异常母线:%s行,电压%s\n' % (fixline, fixnum)) f['findLP1'] = [0, fixline] myutils.writeflag(f) return 'pause'
def go2(): genList = dict() loadList = dict() mx5 = myutils.readfile('LF.L5') for ind, i in enumerate(mx5): if i[2] != 0: genList[i[1]] = ind mx6 = myutils.readfile('LF.L6') for ind, i in enumerate(mx6): loadList[i[1]] = ind genDis = myutils.readfile('genDis.txt') # init end f = myutils.readflag() markList = f['markList'] lastLoad_list = f['lastLoad_list'] x = tuple(f['findLP1']) f['findLP1'] = 'None' if x[0] == -2: print('x[0] == -2, goonestep return 1') f['goone'] = 1 myutils.writeflag(f) return 'continue' return 1 #continue, try once again if x[0] == -1: if myutils.getflag(): f['goone'] = 0 myutils.writeflag(f) return 0 # break, fixed, cur++ else: f['goone'] = -1 myutils.writeflag(f) return -1 # fail if x[0] == 0: if x[1] in genList: # 发电机 linen = genList[x[1]] ttt = setG(linen) if ttt == "fail": f['goone'] = ttt myutils.writeflag(f) return ttt else: f['goone'] = 1 myutils.writeflag(f) return 'pause' if x[1] in loadList: # 负荷 linen = loadList[x[1]] if linen == lastLoad_list[0]: lastLoad_list[1] = lastLoad_list[1] + 1 else: lastLoad_list[0] = linen lastLoad_list[1] = 0 f['lastLoad_list'] = lastLoad_list if lastLoad_list[1] > 3: # 已调整负荷附近的发电机多次 ttt = setbyhand(x[1]) if ttt == 1: markList.append(x[1]) print('append', x[1]) f['markList'] = markList f['goone'] = 1 myutils.writeflag(f) return 'pause' return 1 # continue, try again genid = genDis[lastLoad_list[0] - 1][lastLoad_list[1]] for ind, i in enumerate(mx5): if i[1] == genid: ttt = setG(ind) if ttt == "fail": f['goone'] = ttt myutils.writeflag(f) return ttt break if myutils.getflag(): f['goone'] = 0 myutils.writeflag(f) return 'pause' return 0 # break, fixed, cur++ else: f['goone'] = -1 myutils.writeflag(f) return -1 # fail print('error', x)