Ejemplo n.º 1
0
Archivo: ops.py Proyecto: Hhkai/WMLFRTM
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'
Ejemplo n.º 2
0
def changemx(b):
    # 调整潮流
    mx = myutils.readfile('LF.L6')
    for i in range(len(mx)):
        print(mx[i][4], type(mx[i][4]))
        mx[i][4] = mx[i][4] * b
        mx[i][5] = mx[i][5] * b
    myutils.writefile("LF.L6", mx)
    mx2 = myutils.readfile('LF.L5')
    for i in range(len(mx2)):
        mx2[i][3] = mx2[i][3] * b
    myutils.writefile('LF.L5', mx2)
Ejemplo n.º 3
0
Archivo: ops.py Proyecto: Hhkai/WMLFRTM
def setG(linen):
    print('aaaaaaaaaaaaaaa')
    # 调整单个发电机
    mx = myutils.readfile("LF.L5")
    name = 0
    P = (0.1, 0.1)

    oldtype = mx[linen][2]
    oldValueP = mx[linen][3]
    oldValueQ = mx[linen][4]
    mx[linen][2] = 0
    name = mx[linen][-1]
    myutils.writefile("LF.L5", mx)
    os.system("WMLFRTMsg")
    if myutils.getflag():
        P = myutils.readslackval(myutils.readslack(), name)
    else:
        return "fail"
    mx[linen][2] = oldtype
    mx[linen][3] = float(P[0][:4])
    mx[linen][4] = float(P[1][:4])

    f = myutils.readflag()
    r = f['r']
    with open('ops.txt', 'a', encoding='utf-8') as fi:
        fi.write('所用知识: 调整母线附近发电机\n')
        fi.write('修改方案: 调整发电机(设置平衡机来寻求最优值)\n')
        fi.write('\t%s:%.2f+%.2fj->%.2f+%.2fj\n' %
                 (mx[linen][-1], oldValueP / r, oldValueQ / r,
                  mx[linen][3] / r, mx[linen][4] / r))

    myutils.writefile("LF.L5", mx)
    return 'pause'
Ejemplo n.º 4
0
Archivo: ops.py Proyecto: Hhkai/WMLFRTM
def checkP():
    # 全区平衡有功
    mx = myutils.readfile('LF.L6')
    load = 0
    for i in mx:
        load += i[4]
    mx2 = myutils.readfile('LF.L5')
    gen = 0
    for i in mx2:
        gen += i[3]
    stdgen = load * 1.011
    r = stdgen / gen
    for i in range(len(mx2)):
        if mx2[i][2] == 1:
            mx2[i][3] = mx2[i][3] * r
            mx2[i][4] = mx2[i][4] * r
        if mx2[i][2] == -1:
            mx2[i][3] = mx2[i][3] * r
    return 0
def transform_vrt(vrt_path, cols):
    """Transform VRT into a dataframe with gold tokens and all OCR comparisons."""
    vrt = util.readfile(vrt_path)
    # Remove last token in each text in order to avoid misleading very long 'words' consisting of
    # the final words on a full page not present in the gold standard, joined with '_'.
    vrt = re.sub(r'\n.+\n</sentence>\n</text>', r'\n</sentence>\n</text>', vrt)
    vrt_lines = vrt.splitlines()
    token_lines = [line.split('\t') for line in vrt_lines if not re.match(r'</?(corpus|text|sentence)', line)]
    df = pd.DataFrame(token_lines, columns=cols)

    print('VRT dataset so far:')
    print(list(df))
    return df
Ejemplo n.º 6
0
Archivo: ops.py Proyecto: Hhkai/WMLFRTM
def setbyhand(x):
    print('bbbbbbbbbbbbbb')
    # open a -5 will make it higher
    # 调电容电抗器
    toohigh = myutils.ishigh(x)
    mx = myutils.readfile('LF.L2')
    flag = False
    linen = 0
    r = 'ks'
    print(toohigh)
    for i in range(len(mx)):
        if mx[i][1] == x and mx[i][2] == x:
            if toohigh:
                if mx[i][0] == 0 and mx[i][5] > 0:
                    mx[i][0] = 1
                    myutils.writefile('LF.L2', mx)
                    flag = True
                    linen = i + 1
                    r = '无效 -> 有效'
                    break
                if mx[i][0] == 1 and mx[i][5] < 0:
                    mx[i][0] = 0
                    myutils.writefile('LF.L2', mx)
                    flag = True
                    linen = i + 1
                    r = '有效 -> 无效'
                    break
            else:
                if mx[i][0] == 0 and mx[i][5] < 0:
                    mx[i][0] = 1
                    myutils.writefile('LF.L2', mx)
                    flag = True
                    linen = i + 1
                    r = '无效 -> 有效'
                    break
                if mx[i][0] == 1 and mx[i][5] > 0:
                    mx[i][0] = 0
                    myutils.writefile('LF.L2', mx)
                    flag = True
                    linen = i + 1
                    r = '有效 -> 无效'
                    break
    if flag:
        with open('ops.txt', 'a', encoding='utf-8') as fi:
            fi.write('所用知识: 根据母线电压高低投切附近的电容电抗器\n')
            fi.write('修改方案: 调整电容电抗器\n')
            fi.write('\tLF.L2 %s行:%s\n' % (linen, r))
        return 'pause'
    return 1  # 调节失败
