from calculators import RoundMethod from commons.models.material import Material from commons.models.price_result import PriceResult def calculate(year=2023, month=8): """ 计算生成趋势表 """ from calculators import Calculator # 清空当月数据 PriceResult.clean(year, month) # 从材料表获取趋势表所需的材料信息 for material in Material.list(type=1): calculator = Calculator(year=year, month=month) calculator.name = material.name calculator.material_id = material.id calculator.unit = material.unit calculator.spec = material.spec # 设置小数位数,如果数据库中未设置则使用默认值0 calculator.round_bit = material.round_bit if material.round_bit is not None else 0 # 设置舍入方法,如果数据库中未设置则使用normal if material.round_method == 'none': calculator.round_method = RoundMethod.none elif material.round_method == 'five': calculator.round_method = RoundMethod.five else: calculator.round_method = RoundMethod.normal _result = calculator.run() calculator.save() print(_result) if __name__ == '__main__': from core.factory import ClientApp with ClientApp().app_context(): calculate(2025, 5) # for i in range(2, 12): # calculate(2022, i+1) # for i in range(1, 5+1): # calculate(2025, i) # for i in range(6-1, 10): # calculate(2024, i+1)