Code Duplication    Length = 16-19 lines in 2 locations

omaha_server/omaha/statistics.py 2 locations

@@ 198-216 (lines=19) @@
195
196
197
198
def get_hourly_data_by_platform(app_id, end, n_hours, versions, platform, channel, tz='UTC'):
199
    def build_event_name(app_id, platform, channel, v):
200
        if channel:
201
            return "request:{}:{}:{}:{}".format(app_id, platform, channel, v)
202
        else:
203
            return "request:{}:{}:{}".format(app_id, platform, v)
204
205
    tzinfo = pytz.timezone(tz)
206
    start = end - timezone.timedelta(hours=n_hours)
207
208
    hours = [datetime(start.year, start.month, start.day, start.hour, tzinfo=pytz.UTC)
209
             + timezone.timedelta(hours=x) for x in range(1, n_hours + 1)]
210
211
    data = [(v, [[hour.astimezone(tzinfo).strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
212
                  len(HourEvents.from_date(build_event_name(app_id, platform, channel, v), hour))]
213
                 for hour in hours])
214
            for v in versions]
215
    data = filter(lambda version_data: sum([data[1] for data in version_data[1]]), data)
216
    return dict(data)
217
218
219
def get_daily_data_by_platform(app_id, end, n_days, versions, platform, channel):
@@ 219-234 (lines=16) @@
216
    return dict(data)
217
218
219
def get_daily_data_by_platform(app_id, end, n_days, versions, platform, channel):
220
    def build_event_name(app_id, platform, channel, v):
221
        if channel:
222
            return "request:{}:{}:{}:{}".format(app_id, platform, channel, v)
223
        else:
224
            return "request:{}:{}:{}".format(app_id, platform, v)
225
226
    start = end - timezone.timedelta(days=n_days)
227
228
    days = [start + timezone.timedelta(days=x) for x in range(0, n_days+1)]
229
    data = [(v, [[day.strftime("%Y-%m-%dT00:%M:%S.%fZ"),
230
                  len(DayEvents.from_date(build_event_name(app_id, platform, channel, v), day))]
231
                 for day in days])
232
            for v in versions]
233
    data = filter(lambda version_data: sum([data[1] for data in version_data[1]]), data)
234
    return dict(data)
235
236
237
def get_users_live_versions(app_id, start, end, channel, tz='UTC'):