def test_multiple_interval_calculation(self):
        day = WorkDay()
        day.clear_interval()

        time_one = Time(12, 30, Meridian.PM)
        time_two = Time(2, 30, Meridian.PM)

        date_one = Date(4, 29, 2021)
        date_two = Date(4, 29, 2021)

        date_time_one = DateTime(date_one, time_one)
        date_time_two = DateTime(date_two, time_two)

        day.set_interval_start(date_time_one)
        day.end_current_interval(date_time_two)

        time_one = Time(2, 30, Meridian.PM)
        time_two = Time(4, 30, Meridian.PM)

        date_time_one = DateTime(date_one, time_one)
        date_time_two = DateTime(date_two, time_two)

        day.set_interval_start(date_time_one)
        day.end_current_interval(date_time_two)

        self.assertEqual(str(day.get_total_hours_worked()), "4:00")
    def test_multiple_interval_not_hanging(self):
        day = WorkDay()
        day.clear_interval()

        time_one = Time(12, 30, Meridian.PM)
        time_two = Time(2, 30, Meridian.PM)

        date_one = Date(4, 29, 2021)
        date_two = Date(4, 29, 2021)

        date_time_one = DateTime(date_one, time_one)
        date_time_two = DateTime(date_two, time_two)

        day.set_interval_start(date_time_one)
        day.end_current_interval(date_time_two)

        time_one = Time(2, 30, Meridian.PM)
        time_two = Time(4, 30, Meridian.PM)

        date_time_one = DateTime(date_one, time_one)
        date_time_two = DateTime(date_two, time_two)

        day.set_interval_start(date_time_one)
        day.end_current_interval(date_time_two)

        self.assertEqual(day.check_for_incomplete_interval(), False)
Beispiel #3
0
 def test_can_return_week(self):
     m = Month(2012, 10)
     w = Week()
     w.set_day(0, TimeRange(Time(7), Time(17)))
     m.add_week(40, w)
     self.assertEquals(
         m.get_week(40).get_day(0), TimeRange(Time(7), Time(17)))
Beispiel #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))
Beispiel #5
0
    def test_can_return_half_week(self):
        m = Month(2012, 11)
        w = Week()
        w.set_day(2, TimeRange(Time(7), Time(17)))
        w.set_day(3, TimeRange(Time(8), Time(18)))
        m.add_week(44, w)

        self.assertEquals(m.get_week(44).get_day(2), None)
Beispiel #6
0
def main():
    t_test = Time()
    t_test.hour, t_test.minute, t_test.second = 10, 30, 47

    t_pace = Time()
    t_pace.hour, t_pace.minute, t_pace.second = 0, 5, 30

    print_time(pace(t_pace, 0.3))
Beispiel #7
0
    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))
Beispiel #8
0
    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))
Beispiel #9
0
    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))
Beispiel #10
0
 def __getcourses_and_time(self, roomsunavlb):
     courses = self.__doc.getElementsByTagName("courses")
     coursex = courses[0].getElementsByTagName("course")
     output = []
     outputimes = []
     timescounter = 0
     for course in coursex:
         y = course.getElementsByTagName("config")
         courseid = int(course.getAttribute("id"), 10)
         for config in y:
             z = config.getElementsByTagName("subpart")
             configid = int(config.getAttribute("id"), 10)
             for subpart in z:
                 w = subpart.getElementsByTagName("class")
                 subpartid = int(subpart.getAttribute("id"), 10)
                 for classx in w:
                     classid = int(classx.getAttribute("id"), 10)
                     classlimit = classx.getAttribute("limit")
                     parentclss = classx.getAttribute("parent")
                     if (parentclss != ''):
                         parentclss = int(parentclss, 10)
                     if (classlimit != ''):
                         classlimit = int(classlimit, 10)
                     roombool = classx.getAttribute("room")
                     rooms = {}
                     if (roombool != "false"):
                         aux = classx.getElementsByTagName("room")
                         for room in aux:
                             idaux = int(room.getAttribute("id"), 10)
                             penaux = int(room.getAttribute("penalty"), 10)
                             rooms[idaux] = penaux
                     else:
                         rooms = "false"
                     aux = classx.getElementsByTagName("time")
                     times = []
                     for time in aux:
                         days = time.getAttribute("days")
                         weeks = time.getAttribute("weeks")
                         start = int(time.getAttribute("start"), 10)
                         length = int(time.getAttribute("length"), 10)
                         penaux = int(time.getAttribute("penalty"), 10)
                         outputimes.append(
                             Time(days, start, length, weeks, penaux,
                                  classid, timescounter + 1))
                         times.append(timescounter)
                         timescounter += 1
                     output.append(
                         Clazz(classid, classlimit, rooms, parentclss,
                               courseid, configid, subpartid, times))
     for room in roomsunavlb:
         for unavai in room.unavailable:
             outputimes.append(
                 Time(unavai.days, unavai.start, unavai.length,
                      unavai.weeks, "unnv", room.id, timescounter + 1))
             timescounter += 1
     return (output, outputimes)
