示例#1
0
 def __init__(self, name, coords, country, aCapacity):
     self.name = name
     self.coords = coords
     self.Country = country
     self.Users = ""
     self.Capacity = aCapacity
     self.hours = Hours()
示例#2
0
文件: YearTest.py 项目: remar/bfiller
    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))
示例#3
0
    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)
示例#4
0
 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))
示例#5
0
    def get_total_time(self):
        total = Hours(0)

        for day in self.days:
            if day != None:
                total += day.get_length()

        return total
示例#6
0
    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
示例#7
0
文件: YearTest.py 项目: remar/bfiller
    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))
示例#8
0
文件: YearTest.py 项目: remar/bfiller
    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))
示例#9
0
    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
示例#10
0
文件: YearTest.py 项目: remar/bfiller
 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)))
示例#11
0
文件: YearTest.py 项目: remar/bfiller
 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)))
示例#12
0
文件: YearTest.py 项目: remar/bfiller
    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))
示例#13
0
 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])
示例#14
0
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
        }
示例#15
0
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
示例#16
0
    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])
示例#17
0
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 !")
示例#18
0
 def test_can_return_total_minutes(self):
     hours = Hours(1, 10)
     self.assertEquals(hours.get_total_minutes(), 70)
示例#19
0
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
示例#20
0
 def test_can_be_empty(self):
     time_range = TimeRange()
     self.assertEquals(time_range.get_length(), Hours(0))
示例#21
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))
示例#22
0
 def test_create_simple_hour_object(self):
     hours = Hours(10)
     self.assertEquals(hours.get_hours(), 10)
示例#23
0
 def test_can_be_printed(self):
     self.assertEquals(str(Hours(4, 30)), "4:30")
     self.assertEquals(str(Hours(3)), "3:00")
示例#24
0
 def test_can_roll_over_when_subtracted(self):
     self.assertEquals(Hours(0, 50), Hours(1) - Hours(0, 10))
示例#25
0
 def test_can_be_compared_with_other_hours_object(self):
     self.assertEquals(Hours(10), Hours(10))
示例#26
0
 def test_can_be_subtracted(self):
     self.assertEquals(Hours(2), Hours(5) - Hours(3))
示例#27
0
 def test_can_return_total_minutes(self):
     hours = Hours(1, 10)
     self.assertEquals(hours.get_total_minutes(), 70)
示例#28
0
 def test_can_be_compared_with_gt(self):
     self.assertTrue(Hours(5) > Hours(3))
示例#29
0
 def test_create_simple_hour_object(self):
     hours = Hours(10)
     self.assertEquals(hours.get_hours(), 10)
示例#30
0
 def test_can_be_added(self):
     self.assertEquals(Hours(2) + Hours(3, 30), Hours(5, 30))
示例#31
0
 def test_can_be_created_with_minutes(self):
     hours = Hours(10, 30)
     self.assertEquals(hours.get_minutes(), 30)
示例#32
0
 def test_can_be_created_with_minutes(self):
     hours = Hours(10, 30)
     self.assertEquals(hours.get_minutes(), 30)
示例#33
0
 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))