fix: 更新计算生成趋势表逻辑

This commit is contained in:
han0
2025-02-21 14:47:15 +08:00
parent 95456e2076
commit d21bdc17cf
2 changed files with 25 additions and 124 deletions

View File

@@ -25,6 +25,8 @@ class Material(db.Model, Model, OperationTrackMixin):
is_tree = Column('IS_TREE', Integer, comment='是否树')
sort = Column('SORT', Integer, default=0, comment='排序')
code = Column('CODE', String(20), comment='材料编码')
round_bit = Column('ROUND_BIT', Integer, comment='保留小数位数')
round_method = Column('ROUND_METHOD', String(20), comment='保留小数具体方法')
__table_args__ = (
{'comment': '材料'},

View File

@@ -1,19 +1,5 @@
from calculators import RoundMethod
from calculators.asphalt_domestic import AsphaltDomesticCalculator
from calculators.asphalt_imported import AsphaltImportedCalculator
from calculators.cement_325 import Cement325Calculator
from calculators.cement_425 import Cement425Calculator
from calculators.modifier import ModifierCalculator
from calculators.oil_0 import Oil0Calculator
from calculators.oil_89 import Oil89Calculator
from calculators.oil_92 import Oil92Calculator
from calculators.steel_plate import SteelPlateCalculator
from calculators.steel_rebar_300 import Reber300Calculator
from calculators.steel_rebar_400 import Reber400Calculator
from calculators.steel_section import SteelSectionCalculator
from calculators.steel_strand import SteelStrandCalculator
from calculators.asphalt_domestic_modifier import AsphaltDomesticModifierCalculator
from calculators.asphalt_imported_modifier import AsphaltImportedModifierCalculator
from commons.models.material import Material
def calculate(year=2023, month=8):
@@ -22,126 +8,39 @@ def calculate(year=2023, month=8):
"""
from calculators import Calculator
for round_bit, round_method, material_id, name, spec, unit in [
# 趋势表
[0, RoundMethod.normal, '2001001', 'HPB300钢筋', '', 't'],
[0, RoundMethod.normal, '2001002', 'HRB400钢筋', '', 't'],
[0, RoundMethod.normal, '2001008', '钢绞线', '普通无松弛Φ15.24', 't'],
[0, RoundMethod.normal, '2003004', '型钢', '工字钢, 角钢 20', 't'],
[0, RoundMethod.normal, '2003005', '钢板', 'A3, δ=540mm', 't'],
[0, RoundMethod.normal, '2003005001', '钢板', 'Q355', 't'],
[0, RoundMethod.normal, '3001001002', '石油沥青', '国产', 't'],
[0, RoundMethod.normal, '3001001001', '石油沥青', '进口', 't'],
[0, RoundMethod.normal, '3001002002', '改性石油沥青', '进口', 't'],
[0, RoundMethod.normal, '3001002001', '改性石油沥青', '国产', 't'],
[2, RoundMethod.none, '3003002001', '汽油', '89#', 'kg'],
[2, RoundMethod.none, '3003002002', '汽油', '92#', 'kg'],
[2, RoundMethod.none, '3003003', '柴油', '0#', 'kg'],
[0, RoundMethod.normal, '5509001', '32.5级水泥', '32.5', 't'],
[0, RoundMethod.normal, '5509002', '42.5级水泥', '32.5', 't'],
[0, RoundMethod.normal, '5509003', '52.5级水泥', '52.5', 't'],
# 直接来自调查表 todo 可通过忽略调查表以外的查询 来加快计算进程
[0, RoundMethod.normal, '2001003', '冷轧带肋钢筋网', '', 't'],
[0, RoundMethod.normal, '2001006', '预应力粗钢筋', '', 't'],
[0, RoundMethod.normal, '2001013', '高强钢丝', 'Φ5mm预应力用碳素钢丝', 't'],
[0, RoundMethod.normal, '2001019', '钢丝绳', '股丝6-7×19mm(非镀锌)', 't'],
[0, RoundMethod.normal, '2001025', '钢板网', '网眼尺寸25 * 76mm', 'm2'],
[0, RoundMethod.normal, '2001026', '铁丝编织网', '镀锌铁丝(包括加强钢丝、花蓝螺丝)', 'm2'],
[0, RoundMethod.normal, '2003006', '圆钢', 'Φ40mm', 't'],
[0, RoundMethod.normal, '2003007', '钢轨', '43-50kg / m', 't'],
[0, RoundMethod.normal, '2003012', '镀锌钢板', '厚度1-3mm', 't'],
[0, RoundMethod.normal, '2003008', '钢管', '无缝钢管', 't'],
[0, RoundMethod.normal, '2003009', '镀锌钢管', '外径15-200mm, 壁厚2.75-4.5mm', 't'],
[0, RoundMethod.normal, '2003015', '钢管立柱', '', 't'],
[0, RoundMethod.normal, '2003016', '型钢立柱', '镀锌(包括斜撑)', 't'],
[0, RoundMethod.normal, '2003017001', '波形钢板(双波)', '双波 镀锌(包括端头板、撑架)', 't'],
[0, RoundMethod.normal, '2003017002', '波形钢板(三波)', '三波 镀锌(包括端头板、撑架)', 't'],
[0, RoundMethod.normal, '2003021', '钢管桩', '', 't'],
[0, RoundMethod.normal, '2003022', '钢护筒', '', 't'],
[0, RoundMethod.normal, '2004004', '镀锌无缝钢管', '热浸镀锌外径152以上', 't'],
[1, RoundMethod.none, '2005002', '不锈钢板', '厚度2-3mm', 'kg'],
[1, RoundMethod.none, '2009028', '铁件', '包括扒钉、螺栓、拉杆、夹板', 'kg'],
[1, RoundMethod.none, '2009033', '铸铁管', '', 'kg'],
[2, RoundMethod.none, '3003001', '重油', '', 'kg'],
[0, RoundMethod.normal, '4003001001', '杉原木', '二等材长4m, Φ14-18cm', 'm3'],
[0, RoundMethod.normal, '4003001002', '松原木', '二等材Φ22-28cm长4-5m', 'm3'],
[0, RoundMethod.normal, '4003002001', '锯材', '杉板料', 'm3'],
[0, RoundMethod.normal, '4003002002', '锯材', '松板料', 'm3'],
[0, RoundMethod.normal, '4005001', '毛竹', 'Φ=60mm, L≥6m;Φ=75~90mm, L≥6m', ''],
[1, RoundMethod.none, '5005001', '乳化炸药', '', 'kg'],
[1, RoundMethod.none, '5005002', '硝铵炸药', '1号、2号岩石硝铵炸药', 'kg'],
[1, RoundMethod.none, '5005003', '导火线', '120s/m', 'm'],
[1, RoundMethod.none, '5005006', '普通雷管', '8号钢管', ''],
[1, RoundMethod.none, '5005007', '电雷管', '6号瞬发电雷管, 带脚线1.5m', ''],
[1, RoundMethod.none, '5005009', '导爆索', '爆速60007000m/s', 'm'],
[1, RoundMethod.none, '5006001', '工业数码电子雷管', '带电子芯片带脚线7m', ''],
[1, RoundMethod.none, '5006002', '引爆母线', '铜线φ0.5mm', 'm'],
[2, RoundMethod.none, '5007003001', '土工格栅', '宽6m聚乙烯单向、双向拉伸、聚丙烯双向、玻璃纤维', 'm2'],
[1, RoundMethod.none, '5009002', '油漆', '普通调和漆', 'kg'],
[0, RoundMethod.none, '5506001', '路缘石', '花岗岩', 'm3'],
[1, RoundMethod.none, '6001002', '四氟板式橡胶组合支座', 'GJZF4系列、GYZF4系列', 'dm3'],
[1, RoundMethod.none, '6001003', '板式橡胶支座', 'GJZ系列、GYZ系列', 'dm3'],
[0, RoundMethod.normal, '6001059', '盆式橡胶支座', '2500KN(双向)', ''],
[0, RoundMethod.normal, '6001071', '盆式橡胶支座', '5000KN(双向)', ''],
[0, RoundMethod.normal, '6001080', '盆式橡胶支座', '8000KN(双向)', ''],
[0, RoundMethod.normal, '6001086', '盆式橡胶支座', '10000KN(双向)', ''],
[0, RoundMethod.normal, '6001089', '盆式橡胶支座', '双向12500KN', ''],
[0, RoundMethod.normal, '6001092', '盆式橡胶支座', '双向15000KN', ''],
[0, RoundMethod.normal, '6002001', '橡胶护舷', 'H300×L1000', ''],
[0, RoundMethod.normal, '6002002', '橡胶护舷', 'H300×L1500', ''],
[0, RoundMethod.normal, '6002003', '橡胶护舷', 'H300×L2000', ''],
[0, RoundMethod.normal, '6002004', '鼓型橡胶护舷', 'SC1000H', ''],
[0, RoundMethod.normal, '6002005', '鼓型橡胶护舷', 'SC1600H', ''],
[0, RoundMethod.normal, '6002006', '鼓型橡胶护舷', 'SC2000H', ''],
[0, RoundMethod.normal, '6003001', '模数式伸缩缝', '80型', ''],
[0, RoundMethod.normal, '6003003', '模数式伸缩缝', '160型', ''],
[0, RoundMethod.normal, '6005005', '钢绞线群锚(3孔)', '包括夹片、锚垫板和螺旋筋', ''],
[0, RoundMethod.normal, '6005009', '钢绞线群锚(7孔)', '包括夹片、锚垫板和螺旋筋', ''],
[0, RoundMethod.normal, '6005015', '钢绞线群锚(15孔)', '包括夹片、锚垫板和螺旋筋', ''],
[0, RoundMethod.normal, '6007002', '铝合金标志', '纯铝板1100', 't'],
]:
# 从材料表获取趋势表所需的材料信息
for material in Material.query.all():
calculator = Calculator(year=year, month=month)
calculator.name = name
calculator.material_id = material_id
calculator.unit = unit
calculator.spec = spec
calculator.round_bit = round_bit
calculator.round_method = round_method
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)
# # todo-1 价格计算触发器
# for Calculator in [
# AsphaltDomesticCalculator,
# AsphaltImportedCalculator,
# Cement325Calculator,
# Cement425Calculator,
# Oil0Calculator,
# Oil89Calculator,
# Oil92Calculator,
# SteelPlateCalculator,
# Reber300Calculator,
# Reber400Calculator,
# SteelSectionCalculator,
# SteelStrandCalculator,
# # ModifierCalculator,
# AsphaltDomesticModifierCalculator,
# AsphaltImportedModifierCalculator,
# ]:
# calculator = Calculator(year=year, month=month)
# _result = calculator.run()
# calculator.save()
# print(_result)
if __name__ == '__main__':
from core.factory import ClientApp
with ClientApp().app_context():
calculate(2024, 8)
# for i in range(2, 12):
# calculate(2022, i+1)
# for i in range(0, 12):
# calculate(2023, i+1)
for i in range(6-1, 10):
calculate(2024, i+1)
# for i in range(6-1, 10):
# calculate(2024, i+1)