Beispiel #11
0
 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)))
Beispiel #12
0
 def test_returns_correctly_annotated_week_for_start_of_month(self):
     m = Month(2012, 11)
     w = Week()
     for i in xrange(7):
         w.set_day(i, TimeRange(Time(7), Time(17)))
     m.add_week(44, w)
     aw = m.get_week(44)
     self.assertEquals(aw.get_earliest_day_in_month(), 1)
     self.assertEquals(aw.get_first_valid_day(), 3)
     self.assertEquals(aw.get_last_valid_day(), 6)
Beispiel #13
0
 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)))
Beispiel #14
0
    def test_can_be_printed(self):
        w = Week()
        for i in xrange(7):
            w.set_day(i, TimeRange(Time(7), Time(17)))
        self.assertEquals(
            str(w), """M: 7:00-17:00
T: 7:00-17:00
O: 7:00-17:00
T: 7:00-17:00
F: 7:00-17:00
L: 7:00-17:00
S: 7:00-17:00""")
Beispiel #15
0
 def _get_assistance_week(self):
     w = Week()
     w.set_day(0, TimeRange(Time(13, 30), Time(17)))
     w.set_day(1, TimeRange(Time(6, 30), Time(8, 30)))
     w.set_day(2, TimeRange(Time(7), Time(17)))
     w.set_day(3, TimeRange(Time(6, 30), Time(8, 30)))
     return w
Beispiel #16
0
 def test_can_enter_times_from_last_week_in_month(self):
     m = Month(2012, 10)
     w = Week()
     w.set_day(2, TimeRange(Time(7), Time(17)))
     w.set_day(3, TimeRange(Time(7), Time(17)))
     m.add_week(44, w)
     self.assertEquals(m.get_day(31), TimeRange(Time(7), Time(17)))
     self.assertNotEquals(m.get_day(32), TimeRange(Time(7), Time(17)))
Beispiel #17
0
    def _prop_from_ref(self, p):

        if (p == None or p == WrapperNULL):
            return None

        d_string = icallangbind_property_eval_string(p, ":")

        d = eval(d_string)
        d['ref'] = p

        if not self.cached_props.has_key(p):

            if d['value_type'] == 'DATE-TIME' or d['value_type'] == 'DATE':
                prop = Time(d, )
            elif d['value_type'] == 'PERIOD':
                prop = Period(d)
            elif d['value_type'] == 'DURATION':
                prop = Duration(d)
            elif d['name'] == 'ATTACH':
                prop = Attach(d)
            elif d['name'] == 'ATTENDEE':
                prop = Attendee(d)
            elif d['name'] == 'ORGANIZER':
                prop = Organizer(d)
            else:
                prop = Property(ref=p)

            self.cached_props[p] = prop
Beispiel #18
0
 def sign_params(self, verb, path, params=None):
     if not params:
         params = {}
     params.update({'tonce': int(1000*Time.Time()), 'access_key': self.access_key})
     query = self.urlencode(params)
     signature = self.sign(verb, path, params)
     return signature, query
Beispiel #19
0
    def _prop_from_ref(self, p):

        if (p == None or p == WrapperNULL):
            return None

        d = {}
        d['value'] = icalproperty_get_value_as_string(p)
        d['name'] = icalproperty_get_property_name(p)

        propkind = icalproperty_string_to_kind(d['name'])
        kind = icalproperty_kind_to_value_kind(propkind)
        d['value_type'] = icalvalue_kind_to_string(kind)
        d['ref'] = p

        #~ print p, Property(ref=p).name()
        if not self.cached_props.has_key(p):

            if d['value_type'] == 'DATE-TIME' or d['value_type'] == 'DATE':
                prop = Time(d, )
            elif d['value_type'] == 'PERIOD':
                prop = Period(d)
            elif d['value_type'] == 'DURATION':
                prop = Duration(d)
            elif d['name'] == 'ATTACH':
                prop = Attach(d)
            elif d['name'] == 'ATTENDEE':
                prop = Attendee(d)
            elif d['name'] == 'ORGANIZER':
                prop = Organizer(d)
            else:
                prop = Property(ref=p)

            self.cached_props[p] = prop
