Index: trunk/tools/wsor/message_templates/umetrics/generators/edit_counts.py |
— | — | @@ -1,4 +1,4 @@ |
2 | | -import itertools |
| 2 | +import itertools, datetime, time |
3 | 3 | from .metric_generator import MetricGenerator |
4 | 4 | |
5 | 5 | class EditCounts(MetricGenerator): |
— | — | @@ -10,9 +10,13 @@ |
11 | 11 | return itertools.chain(*[ |
12 | 12 | [ |
13 | 13 | 'ns_%s_revisions_before' % ns, |
14 | | - 'ns_%s_revisions_after' % ns, |
| 14 | + 'ns_%s_revisions_after_0_3' % ns, |
| 15 | + 'ns_%s_revisions_after_3_30' % ns, |
| 16 | + 'ns_%s_revisions_after_gt_30' % ns, |
15 | 17 | 'ns_%s_revisions_deleted_before' % ns, |
16 | | - 'ns_%s_revisions_deleted_after' % ns |
| 18 | + 'ns_%s_revisions_deleted_after_0_3' % ns, |
| 19 | + 'ns_%s_revisions_deleted_after_3_30' % ns, |
| 20 | + 'ns_%s_revisions_deleted_after_gt_30' % ns |
17 | 21 | ] |
18 | 22 | for ns in [0,3] |
19 | 23 | # for ns in itertools.chain(range(0,16), [100, 101, 108, 109]) |
— | — | @@ -21,12 +25,26 @@ |
22 | 26 | def values(self, username, timestamp): |
23 | 27 | rowData = {} |
24 | 28 | |
| 29 | + # Partition timestamps into: |
| 30 | + # |
| 31 | + # 0-3 days after |
| 32 | + # 3-30 days after |
| 33 | + # more than 30 days after |
| 34 | + |
| 35 | + timeobj = datetime.datetime(year=int(timestamp[:4]), month=int(timestamp[4:6]), day=int(timestamp[6:8]), hour=int(timestamp[8:10]), minute=int(timestamp[10:12]), second=int(timestamp[12:14])) |
| 36 | + |
| 37 | + timeobj_3_days = timeobj + datetime.timedelta(days=3) |
| 38 | + timeobj_30_days = timeobj + datetime.timedelta(days=30) |
| 39 | + |
| 40 | + timestamp_3_days = time.strftime("%Y%m%d%H%M%S", timeobj_3_days.timetuple()) |
| 41 | + timestamp_30_days = time.strftime("%Y%m%d%H%M%S", timeobj_30_days.timetuple()) |
| 42 | + |
25 | 43 | cursor = self.conn.cursor() |
26 | 44 | cursor.execute(""" |
27 | 45 | ( |
28 | 46 | SELECT |
29 | 47 | page_namespace as ns, |
30 | | - IF(rev_timestamp < %(timestamp)s, "before", "after") as whence, |
| 48 | + IF(rev_timestamp < %(timestamp)s, "before", IF(rev_timestamp < %(timestamp_3_days)s, "after_0_3", IF(rev_timestamp < %(timestamp_30_days)s, "after_3_30", "after_gt_30"))) as whence, |
31 | 49 | "" as deleted, |
32 | 50 | count(*) as revisions |
33 | 51 | FROM enwiki.revision |
— | — | @@ -37,7 +55,7 @@ |
38 | 56 | UNION ( |
39 | 57 | SELECT |
40 | 58 | ar_namespace as ns, |
41 | | - IF(ar_timestamp < %(timestamp)s, "before", "after") as whence, |
| 59 | + IF(ar_timestamp < %(timestamp)s, "before", IF(ar_timestamp < %(timestamp_3_days)s, "after_0_3", IF(ar_timestamp < %(timestamp_30_days)s, "after_3_30", "after_gt_30"))) as whence, |
42 | 60 | "_deleted" as deleted, |
43 | 61 | count(*) as revisions |
44 | 62 | FROM enwiki.archive |
— | — | @@ -46,6 +64,8 @@ |
47 | 65 | )""", |
48 | 66 | { |
49 | 67 | 'timestamp': timestamp, |
| 68 | + 'timestamp_3_days': timestamp_3_days, |
| 69 | + 'timestamp_30_days': timestamp_30_days, |
50 | 70 | 'username': username.encode('utf-8') |
51 | 71 | } |
52 | 72 | ) |