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 年 4 月 20 日每次上传的平均经过时间为(第 1 行和第 2 行的时间差(9 分钟)+第 2 行和第 3 行的时间差(10 分钟)+第 3 行和第 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 回答