2025-01-07 16:26:54 +08:00
|
|
|
from calculators import RoundMethod
|
2025-02-21 14:47:15 +08:00
|
|
|
from commons.models.material import Material
|
2025-03-19 14:37:48 +08:00
|
|
|
from commons.models.price_result import PriceResult
|
2024-05-29 10:21:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
def calculate(year=2023, month=8):
|
2024-07-09 18:11:22 +08:00
|
|
|
"""
|
|
|
|
计算生成趋势表
|
|
|
|
"""
|
2024-12-09 17:26:32 +08:00
|
|
|
from calculators import Calculator
|
|
|
|
|
2025-03-19 14:37:48 +08:00
|
|
|
# 清空当月数据
|
|
|
|
PriceResult.clean(year, month)
|
2025-02-21 14:47:15 +08:00
|
|
|
# 从材料表获取趋势表所需的材料信息
|
2025-03-19 15:23:09 +08:00
|
|
|
for material in Material.list(type=1):
|
2024-05-29 10:21:31 +08:00
|
|
|
calculator = Calculator(year=year, month=month)
|
2025-02-21 14:47:15 +08:00
|
|
|
calculator.name = material.name
|
|
|
|
calculator.material_id = material.id
|
|
|
|
calculator.unit = material.unit
|
|
|
|
calculator.spec = material.spec
|
2025-05-07 08:35:52 +08:00
|
|
|
|
2025-02-21 14:47:15 +08:00
|
|
|
# 设置小数位数,如果数据库中未设置则使用默认值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
|
|
|
|
|
2024-05-29 10:21:31 +08:00
|
|
|
_result = calculator.run()
|
|
|
|
calculator.save()
|
|
|
|
print(_result)
|
|
|
|
|
2024-12-09 17:26:32 +08:00
|
|
|
|
2024-05-29 10:21:31 +08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
from core.factory import ClientApp
|
|
|
|
|
2024-06-05 09:21:00 +08:00
|
|
|
with ClientApp().app_context():
|
2025-06-05 18:57:35 +08:00
|
|
|
calculate(2025, 5)
|
2025-02-21 14:47:15 +08:00
|
|
|
|
2024-12-09 17:26:32 +08:00
|
|
|
# for i in range(2, 12):
|
|
|
|
# calculate(2022, i+1)
|
2025-05-07 08:35:52 +08:00
|
|
|
# for i in range(1, 5+1):
|
|
|
|
# calculate(2025, i)
|
2025-02-21 14:47:15 +08:00
|
|
|
# for i in range(6-1, 10):
|
|
|
|
# calculate(2024, i+1)
|