예제 #1
0
 def build(dict):
     object = collections.namedtuple("UCDay", dict.keys())(*dict.values())
     newHours = []
     for hourDict in object.hours:
         obHour = UCHour.build(hourDict)
         newHours.append(obHour)
     ucday = UCDay(object.date)
     ucday.hours = newHours
     return ucday
예제 #2
0
def convert_predictions_json_to_sorted_ucdays(predictions):
    ucdays = []
    days = predictions.keys()
    sorted_days = sorted(days)
    for day in sorted_days:
        ucday = UCDay(day)
        for i in range(0, 24):
            hour_json = predictions[day][i]
            ucday.hours[i] = UCHour.buildv2(hour_json)
        ucdays.append(ucday)
    return ucdays
예제 #3
0
def convert_day_hour_counts_to_ucdoc(uckey, day_hour_counts):
    ucdoc = UCDoc.build_from_concat_string(uckey)
    for day_map in day_hour_counts:
        if len(day_map) > 0:
            # There is only one key here.
            day = next(iter(day_map.keys()))
            hour_count_map = day_map[day]
            for hour_map in hour_count_map:
                if len(hour_map) > 0:
                    hour = next(iter(hour_map.keys()))
                    h = hour_map[hour]
                    records = ucdoc.records
                    if day not in records:
                        records[day] = UCDay(str(day))
                    dict = build_dict_from_counts(h, hour)
                    uchour = UCHour.buildv1(dict)
                    records[day].hours[hour] = uchour
    return ucdoc
예제 #4
0
 def devide(ucday, length_days):
     result = UCDay(ucday.date)
     for i in range(0, 24):
         _uchour = UCHour.devide(ucday.hours[i], length_days)
         result.hours[i] = _uchour
     return result
예제 #5
0
 def add(date, ucday1, ucday2):
     result = UCDay(date)
     for i in range(0, 24):
         sum_uchour = UCHour.add(ucday1.hours[i], ucday2.hours[i])
         result.hours[i] = sum_uchour
     return result
예제 #6
0
 def __init__(self, date):
     self.hours = []
     self.date = date
     for h_index in range(0, 24):
         self.__add_hour(UCHour(h_index))