def __init__(self, siteId, year, month, monthObjs, yearObj, dayObjs, manualDayObjs): self.siteId = siteId self.year = year self.month = month self.monthObjs = monthObjs self.yearObj = yearObj self.dayObjs = dayObjs self.manualDayObjs = manualDayObjs self.monthObj = Month(year=self.year, month=self.month) self.days = Month(year=self.year, month=self.month).get_days_of_month() self.tempMins, self.tempAvgs, self.tempMaxs = self.collect_daily_temperature( ) self.indices = self.calculate_climate_index_days() self.tempDist = json.dumps(self.generate_temp_distribution()) self.rhDist = json.dumps(self.generate_rh_distribution()) self.prec = json.dumps(self.collect_daily_precipitation()) self.precDist = Climate.get_precipitation_over_limits( self.collect_daily_precipitation()) self.windDist = json.dumps(self.generate_wind_distribution()) self.significants = json.dumps(monthObjs[0].significants) self.precipitation = Climate.sum(self.collect_daily_precipitation()) self.tmin = Climate.avg(self.tempMins) self.tmax = Climate.avg(self.tempMaxs) self.tavg = Climate.avg2(self.tempMins, self.tempMaxs) self.dataAvailable = self.calculate_number_of_available_data() self.tempMins = json.dumps(self.tempMins) self.tempAvgs = json.dumps(self.tempAvgs) self.tempMaxs = json.dumps(self.tempMaxs) self.snowDepths = json.dumps(self.collect_snow_depth()) self.snowDays = self.get_nr_of_snow_days() self.comments = self.get_comments()
def __init__(self, siteId, year, monthObjs, yearObj, dayObjs, manualDayObjs): self.siteId = siteId self.year = year self.monthObjs = monthObjs self.yearObj = yearObj self.dayObjs = dayObjs self.manualDayObjs = manualDayObjs self.months = Year.get_months_of_year() self.temps = { 'mins': json.dumps(self.collect_monthly_data('tempMin')), 'minAvgs': json.dumps(self.collect_monthly_data('tempMinAvg')), 'avgs': json.dumps(self.collect_monthly_data('tempAvg')), 'maxAvgs': json.dumps(self.collect_monthly_data('tempMaxAvg')), 'maxs': json.dumps(self.collect_monthly_data('tempMax')) } self.tempIndices = { 'summerDays': json.dumps(self.collect_monthly_data('summerDays')), 'frostDays': json.dumps(self.collect_monthly_data('frostDays')), 'winterDays': json.dumps(self.collect_monthly_data('winterDays')), 'coldDays': json.dumps(self.collect_monthly_data('coldDays')), 'warmNights': json.dumps(self.collect_monthly_data('warmNights')), 'warmDays': json.dumps(self.collect_monthly_data('warmDays')), 'hotDays': json.dumps(self.collect_monthly_data('hotDays')) } self.prec = json.dumps(self.collect_monthly_data('precipitation')) self.tempDist = json.dumps(self.generate_temperature_distribution()) self.rhDist = json.dumps(self.generate_rh_distribution()) self.windDist = json.dumps(self.generate_wind_distribution()) self.precipitation = Climate.sum( self.collect_monthly_data('precipitation')) self.precDist = Climate.get_precipitation_over_limits( self.collect_daily_data('precipitation')) self.tmin = Climate.avg(self.collect_monthly_data('tempMin')) self.tmax = Climate.avg(self.collect_monthly_data('tempMax')) self.tavg = Climate.avg2(self.collect_monthly_data('tempMin'), self.collect_monthly_data('tempMax')) self.dataAvailable = self.calculate_number_of_available_data() self.snowDays = self.get_nr_of_snow_days()
def test_avg_not_none(self): self.assertEqual(Climate.avg([0, 5, 10]), 5)
def test_avg_only_none(self): self.assertEqual(Climate.avg([None, None, None]), None)
def test_avg_with_none(self): self.assertEqual(Climate.avg([-2, None, -1]), -1.5)
def test_avg_empty(self): self.assertEqual(Climate.avg([]), None)