from utils.DBModels.DeviceParModels import *
import pandas as pd

class InitParameterDB():
    def __init__(self) -> None:
        self.writeParameter()
        self.writeUnitParameter()

    def writeParameter(self) -> None:
        blockNames = pd.ExcelFile('static/PA块信息表.xlsx').sheet_names
        for blockName in blockNames:
            parameters = pd.read_excel('static/PA块信息表.xlsx', sheet_name = str(blockName))
      
            for  index, row in parameters.iterrows():
                parameter = row.values
                clsblockName = globals()[blockName]() #通过excel的sheet名字获取对应的数据库函数
                if not clsblockName.getByName(parameter[1]):
                    clsblockName.addParame(index = parameter[0], paramName = parameter[1], objectType = parameter[2], dataType = parameter[3],
                                            saveType = parameter[4], dataSize = parameter[5], accessType = parameter[6], transferType = parameter[7], description = parameter[8])
    
    def writeUnitParameter(self):
        parameters = pd.read_excel('static/UnitTable.xlsx', sheet_name = 'UnitTable')
        for  index, row in parameters.iterrows():
                parameter = row.values
                clsblockName = UnitTable() 
                if not clsblockName.getByValue(parameter[0]):
                    clsblockName.addParame(unitValue = parameter[0], unitSymbol = parameter[1], description = parameter[2])