59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
import datetime
|
||
|
||
from calculators import Calculator, Helper
|
||
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 Oil0Calculator(Calculator):
|
||
name = "柴油(0)"
|
||
material_id = "3003003"
|
||
unit = "kg"
|
||
spec = "0#"
|
||
|
||
def _get_survey_price(self):
|
||
query = FujianSurvey.get_query(self.year, self.month, name='柴油', spec='0#')
|
||
data = query.first()
|
||
price = data.price if data else 0
|
||
fluctuating = self._get_fluctuating('price_survey', price)
|
||
return round(price, 2), round(fluctuating, 2)
|
||
|
||
def _get_network_price(self):
|
||
query = DataNetwork.get_query(self.year, self.month, spec='0号')
|
||
data = query.first()
|
||
price = data.price if data else 0
|
||
fluctuating = self._get_fluctuating('price_network', price)
|
||
return round(price, 2), round(fluctuating, 2)
|
||
|
||
def _get_calculate_price(self, round_dit=2):
|
||
return super()._get_calculate_price(round_dit)
|
||
|
||
def _get_fujian_price(self):
|
||
query = DataFujian.get_query(self.year, self.month, name='柴油', spec='0#')
|
||
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):
|
||
return self.price_network, self.fluctuating_network
|
||
|
||
def save(self):
|
||
result = self.result()
|
||
PriceResult(**result).upsert()
|
||
|
||
|
||
if __name__ == '__main__':
|
||
from core.factory import ClientApp
|
||
|
||
with ClientApp().app_context():
|
||
calculator = Oil0Calculator(year=2024, month=5)
|
||
result = calculator.run()
|
||
calculator.save()
|
||
print(result)
|