Beispiel #20
0
def main():
    while True:
        conn = HTTPConnection(
            f"{argv[1] if len(argv) > 1 else  'localhost'}:{PORT}")

        try:
            conn.request("GET", "/")
        except ConnectionRefusedError as error:
            print(error)
            sleep(1)
            continue

        print('Connected')
        res = conn.getresponse()
        while True:
            chunk = res.readline()
            if (chunk == b'\n'): continue
            if (not chunk): break

            chunk = chunk[:-1].decode()
            data = json.loads(chunk)
            print(Time(), data)
            action = data['action']
            print('action', action)
            try:
                print(MOTOR_SPEEDS[action])
            except KeyError as error:
                print(error)
 def create_with_hairdressers(cls,
                              mean_time_wait_client,
                              time_period,
                              hairdressers_time,
                              start_time_work=Time(10, 0)):
     barber = cls(mean_time_wait_client, time_period)
     for time_work in hairdressers_time:
         barber.add_hairdresser(Hairdresser(time_work))
     return barber
def ask_time(reason):
    print("Please enter a time " + reason + ".")

    hours = user_input("hours")
    minutes = user_input("minutes")
    seconds = user_input("seconds")
    milliseconds = user_input("milliseconds")

    return Time(hours, minutes, seconds, milliseconds)
Beispiel #23
0
 def __init__(self):
     self.requests = Items()
     self.responses = Items()
     self.speaker_id = "ND"
     self.skill_id = "ND"
     mytime = Time()
     mytime.set_now()
     self.time = mytime
     self.dictionary = {}
Beispiel #24
0
    def __init__(self, map):
        self.map = map
        soldiers = dict(
            (loc, self.map.soldiers[loc].copy()) for loc in self.map.soldiers)
        id = 1
        for soldier in soldiers.values():
            soldier.id = id
            id += 1

        self.times = [Time(self.MIN_TIME, soldiers, dict())]
    def getTimes(self):
        self.conn.execute_query(
            'SELECT * FROM Edu_Times WHERE EndOfInterval = 0')
        times = {}
        for row in self.conn:
            time = Time(row['ID'], row['Title'], row['EndOfInterval'])
            times[row['ID']] = time

        self._times = times
        print 'Times: ', len(self._times)
        return times
 def __init__(self,
              mean_time_wait_client,
              time_period,
              start_time_work=Time(10, 0)):
     self.start_time_work = start_time_work
     self.mean_time_wait_client = mean_time_wait_client
     self.time_period = time_period
     self.alpha = 1 / mean_time_wait_client
     self.count_clients = self.__count_clients
     self.hairdressers = Hairdressers()
     self.queue_clients = QueueClients()
Beispiel #27
0
    def start(self, v=None):
        """
        Return or set start time of the period. The start time may be
        expressed as an RFC2445 format string or an instance of Time.
        The return value is an instance of Time
        """

        if (v != None):
            if isinstance(t, Time):
                t = v
            elif isinstance(t, StringType) or isinstance(t, IntType):
                t = Time(v, "DTSTART")
            else:
                raise TypeError

            self.pt.start = t.tt

            self._update_value()

        return Time(self.pt.start.as_timet(), "DTSTART")
    def test_single_interval_hanging(self):
        day = WorkDay()
        day.clear_interval()

        time_one = Time(12, 40, Meridian.PM)
        date_one = Date(4, 29, 2021)
        date_time_one = DateTime(date_one, time_one)

        day.set_interval_start(date_time_one)

        self.assertEqual(day.check_for_incomplete_interval(), True)
Beispiel #29
0
    def end(self,v=None):
        """
        Return or set end time of the period. The end time may be
        expressed as an RFC2445 format string or an instance of Time.
        The return value is an instance of Time.

        If the Period has a duration set, but not an end time, this
        method will caluculate the end time from the duration.  """

        if(v != None):
            
            if isinstance(t,Time):
                t = v
            elif isinstance(t,StringType) or isinstance(t,IntType):
                t = Time(v)
            else:
                raise TypeError

            if(self._end_is_duration()):
                start = icaltime_as_timet(icalperiodtype_start_get(self.pt))
                dur = t.utc_seconds()-start;
                icalperiodtype_duration_set(self.pt,
                                            icaldurationtype_from_int(dur))
            else:
                icalperiodtype_end_set(self.pt,t.tt)
                
            self._update_value()

        if(self._end_is_time()):
            rt = Time(icaltime_as_timet(icalperiodtype_end_get(self.pt)),
                      'DTEND')
            rt.timezone(self.timezone())
            return rt
        elif(self._end_is_duration()):
            start = icaltime_as_timet(icalperiodtype_start_get(self.pt))
            dur = icaldurationtype_as_int(icalperiodtype_duration_get(self.pt))
            rt = Time(start+dur,'DTEND')
            rt.timezone(self.timezone())
            return rt
        else:
            return Time({},'DTEND')
Beispiel #30
0
 def test_can_enter_times_into_first_incomplete_week(self):
     m = Month(2012, 11)
     w = Week()
     w.set_day(0, TimeRange(Time(7), Time(17)))
     w.set_day(3, TimeRange(Time(8), Time(18)))
     m.add_week(44, w)
     self.assertEquals(m.get_day(1), TimeRange(Time(8), Time(18)))