aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/docs/sessions.md
blob: 882f010e31aa3203f6adcb952edd1eb308cd15b3 (plain) (blame)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
vk-sessions
===========

View/visualize the amount of time people spend online.

Usage
-----

```
> vk-sessions -h
usage: vk-sessions [-h] [-g {user,date,weekday,hour}] [-i {csv,log,null}]
                   [-o {csv,json,plot}] [-a TIME_FROM] [-b TIME_TO]
                   [input] [output]
```

This script additionally requires [matplotlib] to be installed.

Analyze the database produced by [vk-status] and calculate the total amount of
time people spent online.
For example (assuming the database in "db.csv" was generated by [vk-status]
before):

```
> vk-sessions db.csv
89497105,John,Smith,john.smith,0:12:31
3698577,Jane,Smith,jane.smith,1:34:46
```

In the example above, "John Smith" and "Jane Smith" spent approx. 13 and 95
minutes online respectively.

The output format is CSV (comma-separated values) by default.
You can also get a JSON document:

```
> vk-sessions --output-format json db.csv
[
   {
      "uid": 89497105,
      "first_name": "John",
      "last_name": "Smith",
      "domain": "john.smith",
      "duration": "0:12:31"
   },
   {
      "uid": 3698577,
      "first_name": "Jane",
      "last_name": "Smith",
      "domain": "jane.smith",
      "duration": "1:34:46"
   }
]
```

The durations are calculated on a per-user basis by default.
You can change that by supplying either `date` (to group by dates), `weekday`
(to group by weekdays) or `hour` (to group by day hours) as the `--group-by`
parameter value.
For example (assuming that both Jane and Joe spent their time online on Friday,
June 17, 2016).

```
> vk-sessions --output-format json --group-by date db.csv
[
   {
      "date": "2016-06-17",
      "duration": "1:47:17"
   }
]
```

```
> vk-sessions --output-format csv --group-by weekday db.csv
Monday,0:00:00
Tuesday,0:00:00
Wednesday,0:00:00
Thursday,0:00:00
Friday,1:47:17
Saturday,0:00:00
Sunday,0:00:00
```

```
> vk-sessions --group-by hour db.csv
0:00:00,0:00:00
1:00:00,0:00:00
2:00:00,0:00:00
3:00:00,0:00:00
4:00:00,0:03:56
5:00:00,0:14:14
6:00:00,0:29:30
7:00:00,0:31:20
8:00:00,0:12:04
9:00:00,0:00:00
10:00:00,0:00:00
11:00:00,0:23:14
12:00:00,0:06:00
13:00:00,0:46:19
14:00:00,0:00:00
15:00:00,0:00:00
16:00:00,0:00:00
17:00:00,0:00:00
18:00:00,0:00:00
19:00:00,0:00:00
20:00:00,0:00:00
21:00:00,0:00:00
22:00:00,0:00:00
23:00:00,0:00:00
```

In my opinion, the script's most useful feature is its ability to easily create
plots that represent this data (like in the examples above).
To produce a plot, pass `plot` as the `--output-format` parameter value and add
a file path to write the image to.

```
> vk-sessions --output-format plot db.csv user.png
```

![user.png]

```
> vk-sessions --output-format plot --group-by date db.csv date.png
```

![date.png]

```
> vk-sessions --output-format plot --group-by weekday db.csv weekday.png
```

![weekday.png]

```
> vk-sessions --output-format plot --group-by hour db.csv hour.png
```

![hour.png]

You can limit the scope of the database by supplying a time range.
Only online sessions that overlap with this range shall then be processed.
Set the range by specifying both or one of the `--from` and `--to` parameters.
The values must be in the `%Y-%m-%dT%H:%M:%SZ` format (a subset of ISO 8601).

All dates and times are in UTC.

[matplotlib]: http://matplotlib.org/
[vk-status]: status.md

[user.png]: images/user.png
[date.png]: images/date.png
[weekday.png]: images/weekday.png
[hour.png]: images/hour.png

Known issues
------------

* When people go online using the web version and don't visit other pages over
time (for example, just listening to music), they appear offline.
Hence the 0:00:00 durations you might sometimes encounter.
This might also happen using other clients.

See also
--------

* [License]

[License]: ../README.md#license