feat: 更新国产沥青计算

This commit is contained in:
han0
2024-07-09 20:16:29 +08:00
parent d2eca25632
commit 5afcfc4846
3 changed files with 63 additions and 32 deletions

View File

@@ -1,12 +1,9 @@
import datetime
from sqlalchemy import func
from calculators import Calculator, Helper
from calculators import Calculator
from commons.models.data_network import DataNetwork
from commons.models.fujian_survey import FujianSurvey
from commons.models.asphalt_domestic import AsphaltDomestic
class AsphaltDomesticCalculator(Calculator):
name = "国产沥青"
@@ -19,33 +16,11 @@ class AsphaltDomesticCalculator(Calculator):
self.month = month
def _get_network_price(self):
name_in = (
'浙江省—镇海炼化(70#,90#,A级)',
'福建省—联合石化(70#,A级)',
'广东省—茂名石化(70#,90#,A级)',
'广东省—中油高富(70#,90#,A级)华南公司',
)
last_month_year, last_month = Helper.get_last_month(self.year, self.month)
end_date = AsphaltDomestic.get_last_date_from(date=datetime.date(last_month_year, last_month, 26))
start_date = AsphaltDomestic.get_last_date_from(date=datetime.date(self.year, self.month, 25))
previous_items = AsphaltDomestic.get_items(date=end_date, name_in=name_in)
previous_prices = {material: float(price or 0) for material, price in previous_items}
current_items = AsphaltDomestic.get_items(date=start_date, name_in=name_in)
current_prices = {material: float(price or 0) for material, price in current_items}
fluctuating_a = current_prices.get(name_in[0], 0) - previous_prices.get(name_in[0], 0)
fluctuating_b = current_prices.get(name_in[1], 0) - previous_prices.get(name_in[1], 0)
fluctuating_c = current_prices.get(name_in[2], 0) - previous_prices.get(name_in[2], 0)
fluctuating_d = current_prices.get(name_in[3], 0) - previous_prices.get(name_in[3], 0)
previous_price = int(getattr(self.previous_prices, 'price_network', 0))
price = previous_price + 0.4 * fluctuating_a + 0.2 * (fluctuating_b + fluctuating_c + fluctuating_d)
query = DataNetwork.get_query(self.year, self.month, name='石油沥青', spec='国产')
data = query.first()
price = data.price if data else 0
previous_price = int(getattr(self.previous_prices, 'price_network', price))
fluctuating = price - previous_price
return price, fluctuating
def _get_survey_price(self):