2014-04-11 16:56:49 +00:00
|
|
|
#!/usr/bin/python
|
2014-04-11 17:23:22 +00:00
|
|
|
# coding=UTF-8
|
2014-04-11 16:56:49 +00:00
|
|
|
|
|
|
|
# Выводит список активных кусков - кусков, не покрытых никаким другим куском.
|
|
|
|
# Использование: `ls /opt/clickhouse/data/merge/visits | active_parts.py`
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
|
|
|
|
parts = {}
|
|
|
|
for s in sys.stdin.read().split():
|
2014-05-08 12:35:46 +00:00
|
|
|
m = re.match('^([0-9]{6})[0-9]{2}_([0-9]{6})[0-9]{2}_([0-9]+)_([0-9]+)_([0-9]+)$', s)
|
|
|
|
if m == None:
|
|
|
|
continue
|
|
|
|
m1 = m.group(1)
|
|
|
|
m2 = m.group(2)
|
|
|
|
i1 = int(m.group(3))
|
|
|
|
i2 = int(m.group(4))
|
|
|
|
l = int(m.group(5))
|
|
|
|
if m1 != m2:
|
|
|
|
raise Exception('not in single month: ' + s)
|
|
|
|
if m1 not in parts:
|
|
|
|
parts[m1] = []
|
|
|
|
parts[m1].append((i1, i2, l, s))
|
2014-04-11 16:56:49 +00:00
|
|
|
|
|
|
|
for m in parts:
|
2014-07-07 10:21:57 +00:00
|
|
|
parts[m].sort(key=lambda (i1, i2, l, s): (i1, -i2, -l))
|
|
|
|
(x2, y2, l2, s2) = (-1, -1, -1, -1)
|
2014-05-08 12:35:46 +00:00
|
|
|
for x1, y1, l1, s1 in parts[m]:
|
2014-07-07 10:21:57 +00:00
|
|
|
if x1 >= x2 and y1 <= y2 and l1 < l2 and (x1, y1) != (x2, y2): # 2 contains 1
|
|
|
|
pass
|
|
|
|
elif x1 > y2: # 1 is to the right of 2
|
2014-08-01 09:30:56 +00:00
|
|
|
if x1 != y2 + 1 and y1 != -1:
|
2014-07-07 11:51:11 +00:00
|
|
|
print # чтобы на глаз было видно пропущенные номера
|
2014-07-07 10:21:57 +00:00
|
|
|
(x2, y2, l2, s2) = (x1, y1, l1, s1)
|
2014-05-08 12:35:46 +00:00
|
|
|
print s1
|
2014-07-07 10:21:57 +00:00
|
|
|
else:
|
|
|
|
raise Exception('invalid parts intersection: ' + s1 + ' and ' + s2)
|
2014-08-01 10:04:36 +00:00
|
|
|
print
|