This repository has been archived by the owner on Sep 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests_alex.py
122 lines (88 loc) · 4.12 KB
/
tests_alex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from chrony import timespans
import pandas as pd
print('')
print('Test merge_overlapping_events #1')
print('=================================')
begs = pd.to_datetime(['2014-09-12 12:00:00','2014-09-12 13:00:00','2014-09-12 14:00:00', '2014-09-12 15:00:00', '2014-09-12 22:00:00','2014-09-12 23:15:00','2014-09-12 23:46:00'])
ends = pd.to_datetime(['2014-09-12 12:30:00','2014-09-12 15:30:00','2014-09-12 15:00:00', '2014-09-12 16:00:00','2014-09-12 23:00:00','2014-09-12 23:16:00','2014-09-12 23:50:00'])
df = pd.DataFrame({'ts_beg':begs,'ts_end':ends})
print('')
print('df=')
print(df)
print('')
print('merge_overlapping_events(df,ts_beg,ts_end)=')
print(timespans.merge_overlapping_events(df,'ts_beg','ts_end'))
print('')
print('Test merge_overlapping_events #2')
print('=================================')
begs = pd.date_range('2014-09-12 12:00:00','2014-09-12 20:00:00',freq='h')
ends = pd.date_range('2014-09-12 13:00:01','2014-09-12 21:00:01',freq='h')
df = pd.DataFrame({'ts_beg':begs,'ts_end':ends})
print('')
print('df=')
print(df)
print('')
print('merge_overlapping_events(df, ts_beg, ts_end)=')
print(timespans.merge_overlapping_events(df,'ts_beg','ts_end'))
print('')
print('Test merge_overlapping_events_kind #1')
print('======================================')
begs = pd.date_range('2014-09-12 12:00:00','2014-09-12 20:00:00',freq='h')
ends = pd.date_range('2014-09-12 13:00:01','2014-09-12 21:00:01',freq='h')
cats = []
for i in range(len(begs)):
if i<len(begs)/2:
cats.append(1)
else:
cats.append(2)
df = pd.DataFrame({'ts_beg':begs,'ts_end':ends,'category':cats})
print('')
print('df=')
print(df)
print('')
print('merge_overlapping_events_kind(df, \'ts_beg\', \'ts_end\', [\'category\'])=')
print(timespans.merge_overlapping_events_kind(df,'ts_beg','ts_end',kind=['category']))
print('')
print('Test merge_overlapping_events_kind #2')
print('======================================')
begs = pd.to_datetime(['2014-09-12 12:00:00','2014-09-12 13:00:00','2014-09-12 14:00:00', '2014-09-12 15:00:00', '2014-09-12 17:00:00'])
ends = pd.to_datetime(['2014-09-12 12:30:00','2014-09-12 15:30:00','2014-09-12 15:00:00', '2014-09-12 17:01:00','2014-09-12 18:00:00'])
cats = [1,1,1,2,2]
df = pd.DataFrame({'ts_beg':begs,'ts_end':ends,'category':cats})
print('')
print('df=')
print(df)
print('')
print('merge_overlapping_events_kind(df, \'ts_beg\', \'ts_end\', [\'category\'])=')
print(timespans.merge_overlapping_events_kind(df,'ts_beg','ts_end',kind=['category']))
print('')
print('Test add_time_between_events #1')
print('======================================')
begs = pd.to_datetime(['2014-09-12 12:00:00','2014-09-12 13:00:00','2014-09-12 14:00:00', '2014-09-12 15:00:00', '2014-09-12 17:00:00'])
ends = pd.to_datetime(['2014-09-12 12:30:00','2014-09-12 15:30:00','2014-09-12 15:00:00', '2014-09-12 17:01:00','2014-09-12 18:00:00'])
cats = [1,1,1,2,2]
df = pd.DataFrame({'ts_beg':begs,'ts_end':ends,'category':cats})
df = timespans.merge_overlapping_events_kind(df,'ts_beg','ts_end',kind=['category'])
print('')
print('df=')
print(df)
print('')
print('add_time_between_events(df, \'ts_beg\', \'ts_end\', [\'category\'])=')
print(timespans.add_time_between_events(df,'ts_beg','ts_end',['category']))
print('')
print('Test add_time_between_events #2')
print('======================================')
begs = pd.to_datetime(['2014-09-12 12:00:00','2014-09-12 13:00:00','2014-09-12 14:00:00', '2014-09-12 15:00:00', '2014-09-12 22:00:00','2014-09-12 23:15:00','2014-09-12 23:46:00'])
ends = pd.to_datetime(['2014-09-12 12:30:00','2014-09-12 15:30:00','2014-09-12 15:00:00', '2014-09-12 16:00:00','2014-09-12 23:00:00','2014-09-12 23:16:00','2014-09-12 23:50:00'])
cats = [1,1,1,1,1,1,1]
subcats = [1,1,1,2,2,2,2]
df = pd.DataFrame({'ts_beg':begs,'ts_end':ends,'category':cats,'subcategory':subcats})
df = timespans.merge_overlapping_events_kind(df,'ts_beg','ts_end',kind=['category','subcategory'])
print('')
print('df=')
print(df)
print('')
print('add_time_between_events(df, \'ts_beg\', \'ts_end\', [\'category\',\'subcategory\'])=')
print(timespans.add_time_between_events(df,'ts_beg','ts_end',['category','subcategory']))
print('')
print('Done.')