def calculate_number_of_available_data(self): """ | Calculate number of available data :return: {"temp": temp, "tempDist": tempDist, "rhDist": rhDist, "prec": prec, "windDist": windDist, "sign": sign, "snowDepth": snowDepth} """ temp = Climate.number(self.tempMins) > 0 and Climate.number( self.tempMaxs) > 0 tempDist = Climate.number2(self.generate_temp_distribution()) > 0 rhDist = Climate.number2(self.generate_rh_distribution()) > 0 prec = Climate.number( self.collect_daily_precipitation()) > 0 and Climate.sum( self.collect_daily_precipitation()) > 0 windDist = Climate.number2(self.generate_wind_distribution(), True) > 0 sign = Climate.sum([ self.monthObjs[0].significants.get(i) for i in self.monthObjs[0].significants ]) > 0 snowDepth = Climate.number( self.collect_snow_depth()) > 0 and Climate.sum( self.collect_snow_depth()) > 0 return { "temp": temp, "tempDist": tempDist, "rhDist": rhDist, "prec": prec, "windDist": windDist, "sign": sign, "snowDepth": snowDepth, }
def calculate_number_of_available_data(self): """ | Calculate number of available data for every months :return: {"temp": temp, "tempDist": tempDist, "rhDist": rhDist, "prec": prec, "windDist": windDist, "sign": sign } """ temp = Climate.number( self.collect_monthly_data('tempMin')) > 0 and Climate.number( self.collect_monthly_data('tempMinAvg')) > 0 tempDist = Climate.number2(self.generate_temperature_distribution(), strict=True) > 0 rhDist = Climate.number2(self.generate_rh_distribution(), strict=True) > 0 prec = Climate.number( self.collect_monthly_data('precipitation')) > 0 and Climate.sum( self.collect_monthly_data('precipitation')) > 0 windDist = Climate.number2(self.generate_wind_distribution(), strict=True) > 0 sign = False for m in self.monthObjs: if Climate.sum([ self.monthObjs[0].significants.get(i) for i in self.monthObjs[0].significants ]) > 0: sign = True break return { "temp": temp, "tempDist": tempDist, "rhDist": rhDist, "prec": prec, "windDist": windDist, "sign": sign }
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_sum_without_null(self): self.assertEqual(Climate.sum([0, 2, -4]), -2)
def test_sum_with_null(self): self.assertEqual(Climate.sum([0, 5, None, -1]), 4)
def test_sum_only_null(self): self.assertEqual(Climate.sum([None, None]), 0)
def test_sum_empty(self): self.assertEqual(Climate.sum([]), 0)