def add_corrected_ocr_tokens(novel_vrt: str, corr_dir: str, freqlist_forms):
    """Align and add tokens from one-novel corrected OCR string to one-novel VRT string.
    And some difference measures."""
    text_elem, vrt_tokentups = get_tokentuples(novel_vrt)
    ocr_pages = get_ocr_pages(corr_dir, text_elem)
    ocr_page_strings = [readfile(f) for f in ocr_pages]
    ocr_page_strings = fix_hyphens(ocr_page_strings)
    ocr_string = '\n'.join(ocr_page_strings)
    new_vrt_lines = [f'{text_elem}']  # Put original text element back.
    ocr_tokens = tuple(tokenize(ocr_string))
    vrt_tokens = tuple([tup[0] for tup in vrt_tokentups])
    aligned_ocr_toks = align_b_to_a(vrt_tokens, ocr_tokens)
    # Hack to deal with long sequences of tokens due to unequal page samples
    aligned_ocr_toks = [tok if len(tok) < 100 else tok[:30] + '...' for tok in aligned_ocr_toks]
    new_vrt_tups = add_annotation_layer(vrt_tokentups, aligned_ocr_toks)
    new_vrt_tups = add_diff_measures(new_vrt_tups, vrt_tokens, aligned_ocr_toks)
    new_vrt_tups = add_in_freqlist(new_vrt_tups, aligned_ocr_toks, freqlist_forms)
    new_vrt_lines.append('\n'.join(['\t'.join(x) for x in new_vrt_tups]))
    new_vrt_lines.append('</text>')
    return '\n'.join(new_vrt_lines)
def add_ocr_tokens(novel_vrt: str, ocr_dir: str, freqlist_forms):
    """Align and add tokens from OCR pages to one-novel VRT string (where each token is annotated with page numbers).
    And some difference measures."""
    text_elem, page_tokentuples = get_page_tokentuples(novel_vrt)
    ocr_pages = get_ocr_pages(ocr_dir, text_elem)
    ocr_page_strings = [readfile(f) for f in ocr_pages]
    ocr_page_strings = fix_hyphens(ocr_page_strings)
    if len(page_tokentuples) != len(ocr_pages):
        print('OCR dir:', ocr_dir, text_elem)
        raise Exception('Number of novel pages and number of VRT pages do not match.')
    new_vrt_lines = [f'{text_elem}']  # Put original text element back.
    for ocr_text, vrt_tokentups in zip(ocr_page_strings, page_tokentuples):
        ocr_tokens = tuple(tokenize(ocr_text))
        vrt_tokens = tuple([tup[0] for tup in vrt_tokentups])
        aligned_ocr_toks = align_b_to_a(vrt_tokens, ocr_tokens)
        # Hack to deal with long sequences of tokens due to unequal page samples
        aligned_ocr_toks = [tok if len(tok) < 100 else tok[:30] + '...' for tok in aligned_ocr_toks]
        new_vrt_tups = add_annotation_layer(vrt_tokentups, aligned_ocr_toks)
        new_vrt_tups = add_diff_measures(new_vrt_tups, vrt_tokens, aligned_ocr_toks)
        new_vrt_tups = add_in_freqlist(new_vrt_tups, aligned_ocr_toks, freqlist_forms)
        new_vrt_lines.append('\n'.join(['\t'.join(x) for x in new_vrt_tups]))
    new_vrt_lines.append('</text>')
    return '\n'.join(new_vrt_lines)
Ejemplo n.º 9
0
Archivo: ops.py Proyecto: Hhkai/WMLFRTM
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'
Ejemplo n.º 10
0
Archivo: ops.py Proyecto: Hhkai/WMLFRTM
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)