2024-05-29 10:21:31 +08:00
|
|
|
from sqlalchemy import func
|
|
|
|
|
|
|
|
from calculators import Calculator
|
2024-07-10 16:08:47 +08:00
|
|
|
from commons.models.data_network import DataNetwork
|
2024-05-29 10:21:31 +08:00
|
|
|
from commons.models.fujian_survey import FujianSurvey
|
|
|
|
from commons.models.fuzhou_highway_bureau import FuzhouHighwayBureau
|
|
|
|
from commons.models.fuzhou_transportation_bureau import FuzhouTransportationBureau
|
|
|
|
from commons.models.price_result import PriceResult
|
|
|
|
from commons.models.sanming_steel import SanmingSteel
|
|
|
|
from commons.models.steel_rebar import SteelRebar
|
|
|
|
|
|
|
|
|
|
|
|
class Reber300Calculator(Calculator):
|
|
|
|
name = "光圆钢筋"
|
|
|
|
material_id = "15.05.60.00"
|
|
|
|
unit = "t"
|
|
|
|
spec = ""
|
|
|
|
|
|
|
|
def __init__(self, year, month):
|
|
|
|
self.year = year
|
|
|
|
self.month = month
|
|
|
|
|
|
|
|
def _get_ftb_price(self):
|
|
|
|
query = FuzhouTransportationBureau.get_query(self.year, self.month, name='光圆钢筋')
|
2024-07-11 16:01:15 +08:00
|
|
|
data = query.first()
|
|
|
|
price = int(data.price) if data else 0
|
|
|
|
fluctuating = int(self._get_fluctuating('price_ftb', price))
|
2024-05-29 10:21:31 +08:00
|
|
|
return price, fluctuating
|
|
|
|
|
|
|
|
def _get_ss_price(self):
|
|
|
|
query = SanmingSteel.get_query(self.year, self.month, name='高线', spec='φ10mm')
|
2024-07-11 16:01:15 +08:00
|
|
|
data = query.first()
|
|
|
|
price = int(data.price) if data else 0
|
|
|
|
fluctuating = int(self._get_fluctuating('price_ss', price))
|
2024-05-29 10:21:31 +08:00
|
|
|
return price, fluctuating
|
|
|
|
|
|
|
|
def _get_fhb_price(self):
|
|
|
|
query = FuzhouHighwayBureau.get_query(self.year, self.month, name='光圆钢筋')
|
2024-07-11 16:01:15 +08:00
|
|
|
data = query.first()
|
|
|
|
price = int(data.price) if data else 0
|
|
|
|
fluctuating = int(self._get_fluctuating('price_ftb', price))
|
2024-05-29 10:21:31 +08:00
|
|
|
return price, fluctuating
|
|
|
|
|
|
|
|
def _get_network_price(self):
|
2024-07-10 16:08:47 +08:00
|
|
|
query = DataNetwork.get_query(self.year, self.month, name='光圆钢筋', spec='综合')
|
|
|
|
data = query.first()
|
2024-07-11 16:01:15 +08:00
|
|
|
price = int(data.price) if data else 0
|
|
|
|
fluctuating = int(self._get_fluctuating('price_network', price))
|
2024-05-29 10:21:31 +08:00
|
|
|
return price, fluctuating
|
|
|
|
|
|
|
|
def _get_survey_price(self):
|
|
|
|
query = FujianSurvey.get_query(self.year, self.month, name='光圆钢筋')
|
2024-07-11 16:01:15 +08:00
|
|
|
data = query.first()
|
|
|
|
price = int(data.price) if data else 0
|
|
|
|
fluctuating = int(self._get_fluctuating('price_survey', price))
|
2024-05-29 10:21:31 +08:00
|
|
|
return price, fluctuating
|
|
|
|
|
|
|
|
def _get_recommend_price(self):
|
|
|
|
self._fluctuatings = [self.fluctuating_network, self.fluctuating_survey, self.fluctuating_fhb, self.fluctuating_ftb, self.fluctuating_ss]
|
|
|
|
return super()._get_recommend_price()
|
|
|
|
|
|
|
|
def save(self):
|
|
|
|
result = self.result()
|
|
|
|
PriceResult(**result).upsert()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from core.factory import ClientApp
|
|
|
|
|
|
|
|
with ClientApp().app_context():
|
2024-07-10 16:08:47 +08:00
|
|
|
calculator = Reber300Calculator(year=2024, month=5)
|
2024-05-29 10:21:31 +08:00
|
|
|
result = calculator.run()
|
|
|
|
calculator.save()
|
|
|
|
print(result)
|
|
|
|
|