def make(self, data, fuel): from relator.constants.models import Tariff, PriceIndex row = self.data.row year = row.period state = row.group.location.state deflator = float(row.group.database.deflator) enduses = row.group.simulation.fuel_enduses rate = Tariff.objects.get(fuel=self.fuel, state=state).tariff upv = PriceIndex.upv(self.fuel, state.census_region, year, deflator) self.use = enduses.get(fuel=self.fuel).total.into('kWh') self.cost = rate * upv * self.use self.save()
def upv(self): return PriceIndex.upv(self.fuel, self.master.census_region, self.year, self.deflator)