How to use load_profile method in hypothesis

Best Python code snippet using hypothesis

Bill_Calc_old.py

Source:Bill_Calc_old.py Github

copy

Full Screen

1import numpy as np2import pandas as pd3import time4import sys5def bill_calculator(load_profile, tariff):6 def pre_processing_load(load_profile):7 # placeholder for a quick quality check function for load profile8 # make sure it is kwh9 # make sure it is one year10 # make sure it doesn't have missing value or changing the missing values to zero or to average11 # make sure the name is Load12 # time interval is half hour13 return load_profile14 def fr_calc(load_profile, tariff):15 f_load_profile = load_profile16 imports = [np.nansum(f_load_profile[col].values[f_load_profile[col].values > 0])17 for col in f_load_profile.columns if col != 'READING_DATETIME']18 Results = pd.DataFrame(index=[col for col in f_load_profile.columns if col != 'READING_DATETIME'],19 data=imports, columns=['Annual_kWh'])20 Results['Annual_kWh_exp'] = [-1 * np.nansum(f_load_profile[col].values[f_load_profile[col].values < 0])21 for col in f_load_profile.columns if col != 'READING_DATETIME']22 if tariff['ProviderType'] == 'Retailer':23 Results['DailyCharge'] = len(load_profile.index.normalize().unique()) * tariff['Parameters']['Daily']['Value']24 Results['EnergyCharge'] = Results['Annual_kWh'] * tariff['Parameters']['Energy']['Value']25 Results['EnergyCharge_Discounted'] = Results['EnergyCharge'] * (1 - tariff['Discount (%)'] / 100)26 Results['Fit_Rebate'] = Results['Annual_kWh_exp'] * tariff['Parameters']['FiT']['Value']27 Results['Bill'] = Results['DailyCharge'] + Results['EnergyCharge'] - Results['Fit_Rebate']28 else:29 for TarComp, TarCompVal in tariff['Parameters'].items():30 Results[TarComp, 'DailyCharge'] = len(load_profile.index.normalize().unique()) * TarCompVal['Daily']['Value']31 Results[TarComp, 'EnergyCharge'] = Results['Annual_kWh'] * TarCompVal['Energy']['Value']32 Results['Bill'] = Results['NUOS','DailyCharge'] + Results['NUOS','EnergyCharge']33 return Results34 def block_annual(load_profile, tariff):35 f_load_profile = load_profile36 imports = [np.nansum(f_load_profile[col].values[f_load_profile[col].values > 0])37 for col in f_load_profile.columns if col != 'READING_DATETIME']38 Results = pd.DataFrame(index=[col for col in f_load_profile.columns if col != 'READING_DATETIME'],39 data=imports, columns=['Annual_kWh'])40 Results['Annual_kWh_exp'] = [-1 * np.nansum(f_load_profile[col].values[f_load_profile[col].values < 0])41 for col in f_load_profile.columns if col != 'READING_DATETIME']42 if tariff['ProviderType'] == 'Retailer':43 tariff_temp = tariff.copy()44 del tariff_temp['Parameters']45 tariff_temp['Parameters'] = {'Retailer': tariff['Parameters']}46 tariff = tariff_temp.copy()47 for TarComp, TarCompVal in tariff['Parameters'].items():48 Results[TarComp, 'DailyCharge'] = len(load_profile.index.normalize().unique()) * TarCompVal['Daily'][49 'Value']50 BlockUse = Results[['Annual_kWh']].copy()51 BlockUseCharge = Results[['Annual_kWh']].copy()52 lim = 053 for k, v in TarCompVal['Energy'].items():54 BlockUse[k] = BlockUse['Annual_kWh']55 BlockUse[k][BlockUse[k] > v['HighBound']]= v['HighBound']56 BlockUse[k] = BlockUse[k]-lim57 BlockUse[k][BlockUse[k] < 0] = 058 lim = v['HighBound']59 BlockUseCharge[k] = BlockUse[k] * v['Value']60 del BlockUse['Annual_kWh']61 del BlockUseCharge['Annual_kWh']62 Results[TarComp, 'EnergyCharge'] = BlockUseCharge.sum(axis=1)63 if 'Discount (%)' in tariff:64 Results[TarComp, 'EnergyCharge_Discounted'] = Results[TarComp, 'EnergyCharge'] * (65 1 - tariff['Discount (%)'] / 100)66 else:67 Results[TarComp, 'EnergyCharge_Discounted'] = Results[TarComp, 'EnergyCharge']68 if 'FiT' in TarCompVal:69 Results[TarComp, 'Fit_Rebate'] = Results['Annual_kWh_exp'] * TarCompVal['FiT']['Value']70 else:71 Results[TarComp, 'Fit_Rebate'] = 072 if tariff['ProviderType'] == 'Retailer':73 Results['Bill'] = Results['Retailer', 'DailyCharge'] + Results['Retailer', 'EnergyCharge_Discounted'] - \74 Results['Retailer', 'Fit_Rebate']75 else:76 Results['Bill'] = Results['NUOS', 'DailyCharge'] + Results['NUOS', 'EnergyCharge_Discounted'] - Results[77 'NUOS', 'Fit_Rebate']78 return Results79 def block_quarterly(load_profile, tariff):80 load_profile_imp=load_profile.clip_lower(0)81 load_profile_Q1 = load_profile_imp.loc[load_profile_imp.index.month.isin([1, 2, 3]), :]82 load_profile_Q2 = load_profile_imp.loc[load_profile_imp.index.month.isin([4, 5, 6]), :]83 load_profile_Q3 = load_profile_imp.loc[load_profile_imp.index.month.isin([7, 8, 9]), :]84 load_profile_Q4 = load_profile_imp.loc[load_profile_imp.index.month.isin([10, 11, 12]), :]85 f_load_profile = load_profile86 imports = [np.nansum(f_load_profile[col].values[f_load_profile[col].values > 0])87 for col in f_load_profile.columns if col != 'READING_DATETIME']88 Results = pd.DataFrame(index=[col for col in f_load_profile.columns if col != 'READING_DATETIME'],89 data=imports, columns=['Annual_kWh'])90 Results['Q1_kWh'] = load_profile_Q1.sum()91 Results['Q2_kWh'] = load_profile_Q2.sum()92 Results['Q3_kWh'] = load_profile_Q3.sum()93 Results['Q4_kWh'] = load_profile_Q4.sum()94 Results['Annual_kWh_exp'] = [-1 * np.nansum(f_load_profile[col].values[f_load_profile[col].values < 0])95 for col in f_load_profile.columns if col != 'READING_DATETIME']96 if tariff['ProviderType'] == 'Retailer':97 tariff_temp = tariff.copy()98 del tariff_temp['Parameters']99 tariff_temp['Parameters'] = {'Retailer': tariff['Parameters']}100 tariff = tariff_temp.copy()101 for TarComp, TarCompVal in tariff['Parameters'].items():102 Results[TarComp, 'DailyCharge'] = len(load_profile.index.normalize().unique()) * TarCompVal['Daily'][103 'Value']104 for i in range(1,5):105 BlockUse = Results[['Q{}_kWh'.format(i)]].copy()106 BlockUseCharge = BlockUse.copy()107 lim = 0108 for k, v in TarCompVal['Energy'].items():109 BlockUse[k] = BlockUse['Q{}_kWh'.format(i)]110 BlockUse[k][BlockUse[k] > v['HighBound']] = v['HighBound']111 BlockUse[k] = BlockUse[k] - lim112 BlockUse[k][BlockUse[k] < 0] = 0113 lim = v['HighBound']114 BlockUseCharge[k] = BlockUse[k] * v['Value']115 del BlockUse['Q{}_kWh'.format(i)]116 del BlockUseCharge['Q{}_kWh'.format(i)]117 Results[TarComp, 'EnergyCharge_Q{}'.format(i)] = BlockUseCharge.sum(axis=1)118 Results[TarComp, 'EnergyCharge'] = Results[TarComp, 'EnergyCharge_Q1'] +Results[TarComp, 'EnergyCharge_Q2']\119 +Results[TarComp, 'EnergyCharge_Q3']+Results[TarComp, 'EnergyCharge_Q4']120 if 'Discount (%)' in tariff:121 Results[TarComp, 'EnergyCharge_Discounted'] = Results[TarComp, 'EnergyCharge'] * (122 1 - tariff['Discount (%)'] / 100)123 else:124 Results[TarComp, 'EnergyCharge_Discounted'] = Results[TarComp, 'EnergyCharge']125 if 'FiT' in TarCompVal:126 Results[TarComp, 'Fit_Rebate'] = Results['Annual_kWh_exp'] * TarCompVal['FiT']['Value']127 else:128 Results[TarComp, 'Fit_Rebate'] = 0129 if tariff['ProviderType'] == 'Retailer':130 Results['Bill'] = Results['Retailer', 'DailyCharge'] + Results['Retailer', 'EnergyCharge_Discounted'] - \131 Results['Retailer', 'Fit_Rebate']132 else:133 Results['Bill'] = Results['NUOS', 'DailyCharge'] + Results['NUOS', 'EnergyCharge_Discounted'] - Results[134 'NUOS', 'Fit_Rebate']135 return Results136 def tou_calc(load_profile, tariff):137 t0 = time.time()138 f_load_profile = load_profile139 imports = [np.nansum(f_load_profile[col].values[f_load_profile[col].values > 0])140 for col in f_load_profile.columns if col != 'READING_DATETIME']141 Results = pd.DataFrame(index=[col for col in f_load_profile.columns if col != 'READING_DATETIME'],142 data=imports, columns=['Annual_kWh'])143 Results['Annual_kWh_exp'] = [-1 * np.nansum(f_load_profile[col].values[f_load_profile[col].values < 0])144 for col in f_load_profile.columns if col != 'READING_DATETIME']145 if tariff['ProviderType'] == 'Retailer':146 tariff_temp = tariff.copy()147 del tariff_temp['Parameters']148 tariff_temp['Parameters'] = {'Retailer': tariff['Parameters']}149 tariff = tariff_temp.copy()150 for TarComp, TarCompVal in tariff['Parameters'].items():151 Results[TarComp,'DailyCharge'] = len(load_profile.index.normalize().unique()) * TarCompVal['Daily']['Value']152 time_ind = np.zeros(load_profile.shape[0])153 load_profile_TI = pd.DataFrame()154 load_profile_TI_Charge = pd.DataFrame()155 ti = 0156 for k, v in TarCompVal['Energy'].items():157 this_part = v.copy()158 ti += 1159 for k2, v2, in this_part['TimeIntervals'].items():160 start_hour = int(v2[0][0:2])161 if start_hour == 24:162 start_hour = 0163 start_min = int(v2[0][3:5])164 end_hour = int(v2[1][0:2])165 if end_hour == 0:166 end_hour = 24167 end_min = int(v2[1][3:5])168 if this_part['Weekday']:169 if start_hour <= end_hour:170 time_ind = np.where((load_profile.index.weekday < 5) &171 (load_profile.index.month.isin(this_part['Month'])) &172 (((60 * load_profile.index.hour + load_profile.index.minute)173 >= (60 * start_hour + start_min)) &174 ((60 * load_profile.index.hour + load_profile.index.minute)175 < (60 * end_hour + end_min))), ti,176 time_ind)177 else:178 time_ind = np.where((load_profile.index.weekday < 5) &179 (load_profile.index.month.isin(this_part['Month'])) &180 (((60 * load_profile.index.hour + load_profile.index.minute)181 >= (60 * start_hour + start_min)) |182 ((60 * load_profile.index.hour + load_profile.index.minute)183 < (60 * end_hour + end_min))), ti,184 time_ind)185 if this_part['Weekend']:186 if start_hour <= end_hour:187 time_ind = np.where((load_profile.index.weekday >= 5) &188 (load_profile.index.month.isin(this_part['Month'])) &189 (((60 * load_profile.index.hour + load_profile.index.minute)190 >= (60 * start_hour + start_min)) &191 ((60 * load_profile.index.hour + load_profile.index.minute)192 < (60 * end_hour + end_min))), ti,193 time_ind)194 else:195 time_ind = np.where((load_profile.index.weekday >= 5) &196 (load_profile.index.month.isin(this_part['Month'])) &197 (((60 * load_profile.index.hour + load_profile.index.minute)198 >= (60 * start_hour + start_min)) |199 ((60 * load_profile.index.hour + load_profile.index.minute)200 < (60 * end_hour + end_min))), ti,201 time_ind)202 load_profile_TI[k] = load_profile.loc[time_ind == ti, :].sum()203 load_profile_TI_Charge[k] = this_part['Value'] * load_profile_TI[k]204 Results[TarComp,'EnergyCharge'] = load_profile_TI_Charge.sum(axis=1)205 if 'Discount (%)' in tariff:206 Results[TarComp,'EnergyCharge_Discounted'] = Results[TarComp,'EnergyCharge'] * (1 - tariff['Discount (%)'] / 100)207 else:208 Results[TarComp,'EnergyCharge_Discounted'] = Results[TarComp,'EnergyCharge']209 if 'FiT' in TarCompVal:210 Results[TarComp, 'Fit_Rebate'] = Results['Annual_kWh_exp'] * TarCompVal['FiT']['Value']211 else:212 Results[TarComp, 'Fit_Rebate'] = 0213 if tariff['ProviderType'] == 'Retailer':214 Results['Bill'] = Results['Retailer','DailyCharge'] + Results['Retailer','EnergyCharge_Discounted'] - Results['Retailer','Fit_Rebate']215 else:216 Results['Bill'] = Results['NUOS','DailyCharge'] + Results['NUOS','EnergyCharge_Discounted'] - Results['NUOS','Fit_Rebate']217 print(time.time() - t0)218 return Results219 def demand_charge(load_profile, tariff):220 f_load_profile = load_profile221 imports = [np.nansum(f_load_profile[col].values[f_load_profile[col].values > 0])222 for col in f_load_profile.columns if col != 'READING_DATETIME']223 Results = pd.DataFrame(index=[col for col in f_load_profile.columns if col != 'READING_DATETIME'],224 data=imports, columns=['Annual_kWh'])225 Results['Annual_kWh_exp'] = [-1 * np.nansum(f_load_profile[col].values[f_load_profile[col].values < 0])226 for col in f_load_profile.columns if col != 'READING_DATETIME']227 if tariff['ProviderType'] == 'Retailer':228 tariff_temp = tariff.copy()229 del tariff_temp['Parameters']230 tariff_temp['Parameters'] = {'Retailer': tariff['Parameters']}231 tariff = tariff_temp.copy()232 for TarComp, TarCompVal in tariff['Parameters'].items():233 Results[TarComp, 'DailyCharge'] = len(load_profile.index.normalize().unique()) * TarCompVal['Daily'][234 'Value']235 if ('Unit', '$/kWh') in TarCompVal['Energy'].items():236 Results[TarComp, 'EnergyCharge'] = Results['Annual_kWh'] * TarCompVal['Energy']['Value']237 else:238 load_profile_imp = load_profile.clip_lower(0)239 load_profile_Q1 = load_profile_imp.loc[load_profile_imp.index.month.isin([1, 2, 3]), :]240 load_profile_Q2 = load_profile_imp.loc[load_profile_imp.index.month.isin([4, 5, 6]), :]241 load_profile_Q3 = load_profile_imp.loc[load_profile_imp.index.month.isin([7, 8, 9]), :]242 load_profile_Q4 = load_profile_imp.loc[load_profile_imp.index.month.isin([10, 11, 12]), :]243 Results['Q1_kWh'] = load_profile_Q1.sum()244 Results['Q2_kWh'] = load_profile_Q2.sum()245 Results['Q3_kWh'] = load_profile_Q3.sum()246 Results['Q4_kWh'] = load_profile_Q4.sum()247 for i in range(1, 5):248 BlockUse = Results[['Q{}_kWh'.format(i)]].copy()249 BlockUseCharge = BlockUse.copy()250 lim = 0251 for k, v in TarCompVal['Energy'].items():252 BlockUse[k] = BlockUse['Q{}_kWh'.format(i)]253 BlockUse[k][BlockUse[k] > v['HighBound']] = v['HighBound']254 BlockUse[k] = BlockUse[k] - lim255 BlockUse[k][BlockUse[k] < 0] = 0256 lim = v['HighBound']257 BlockUseCharge[k] = BlockUse[k] * v['Value']258 del BlockUse['Q{}_kWh'.format(i)]259 del BlockUseCharge['Q{}_kWh'.format(i)]260 Results[TarComp, 'EnergyCharge_Q{}'.format(i)] = BlockUseCharge.sum(axis=1)261 Results[TarComp, 'EnergyCharge'] = Results[TarComp, 'EnergyCharge_Q1'] + Results[TarComp, 'EnergyCharge_Q2'] \262 + Results[TarComp, 'EnergyCharge_Q3'] + Results[263 TarComp, 'EnergyCharge_Q4']264 if 'Discount (%)' in tariff:265 Results[TarComp, 'EnergyCharge_Discounted'] = Results[TarComp, 'EnergyCharge'] * (266 1 - tariff['Discount (%)'] / 100)267 else:268 Results[TarComp, 'EnergyCharge_Discounted'] = Results[TarComp, 'EnergyCharge']269 if 'FiT' in TarCompVal:270 Results[TarComp, 'Fit_Rebate'] = Results['Annual_kWh_exp'] * TarCompVal['FiT']['Value']271 else:272 Results[TarComp, 'Fit_Rebate'] = 0273 Results[TarComp, 'Demand'] = 0274 Results[TarComp, 'DemandCharge'] = 0275 for DemCharComp, DemCharCompVal in TarCompVal['Demand'].items():276 TSNum = DemCharCompVal['Demand Window Length'] # number of timestamp277 NumofPeaks = DemCharCompVal['Number of Peaks']278 if TSNum > 1:279 load_profile_r = load_profile.rolling(TSNum, min_periods=1).mean()280 else:281 load_profile_r = load_profile282 time_ind = np.zeros(load_profile.shape[0])283 ti = 1284 for k2, v2, in DemCharCompVal['TimeIntervals'].items():285 start_hour = int(v2[0][0:2])286 if start_hour == 24:287 start_hour = 0288 start_min = int(v2[0][3:5])289 end_hour = int(v2[1][0:2])290 if end_hour == 0:291 end_hour = 24292 end_min = int(v2[1][3:5])293 if DemCharCompVal['Weekday']:294 if start_hour <= end_hour:295 time_ind = np.where((load_profile.index.weekday < 5) &296 (load_profile.index.month.isin(DemCharCompVal['Month'])) &297 (((60 * load_profile.index.hour + load_profile.index.minute)298 >= (60 * start_hour + start_min)) &299 ((60 * load_profile.index.hour + load_profile.index.minute)300 < (60 * end_hour + end_min))), ti,301 time_ind)302 else:303 time_ind = np.where((load_profile.index.weekday < 5) &304 (load_profile.index.month.isin(DemCharCompVal['Month'])) &305 (((60 * load_profile.index.hour + load_profile.index.minute)306 >= (60 * start_hour + start_min)) |307 ((60 * load_profile.index.hour + load_profile.index.minute)308 < (60 * end_hour + end_min))), ti,309 time_ind)310 if DemCharCompVal['Weekend']:311 if start_hour <= end_hour:312 time_ind = np.where((load_profile.index.weekday >= 5) &313 (load_profile.index.month.isin(DemCharCompVal['Month'])) &314 (((60 * load_profile.index.hour + load_profile.index.minute)315 >= (60 * start_hour + start_min)) &316 ((60 * load_profile.index.hour + load_profile.index.minute)317 < (60 * end_hour + end_min))), ti,318 time_ind)319 else:320 time_ind = np.where((load_profile.index.weekday >= 5) &321 (load_profile.index.month.isin(DemCharCompVal['Month'])) &322 (((60 * load_profile.index.hour + load_profile.index.minute)323 >= (60 * start_hour + start_min)) |324 ((60 * load_profile.index.hour + load_profile.index.minute)325 < (60 * end_hour + end_min))), ti,326 time_ind)327 load_profile_r = load_profile_r.loc[time_ind == ti, :]328 load_profile_f = load_profile_r.copy()329 load_profile_f = load_profile_f.reset_index()330 load_profile_f = pd.melt(load_profile_f, id_vars=['READING_DATETIME'],331 value_vars=[x for x in load_profile_f.columns if x != 'READING_DATETIME'])332 load_profile_f = load_profile_f.rename(columns={'variable': 'HomeID', 'value': 'kWh'})333 load_profile_f['Month'] = pd.to_datetime(load_profile_f['READING_DATETIME']).dt.month334 AveragePeaks = 2 * load_profile_f[['HomeID', 'kWh', 'Month']].groupby(['HomeID', 'Month']).apply(335 lambda x: x.sort_values('kWh', ascending=False)[:NumofPeaks]).reset_index(drop=True).groupby(336 ['HomeID']).mean()337 Results[TarComp, 'Demand'] = Results[TarComp, 'Demand'] + AveragePeaks['kWh']338 Results[TarComp, 'DemandCharge'] = Results[TarComp, 'DemandCharge'] + AveragePeaks['kWh'] * DemCharCompVal['Value']339 # AllAveragePeaks = AllAveragePeaks.append(AveragePeaks)340 if tariff['ProviderType'] == 'Retailer':341 Results['Bill'] = Results['Retailer', 'DailyCharge'] + Results['Retailer', 'EnergyCharge_Discounted'] + \342 Results['NUOS', 'DemandCharge'] - Results['Retailer', 'Fit_Rebate']343 else:344 Results['Bill'] = Results['NUOS', 'DailyCharge'] + Results['NUOS', 'EnergyCharge_Discounted'] + \345 Results['NUOS', 'DemandCharge'] - Results['NUOS', 'Fit_Rebate']346 return Results347 # Checking the type and run the appropriate function348 load_profile = pre_processing_load(load_profile)349 if tariff['Type'] == 'Flat_rate':350 Results = fr_calc(load_profile, tariff)351 elif tariff['Type'] == 'TOU':352 Results = tou_calc(load_profile, tariff)353 elif tariff['Type'] == 'Block_Annual':354 Results = block_annual(load_profile, tariff)355 elif tariff['Type'] == 'Block_Quarterly':356 Results = block_quarterly(load_profile, tariff)357 elif tariff['Type'] == 'Demand_Charge':358 Results = demand_charge(load_profile, tariff)359 else:360 Results = 'Error'...

