0
 |   uploadedby   |     uploaddate     |
    Gracey Vinas  | 2012-04-20 20:16:00
    Gracey Vinas  | 2012-04-20 20:25:00
    Gracey Vinas  | 2012-04-20 20:35:00
    Gracey Vinas  | 2012-04-20 20:39:00
    Gracey Vinas  | 2012-04-20 22:07:00
    Gracey Vinas  | 2012-04-21 00:04:00
    Gracey Vinas  | 2012-04-21 01:14:00
    Gracey Vinas  | 2012-04-23 17:56:00
    Gracey Vinas  | 2012-04-23 18:06:00
    Gracey Vinas  | 2012-04-23 18:21:00
    Gracey Vinas  | 2012-04-23 19:04:00
    Gracey Vinas  | 2012-04-23 19:11:00
    Gracey Vinas  | 2012-04-23 19:24:00
    Gracey Vinas  | 2012-04-23 20:08:00
    Gracey Vinas  | 2012-04-23 20:22:00
    Gracey Vinas  | 2012-04-23 21:00:00
    Gracey Vinas  | 2012-04-23 22:04:00
    Gracey Vinas  | 2012-04-23 22:17:00
    Gracey Vinas  | 2012-04-23 22:29:00
    Gracey Vinas  | 2012-04-23 23:02:00
    Gracey Vinas  | 2012-04-23 23:48:00
    Gracey Vinas  | 2012-04-24 00:23:00
    Gracey Vinas  | 2012-04-24 01:54:00
    Gracey Vinas  | 2012-04-24 17:13:00
    Gracey Vinas  | 2012-04-24 17:32:00
    Gracey Vinas  | 2012-04-24 17:38:00
    Gracey Vinas  | 2012-04-24 17:45:00
    Gracey Vinas  | 2012-04-24 17:54:00

msqlで日付ごとに各アップロードの平均経過時間を取得するにはどうすればよいですか。例(2012-04-20の各アップロードの平均経過時間は(行1と行2の時間差(9分)+行2と行3の時間差(10分)+行3と行の時間差4(4分)+行4と行5の時間差(92分)/4=平均経過時間は28.75分です。

4

1 に答える 1

0

言語を指定しなかったため、Python ソリューションがあります。

from re import search
from itertools import groupby
from operator import itemgetter
from datetime import datetime

elapsed = []
averages = []
with open("log.txt","r") as f:
    for line in f:
        date = search("\d{4}-\d{2}-\d{2}",line)
        time = search("\d{2}:\d{2}:\d{2}",line)
        if (date and time):
            elapsed.append((date.group(),datetime.strptime(time.group(),'%H:%M:%S')))
    for date,times in groupby(elapsed,itemgetter(0)):
        times = list(times)
        averages.append((date,(times[-1][1]-times[0][1]).seconds/60./(len(times)-1)))

for avg in averages:
    print 'On date %s average minutes downloading is %.2f' % avg

log.txtファイル内のデータの出力は次のとおりです。

On date 2012-04-20 average minutes downloading is 27.75
On date 2012-04-21 average minutes downloading is 70.00
On date 2012-04-23 average minutes downloading is 27.08
On date 2012-04-24 average minutes downloading is 175.17
于 2013-01-29T12:56:23.070 に答える