feat: 更新计算位数

This commit is contained in:
han0
2025-01-07 16:26:54 +08:00
parent 0e528d81e0
commit d8a9d76257
2 changed files with 116 additions and 94 deletions

View File

@@ -32,6 +32,23 @@ class Helper:
return last_month_year, last_month
class RoundMethod:
@staticmethod
def normal(n, round_bit):
result = round(n, round_bit)
return result if round_bit != 0 else int(result)
@staticmethod
def none(n, round_bit):
result = round(int(n * 10 ** round_bit) / 10 ** round_bit, round_bit)
return result if round_bit != 0 else int(result)
@staticmethod
def five(n, round_bit):
result = round(int(n * 10 ** round_bit / 5) * 5 / 10**round_bit, round_bit)
return result if round_bit != 0 else int(result)
class Calculator:
material_id = ""
name = ""
@@ -53,17 +70,20 @@ class Calculator:
fluctuating_recommend = 0
price_fujian = 0
fluctuating_fujian = 0
weight_ftb = 0
weight_ss = 0
weight_fhb = 0
weight_network = 0
weight_survey = 0
weight_ftb = 1
weight_ss = 1
weight_fhb = 1
weight_network = 1
weight_survey = 1
unit = ""
spec = ''
unit = "" # 单位
spec = '' # 规格
_previous_prices = None
_fluctuatings = []
round_bit = 1 # 结果保留位数
round_method = RoundMethod.normal # 舍入方法
_previous_prices = None # 上期价格数据
_fluctuatings = [] # 浮动
def __init__(self, year, month, force=True):
self.year = year
@@ -191,13 +211,12 @@ class Calculator:
self.fluctuating_network * self.weight_network,
self.fluctuating_survey * self.weight_survey,
]
fluctuating = sum(self._fluctuatings) / len(self._fluctuatings)
fluctuating = round(fluctuating, 2)
# fluctuating = round(fluctuating / round_by) * round_by
fluctuating = self.round_method(fluctuating, self.round_bit)
price = fluctuating + previous_price
price = round(price, 2)
# price = round(price / round_by) * round_by
price = self.round_method(price, self.round_bit)
return price, fluctuating
@@ -210,11 +229,11 @@ class Calculator:
self.weight_network = self._previous_prices.weight_network
self.weight_survey = self._previous_prices.weight_survey
else:
self.weight_ftb = 1 if self.fluctuating_ftb else 0
self.weight_ss = 1 if self.fluctuating_ss else 0
self.weight_fhb = 1 if self.fluctuating_fhb else 0
self.weight_network = 1 if self.fluctuating_network else 0
self.weight_survey = 1 if self.fluctuating_survey else 0
self.weight_ftb = 1
self.weight_ss = 1
self.weight_fhb = 1
self.weight_network = 1
self.weight_survey = 1
def save(self):
result = self.result()

View File

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