This commit is contained in:
han0
2024-12-25 11:31:31 +08:00
parent 370a4861dd
commit 0e528d81e0
7 changed files with 161 additions and 31 deletions

View File

@@ -36,14 +36,21 @@ def refresh_task(task_id):
class CalculateQuery(BaseModel):
year: str = Field(title='年份')
month: str = Field(title='月份')
year: int = Field(title='年份')
month: int = Field(title='月份')
@data.route('/calculate', methods=['GET'])
@siwa.doc(tags=[""], summary='触发计算任务', query=CalculateQuery)
def start_calculate(query: CalculateQuery):
calculate(year=query.year, month=query.month)
return Response()
@data.route('/collect', methods=['GET'])
@siwa.doc(tags=[""], summary='触发计算任务', query=CalculateQuery)
def start_collect(query: CalculateQuery):
collect(year=query.year, month=query.month)
return Response()

View File

@@ -73,7 +73,7 @@ class Calculator:
@property
def previous_prices(self):
if not self._previous_prices:
previous_price = PriceResult.get_by_key(self.name, *Helper.get_last_month(self.year, self.month))
previous_price = PriceResult.get_by_key(self.material_id, *Helper.get_last_month(self.year, self.month))
self._previous_prices = previous_price
return self._previous_prices
@@ -120,10 +120,6 @@ class Calculator:
self.price_fujian, self.fluctuating_fujian = self._get_fujian_price()
return self
# todo 缺少三明钢铁导入数据
# todo-0 价格计算改为直接从表读取 不再进行多余计算
# todo 计算验证
def _get_ftb_price(self):
query = FuzhouTransportationBureau.get_query(self.year, self.month, material_id=self.material_id)
data = query.first()

View File

@@ -7,6 +7,10 @@ from commons.models.price_publish import PricePublish
from commons.models.price_result import PriceResult
MATERIAL_ID_TYPE_1 = []
MATERIAL_ID_TYPE_2 = []
class Collector:
def __init__(self, year, month, force=True):
@@ -14,8 +18,6 @@ class Collector:
self.month = month
self.force = True # todo-2 已发布的价格不在覆盖计算
# todo-2 材料id映射
def get_avg(self):
query = PricePublish.get_query(name_in=(
'杉原木',
@@ -229,20 +231,81 @@ class Collector:
).upsert()
def get_from_result(self):
query = PriceResult.get_query(self.year, self.month, name_in=(
'光圆钢筋',
'带肋钢筋',
'型钢',
'钢绞线',
'32.5级水泥',
'42.5级水泥',
'进口沥青',
'国产沥青',
'进口改性沥青',
'国产改性沥青',
'汽油89',
'汽油92',
'柴油0',
query = PriceResult.get_query(self.year, self.month, material_id_in=(
'2001001',
'2001002',
'2001008',
'2003004',
'2003005',
'2003005001',
'5509001',
'5509002',
'5509003',
'3001001002',
'3001001001',
'3001002002',
'3001002001',
'3003002001',
'3003002002',
'3003003',
'4003001001',
'4003001002',
'4003002002',
'4003002001',
'4005001',
'2001003',
'2001006',
'2001013',
'2003006',
'2003007',
'2003008',
'2003009',
'2004004',
'2003012',
'2001019',
'2003015',
'2003016',
'2003017001',
'2003017002',
'2003021',
'2003022',
'6001002',
'6001003',
'6001059',
'6001071',
'6001080',
'6001086',
'6001089',
'6001092',
'6003001',
'6003003',
'6005005',
'6005009',
'6005015',
'2005002',
'2009028',
'6007002',
'2009033',
'2001025',
'2001026',
'6002001',
'6002002',
'6002003',
'6002004',
'6002005',
'6002006',
'5009002',
'5506001',
'5005001',
'5005002',
'5005003',
'5005006',
'5005007',
'5006001',
'5005009',
'5006002',
'5007003001',
'3003001',
))
data = query.all()
for item in data:
@@ -272,7 +335,7 @@ class Collector:
def run(self):
# 当月价
self.get_from_survey()
# self.get_from_survey()
self.get_from_result()
# 近半年平均价
self.get_avg()

View File

@@ -36,7 +36,7 @@ class FujianSurvey(db.Model, Model, BaseModelMixin):
return result
@classmethod
def get_query(cls, year=None, month=None, name=None, spec=None, name_in=None, region='福州', material_id=None):
def get_query(cls, year=None, month=None, name=None, spec=None, name_in=None, region='福州', material_id=None, material_id_in=None):
query = cls.query
if year and month:
start_date = datetime.date(year, month, 1)
@@ -49,6 +49,8 @@ class FujianSurvey(db.Model, Model, BaseModelMixin):
query = query.filter(cls.material_id == material_id)
if name_in:
query = query.filter(cls.name.in_(name_in))
if material_id_in:
query = query.filter(cls.material_id.in_(material_id_in))
if spec:
query = query.filter(cls.spec.like(f'%{spec}%'))
if region:

View File

@@ -43,9 +43,9 @@ class PriceResult(db.Model, Model, OperationTrackMixin, BaseModelMixin):
)
@classmethod
def get_by_key(cls, name, year, month):
def get_by_key(cls, material_id, year, month):
query = cls.query
query = query.filter(cls.name == name).filter(cls.year == year).filter(cls.month == month)
query = query.filter(cls.material_id == material_id).filter(cls.year == year).filter(cls.month == month)
return query.one_or_none()
def find_by_key(self):
@@ -53,15 +53,17 @@ class PriceResult(db.Model, Model, OperationTrackMixin, BaseModelMixin):
query = cls.query
query = query.filter(cls.year == self.year)
query = query.filter(cls.month == self.month)
query = query.filter(cls.name == self.name)
query = query.filter(cls.material_id == self.material_id)
result = query.one_or_none()
return result
@classmethod
def get_query(cls, year, month, name_in=None, name=None):
def get_query(cls, year, month, name_in=None, name=None, material_id_in=None):
query = cls.query
query = query.filter(cls.year == year)
query = query.filter(cls.month == month)
if material_id_in:
query = query.filter(cls.material_id.in_(material_id_in))
if name_in:
query = query.filter(cls.name.in_(name_in))
if name:

View File

@@ -22,6 +22,7 @@ def calculate(year=2023, month=8):
from calculators import Calculator
for material_id, name, spec, unit in [
# 趋势表
['2001001', 'HPB300钢筋', '', 't'],
['2001002', 'HRB400钢筋', '', 't'],
['2001008', '钢绞线', '普通无松弛Φ15.24', 't'],
@@ -38,6 +39,65 @@ def calculate(year=2023, month=8):
['3003002001', '汽油', '89#', 'kg'],
['3003002002', '汽油', '92#', 'kg'],
['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'],
]:
calculator = Calculator(year=year, month=month)
calculator.name = name
@@ -81,5 +141,5 @@ if __name__ == '__main__':
# calculate(2022, i+1)
# for i in range(0, 12):
# calculate(2023, i+1)
for i in range(6, 9):
for i in range(7-1, 10):
calculate(2024, i+1)

View File

@@ -17,5 +17,5 @@ if __name__ == '__main__':
# collect(2022, i + 1)
# for i in range(0, 12):
# collect(2023, i + 1)
for i in range(10, 12):
for i in range(5, 10):
collect(2024, i + 1)