def __init__(self, name, coords, country, aCapacity): self.name = name self.coords = coords self.Country = country self.Users = "" self.Capacity = aCapacity self.hours = Hours()
def test_doesnt_schedule_hours_scheduled_by_taken_week(self): y = Year(2012) taken = Week() taken.set_day(0, TimeRange(Time(13, 30), Time(17))) y.add_taken(40, taken) w = y.get_schedule_for_week(40, Hours(47, 50)) self.assertEquals(w.get_total_time(), Hours(44, 20))
def get_schedule_for_week(self, week_number, hours): disallowed = self._get_disallowed_week(week_number) hours -= self._get_taken_time(week_number) if hours > Hours(48): print "Too many hours for week", week_number, "! Please fill in", hours - Hours( 48), "manually!" hours = Hours(48) return generate_week(hours, disallowed)
def test_can_give_total_time_for_month(self): m = Month(2012, 10) w = Week() w.set_day(4, TimeRange(Time(7), Time(17, 10))) m.add_week(40, w) m.add_week(42, w) self.assertEquals(m.get_total_time(), Hours(20, 20))
def get_total_time(self): total = Hours(0) for day in self.days: if day != None: total += day.get_length() return total
def _get_taken_time(self, week_number): taken_time = Hours(0) taken = self.get_taken(week_number) if taken != None: taken_time = taken.get_total_time() return taken_time
def test_uses_taken_week_when_scheduling(self): y = Year(2012) taken = Week() taken.set_day(0, TimeRange(Time(13, 30), Time(17))) y.add_taken(40, taken) w = y.get_schedule_for_week(40, Hours(57, 50)) self.assertEquals(w.get_day(0).get_start(), Time(17))
def test_uses_blocked_week_when_scheduling(self): y = Year(2012) blocked = Week() blocked.set_day(0, TimeRange(Time(8, 30), Time(13, 30))) y.add_blocked(40, blocked) w = y.get_schedule_for_week(40, Hours(57, 50)) self.assertEquals(w.get_day(0).get_start(), Time(13, 30))
def get_total_time(self): total = Hours(0) for i in xrange(1, self._get_last_day_number() + 1): day = self.get_day(i) if day != None: total += day.get_length() return total
def test_can_generate_monthly_report_for_december(self): y2012 = Year(2012) y2013 = Year(2013) y2012.set_next_year(y2013) blocked = self._get_daycare_week() taken = self._get_assistance_week() y2013.add_blocked(1, blocked) y2013.add_taken(1, taken) m = y2012.generate_montly_report(12, Hours(48, 0)) self.assertEquals(m.get_day(31), TimeRange(Time(17), Time(20)))
def test_can_generate_realistic_monthly_report(self): y = Year(2012) blocked = self._get_daycare_week() taken = self._get_assistance_week() for i in [40, 41, 42, 43, 44]: y.add_blocked(i, blocked) y.add_taken(i, taken) m = y.generate_montly_report(10, Hours(57, 50)) self.assertEquals(m.get_day(1), TimeRange(Time(17), Time(20))) self.assertEquals(m.get_day(2), TimeRange(Time(13, 30), Time(20)))
def test_respects_both_blocked_and_taken_weeks(self): y = Year(2012) blocked = Week() blocked.set_day(0, TimeRange(Time(8, 30), Time(13, 30))) y.add_blocked(40, blocked) taken = Week() taken.set_day(1, TimeRange(Time(7), Time(17))) y.add_taken(40, taken) w = y.get_schedule_for_week(40, Hours(57, 50)) self.assertEquals(w.get_day(0).get_start(), Time(13, 30)) self.assertEquals(w.get_day(1).get_start(), Time(17))
def test_first_day_is_shorter_if_day_is_taken(self): taken_week = Week() taken_week.set_day(0, TimeRange(Time(7), Time(17))) week = generate_week(Hours(40), taken_week) ranges = [ TimeRange(Time(17), Time(20)), TimeRange(Time(7), Time(17)), TimeRange(Time(7), Time(17)), TimeRange(Time(7), Time(17)), TimeRange(Time(7), Time(14)) ] for i in xrange(5): self.assertEquals(week.get_day(i), ranges[i])
class Beach(object): Country = "" name = "" Traffic = "" CurrentDevices = 0 Result = 0 Capacity = 0 coords = [] Users = [] hours = Hours def __init__(self, name, coords, country, aCapacity): self.name = name self.coords = coords self.Country = country self.Users = "" self.Capacity = aCapacity self.hours = Hours() def make_Beach(name, coords): beach = Beach(name, coords) return beach def printBeach(self, beach): print(beach.name, beach.coords) def dump(self): return { Constants.BeachName: self.name, Constants.Coords: self.coords, Constants.CurrentDevices: self.CurrentDevices, Constants.Result: self.Result, 'Hours': self.hours.dump(), 'Capacity': self.Capacity, Constants.Traffic: Constants.LowTraffic, Constants.Country: self.Country } def getCountry(self): return self.Country def getCapacity(self): return self.Capacity def beachListenerDump(self, beachID): return { Constants.BeachName: self.name, Constants.CurrentDevices: self.CurrentDevices, Constants.BeachID: beachID }
def generate_week(hours, taken_week=None, latest_time=None): latest_time = latest_time or DEFAULT_LATEST_TIME longest_day = DEFAULT_LONGEST_DAY week = Week() day = 0 while hours > Hours(0): assert (day < 7) taken_hours = taken_week.get_day(day) if taken_week != None else None generated_day = generate_day( longest_day if hours > longest_day else hours, taken_hours, latest_time) if generated_day.get_length().get_total_minutes() > 0: week.set_day(day, generated_day) day += 1 hours -= generated_day.get_length() return week
def test_generates_realistic_schedule(self): taken_week = Week() taken = [ TimeRange(Time(8, 30), Time(13, 30)), TimeRange(Time(6, 30), Time(13, 30)), TimeRange(Time(7), Time(17)), TimeRange(Time(6, 30), Time(13, 30)) ] for i in xrange(len(taken)): taken_week.set_day(i, taken[i]) week = generate_week(Hours(30, 20), taken_week) ranges = [ TimeRange(Time(13, 30), Time(20)), # 23:50 left TimeRange(Time(13, 30), Time(20)), # 17:20 left TimeRange(Time(17), Time(20)), # 14:20 left TimeRange(Time(13, 30), Time(20)), # 7:50 left TimeRange(Time(7), Time(14, 50)) ] # 0:00 left for i in xrange(len(ranges)): self.assertEquals(week.get_day(i), ranges[i])
def update24HoursInDataBase(minHourValue, maxHourValue, predictedHourValue, beachInfo): len = predictedHourValue.__len__() hours = Hours() minEstimationValue = [] maxEstimationValue = [] currentEstimationValue = [] for i in range(len - (24), len): minEstimationValue.append(minHourValue['yhat_lower'][i]) maxEstimationValue.append(maxHourValue['yhat_upper'][i]) currentEstimationValue.append(predictedHourValue['yhat'][i]) # TODO delete one hour from initial excel for i in range(0, 24): mFirebaseData.child(Constants.Beaches).child(beachInfo.mBeachId).child( Constants.Hours).child(i).child(Constants.MinEstimation).set( minEstimationValue[i]) mFirebaseData.child(Constants.Beaches).child(beachInfo.mBeachId).child( Constants.Hours).child(i).child(Constants.CurrentEstimation).set( currentEstimationValue[i]) mFirebaseData.child(Constants.Beaches).child(beachInfo.mBeachId).child( Constants.Hours).child(i).child(Constants.MaxEstimation).set( maxEstimationValue[i]) print("update 24 hours in cloud !")
def test_can_return_total_minutes(self): hours = Hours(1, 10) self.assertEquals(hours.get_total_minutes(), 70)
from Hours import Hours from TimeRange import TimeRange from Time import Time from Week import Week DEFAULT_EARLIEST_TIME = Time(7) DEFAULT_LATEST_TIME = Time(20) DEFAULT_LONGEST_DAY = Hours(10) def generate_day(hours, taken=None, latest_time=None): if taken != None: start = taken.get_end() else: start = DEFAULT_EARLIEST_TIME new_end = start.add_hours(hours) if latest_time != None and new_end > latest_time: new_end = latest_time return TimeRange(start, new_end) def generate_week(hours, taken_week=None, latest_time=None): latest_time = latest_time or DEFAULT_LATEST_TIME longest_day = DEFAULT_LONGEST_DAY week = Week() day = 0 while hours > Hours(0): assert (day < 7) taken_hours = taken_week.get_day(day) if taken_week != None else None
def test_can_be_empty(self): time_range = TimeRange() self.assertEquals(time_range.get_length(), Hours(0))
def test_can_give_length_for_9_to_10_30(self): time_range = TimeRange(Time(9), Time(10, 30)) self.assertEquals(time_range.get_length(), Hours(1, 30))
def test_create_simple_hour_object(self): hours = Hours(10) self.assertEquals(hours.get_hours(), 10)
def test_can_be_printed(self): self.assertEquals(str(Hours(4, 30)), "4:30") self.assertEquals(str(Hours(3)), "3:00")
def test_can_roll_over_when_subtracted(self): self.assertEquals(Hours(0, 50), Hours(1) - Hours(0, 10))
def test_can_be_compared_with_other_hours_object(self): self.assertEquals(Hours(10), Hours(10))
def test_can_be_subtracted(self): self.assertEquals(Hours(2), Hours(5) - Hours(3))
def test_can_be_compared_with_gt(self): self.assertTrue(Hours(5) > Hours(3))
def test_can_be_added(self): self.assertEquals(Hours(2) + Hours(3, 30), Hours(5, 30))
def test_can_be_created_with_minutes(self): hours = Hours(10, 30) self.assertEquals(hours.get_minutes(), 30)
def test_simple_range_from_9_to_17_is_8_hours(self): time_range = TimeRange(Time(9, 0), Time(17, 0)) self.assertEquals(time_range.get_length(), Hours(8))