import readdata_amro
from openpyxl import load_workbook


def analyze():
    flightdata = readdata_amro.loadData('20230303')

    allmember = getExcelData()

    # ----------------------------------------

    member1 = allmember['第一组']
    #print(list(member1.keys()))
    dic1 = {}
    for name in list(member1.keys()):

        count = 0
        for i in flightdata:
            temp = i['放行人员']+i['维修人员']
            if temp.find(name) != -1:
                count +=1
        dic1[name] = count
    #print(dic1)

    # ----------------------------------------

    member2 = allmember['第二组']
    #print(list(member2.keys()))
    dic2 = {}
    for name in list(member2.keys()):

        count = 0
        for i in flightdata:
            temp = i['放行人员'] + i['维修人员']
            if temp.find(name) != -1:
                count += 1
        dic2[name] = count
    #print(dic2)

    #----------------------------------------

    member3 = allmember['第三组']
    #print(list(member3.keys()))
    dic3 = {}
    for name in list(member3.keys()):

        count = 0
        for i in flightdata:
            temp = i['放行人员'] + i['维修人员']
            if temp.find(name) != -1:
                count += 1
        dic3[name] = count
    #print(dic3)
    return [dic1, dic2, dic3]

def getExcelData():
    wb = load_workbook('./static/resource/四分队人力资源分布与资质.xlsx')
    ws = wb.active
    alldic = {}
    # ----------------------------------------
    num1name = ws['B']
    num1sg = ws['C']
    num1fx = ws['D']
    num1jn = ws['E']
    num1dg = ws['F']
    dic1 = {}
    for i in range(len(num1name)):

        if i >2:
            if num1name[i].value != None:
                dic1[num1name[i].value.replace(' ','')] = {'上岗':num1sg[i].value,
                                                          '放行':num1fx[i].value,
                                                          '技能':num1jn[i].value,
                                                          '到岗':num1dg[i].value}
    alldic[num1name[2].value] = dic1
    # ----------------------------------------
    num2name = ws['G']
    num2sg = ws['H']
    num2fx = ws['I']
    num2jn = ws['J']
    num2dg = ws['K']
    dic2 = {}
    for i in range(len(num2name)):

        if i > 2:
            if num2name[i].value != None:
                dic2[num2name[i].value.replace(' ', '')] = {'上岗': num2sg[i].value,
                                                            '放行': num2fx[i].value,
                                                            '技能': num2jn[i].value,
                                                            '到岗': num2dg[i].value}
    alldic[num2name[2].value] = dic2
    # ----------------------------------------
    num3name = ws['L']
    num3sg = ws['M']
    num3fx = ws['N']
    num3jn = ws['O']
    num3dg = ws['P']
    dic3 = {}
    for i in range(len(num3name)):

        if i > 2:
            if num3name[i].value != None:
                dic3[num3name[i].value.replace(' ', '')] = {'上岗': num3sg[i].value,
                                                            '放行': num3fx[i].value,
                                                            '技能': num3jn[i].value,
                                                            '到岗': num3dg[i].value}
    alldic[num3name[2].value] = dic3

    return alldic
if __name__ == '__main__':
    getExcelData()
    analyze()