75 lines
2.7 KiB
Python
75 lines
2.7 KiB
Python
from calculators import Calculator
|
|
from commons.models.data_fujian import DataFujian
|
|
from commons.models.data_network import DataNetwork
|
|
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
|
|
|
|
|
|
class SteelPlateCalculator(Calculator):
|
|
name = "中厚板"
|
|
material_id = "2003005"
|
|
unit = "t"
|
|
spec = ""
|
|
|
|
def _get_ftb_price(self):
|
|
query = FuzhouTransportationBureau.get_query(self.year, self.month, name='钢板')
|
|
data = query.first()
|
|
price = int(data.price) if data else 0
|
|
fluctuating = int(self._get_fluctuating('price_ftb', price))
|
|
return price, fluctuating
|
|
|
|
# def _get_ss_price(self):
|
|
# return 4000, -10
|
|
|
|
def _get_fhb_price(self):
|
|
query = FuzhouHighwayBureau.get_query(self.year, self.month, name='钢板')
|
|
data = query.first()
|
|
price = int(data.price) if data else 0
|
|
fluctuating = int(self._get_fluctuating('price_fhb', price))
|
|
return price, fluctuating
|
|
|
|
def _get_network_price(self):
|
|
query = DataNetwork.get_query(self.year, self.month, name='钢板')
|
|
data = query.all()
|
|
prices = {item.spec.strip(): float(item.price) for item in data}
|
|
|
|
price = 0.2 * prices.get('12mm', 0) + 0.6 * prices.get('16-20mm', 0) + 0.2 * prices.get('22-28mm', 0)
|
|
price = round(price)
|
|
|
|
fluctuating = int(self._get_fluctuating('price_network', price))
|
|
return price, fluctuating
|
|
|
|
def _get_survey_price(self):
|
|
query = FujianSurvey.get_query(self.year, self.month, name='钢板')
|
|
data = query.first()
|
|
price = int(data.price) if data else 0
|
|
fluctuating = int(self._get_fluctuating('price_survey', price))
|
|
return price, fluctuating
|
|
|
|
def _get_fujian_price(self):
|
|
query = DataFujian.get_query(self.year, self.month, name='钢板', spec='δ14-20')
|
|
data = query.first()
|
|
price = data.price if data else 0
|
|
fluctuating = self._get_fluctuating('price_fujian', price)
|
|
return price, fluctuating
|
|
|
|
def _get_recommend_price(self):
|
|
self._fluctuatings = [self.fluctuating_network, self.fluctuating_survey, self.fluctuating_fhb, self.fluctuating_ftb]
|
|
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():
|
|
calculator = SteelPlateCalculator(year=2024, month=5)
|
|
result = calculator.run()
|
|
calculator.save()
|
|
print(result)
|