forked from ukhas/habitat-payload-telemetry-stats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
habitat_payload_telemetry_stats.py
91 lines (63 loc) · 2.17 KB
/
habitat_payload_telemetry_stats.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
# Copyright (c) 2012 Daniel Richman. GNU GPL 3
# Views for habitat-payload-telemetry-stats
from strict_rfc3339 import rfc3339_to_timestamp
from couch_named_python import version
def _is_flight_telemetry(doc):
return doc['type'] == "payload_telemetry" and \
doc.get('data', {}).get('_parsed', {}).get('flight', False)
@version(1)
def receiver_map(doc):
"""
View: ``payload_telemetry_stats/receiver``
Emits::
receiver callsign -> 1
for every receiver of every payload_telemetry doc that belongs to a
flight (not a testing payload).
N.B.: reduce is "_sum" (Erlang)
"""
if not _is_flight_telemetry(doc):
return
for callsign in doc['receivers']:
yield callsign, 1
@version(1)
def flight_receiver_map(doc):
"""
View: ``payload_telemetry_stats/flight_receiver``
Emits::
[flight id, receiver callsign] -> 1
for every receiver of every payload_telemetry doc that belongs to a
flight (not a testing payload).
N.B.: reduce is "_sum" (Erlang)
"""
if not _is_flight_telemetry(doc):
return
for callsign in doc['receivers']:
yield (doc['data']['_parsed']['flight'], callsign), 1
@version(2)
def time_uploaded_day_map(doc):
"""
View: ``payload_telemetry_stats/time_uploaded_day``
Emits::
(time_created // (3600 * 24)) -> 1
for every receiver of every payload_telemetry doc that belongs to a
flight (not a testing payload).
N.B.: reduce is "_sum" (Erlang)
"""
if not _is_flight_telemetry(doc):
return
for info in doc['receivers'].itervalues():
t = rfc3339_to_timestamp(info["time_created"])
yield int(t // (3600 * 24)), 1
@version(1)
def launch_time_map(doc):
"""
View: ``payload_telemetry_stats/launch_time```
Emits::
launch_time -> {flight}
for every approved flight, where {flight} is a flight-like doc
containing only flight['name'] and flight['launch']['time']
"""
if doc['type'] == 'flight' and doc['approved']:
t = rfc3339_to_timestamp(doc['launch']['time'])
d = {"name": doc['name'], "launch": {"time": doc['launch']['time']}}
yield t, d