Full Screen

Full Screen

models.py

Source:models.py Github

copy

Full Screen

1from django.core.validators import MaxLengthValidator2from django.contrib.auth.models import AbstractUser3from django.db import models4from django.db.models.signals import post_save5from phonenumber_field.modelfields import PhoneNumberField6class User(AbstractUser):7 is_vendor = models.BooleanField('Vendor', default=False)8 is_engineer = models.BooleanField('Engineer', default=False)9 email = models.EmailField(unique=True)10 USERNAME_FIELD = 'email'11 REQUIRED_FIELDS = ['username']12class Vendor(models.Model):13 name = models.CharField('Vendor Name', max_length=125)14 user = models.OneToOneField('User', on_delete=models.CASCADE)15 address = models.CharField(max_length=1200)16 phone_number = PhoneNumberField(blank=False)17class Engineer(models.Model):18 name = models.CharField('Vendor Name', max_length=125)19 user = models.OneToOneField('User', on_delete=models.CASCADE)20 address = models.CharField(max_length=1200)21 phone_number = PhoneNumberField(blank=False)22 years_of_experience = models.IntegerField()23class Project(models.Model):24 user = models.ForeignKey('User', on_delete=models.CASCADE)25 load_profile = models.OneToOneField(26 'LoadProfile', on_delete=models.SET_NULL, null=True)27TYPE_CHOICE = (28 ('AC', 'AC'),29 ('DC', 'DC')30)31class Load(models.Model):32 load_name = models.CharField(max_length=120)33 load_rating = models.FloatField()34 quantity = models.IntegerField()35 hourly_usage = models.FloatField()36 weekly_usage = models.FloatField()37 profile_type = models.CharField(choices=TYPE_CHOICE, max_length=2)38 inverter_efficiency = models.FloatField(blank=True, null=True, default=0.9)39 total_wattage_hourly = models.FloatField()40 load_profile = models.ForeignKey(41 'LoadProfile', related_name='loads', on_delete=models.CASCADE, null=True)42 def save(self, *args, **kwargs):43 total_usage = (self.load_rating *44 self.hourly_usage * self.weekly_usage * self.quantity) / (7)45 self.total_wattage_hourly = total_usage46 super().save(*args, **kwargs)47 def __str__(self):48 return f'{self.load_name} for {self.load_profile} loadProfile'49class LoadProfile(models.Model):50 total_demand = models.FloatField(default=0)51 total_ac_demand = models.FloatField(default=0)52 total_dc_demand = models.FloatField(default=0)53 user = models.ForeignKey('User', on_delete=models.CASCADE)54 name = models.CharField(max_length=120)55 peak_sun_hours = models.FloatField(default=3.5)56 battery_capacity = models.FloatField(default=0)57 inverter_rating = models.FloatField(default=0)58 inverter_efficiency = models.FloatField(blank=True, null=True)59 array_sizing = models.FloatField(default=0)60 cable_sizing = models.FloatField(default=0)61 no_of_panels = models.FloatField(default=0)62 panel_output = models.FloatField(default=0)63 def save(self, *args, **kwargs):64 self.inverter_rating = (self.total_demand + (self.total_demand * 0.3))65 return super().save(*args, **kwargs)66 def __str__(self):67 return f'{self.name} {self.total_demand}'68class SolarModel(models.Model):69 image = models.ImageField(null=True)70 isc = models.DecimalField("Short circuit current",71 decimal_places=2, max_digits=10)72 pveff = models.DecimalField(73 "PV efficiency", decimal_places=2, max_digits=10)74 power_rating = models.IntegerField()75 plan_file = models.FileField(null=True)76 peak_generation_factor = models.DecimalField(77 decimal_places=2, max_digits=10)78 name = models.CharField(max_length=120)79 def __str__(self):80 return self.name81def calculate_total_load(sender, **kwargs):82 total = 083 ac_total = 084 dc_total = 085 load_profile = kwargs['instance'].load_profile86 loads = load_profile.loads.all()87 IE = load_profile.inverter_efficiency or None88 for load in loads:89 if not IE and load.profile_type == 'AC':90 load_profile.inverter_efficiency = load.inverter_efficiency91 if load.profile_type == 'AC':92 ac_total += load.total_wattage_hourly / load_profile.inverter_efficiency93 if load.profile_type == 'DC':94 dc_total += load.total_wattage_hourly95 load_profile.total_ac_demand = ac_total96 load_profile.total_dc_demand = dc_total97 load_profile.total_demand = dc_total + ac_total98 load_profile.save()...

