from unitls.LogerinTxt import app_logger
from unitls.StaticDataclass import get_dic
from .flightDB import flightDB


def createWorkloadtablesFromPg(fdb: flightDB, workLoad: flightDB,selectedtime):
    try:
        workloadDic = {}
        primaryKey2 = 'text UNIQUE NOT NULL'
        pglist=fdb.getAlldata("pglist{}".format(selectedtime))
        if len(pglist) != 0:
            for workloadkey in list(get_dic('workloadLabel'))[1:]:
                workloadDic[workloadkey] = 'text not null'
            for row in pglist:
                workLoad.initTable('workload%s'%str(row[1]),"编号", primaryKey2, workloadDic)
    except Exception as e:
        app_logger.log_error(e)