Full Screen

Full Screen

EnergySystem.py

Source:EnergySystem.py Github

copy

Full Screen

...28 PVTcapacity = i['size']29 else:30 PVTcapacity = 031 load = Demand(self.simulation_duration)32 load_profile = load.load_profile()33 load_profile_lis.append({'load':[1],'profile':load_profile})34 print('load', sum(load_profile['Energy']))35 # generation profile36 tempdp = load.load_profile()37 net_nondispatchable_load = tempdp['Energy']38 for i, k in enumerate(self.solar):39 generation = GenerationAsset(k['size'],self.simulation_duration,k['type'])40 generation_profile = generation.load_profile()41 generation_profile_lis.append({'type-size':[k['type'],k['size']],'profile':generation_profile})42 net_nondispatchable_load -= generation_profile['Energy']43 print(k['type'], sum(generation.load_profile()['Energy']))44 #dispatchable -- battery45 # positive net_nondispatchable_load means exist load, energy need46 for i in self.dispatchable:47 storage = StorageAsset(net_nondispatchable_load, i[0], i[1],i[2])48 if rhc:49 storage_profile = storage.get_output()50 else:51 storage_profile = storage.get_output()52 net_nondispatchable_load = net_nondispatchable_load - storage_profile53 storage_profile_lis.append({'capacity:power/energy':[i[0],i[1]],'profile':storage_profile,'type':i[2]})54 print('storage',[i[0],i[1]], sum(storage_profile))55 #Market Simulation56 market = Market(net_nondispatchable_load,load_profile_lis,generation_profile_lis,storage_profile_lis,self.solar,self.dispatchable,self.simulation_duration)57 if rhc:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful