1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 from collections import namedtuple
21 from operator import attrgetter
22
23 import kenozooid.util as ku
24
26 """
27 Create a named tuple with all fields set to ``None`` by default.
28
29 :Parameters:
30 name
31 Name of tuple.
32 fields
33 String containing space separated list of field names.
34 """
35 t = namedtuple(name, fields)
36 k = len(t._fields)
37 df = k * (None, )
38 dt = t(*df)
39 return dt._replace
40
41
42 Dive = ntuple('Dive', 'number datetime depth duration temp avg_depth mode profile' \
43 ' equipment')
44 Sample = ntuple('Sample', 'depth time temp setpoint setpointby' \
45 ' deco_time deco_depth alarm gas')
46 Gas = ntuple('Gas', 'id name o2 he depth')
47 BinaryData = ntuple('BinaryData', 'datetime data')
48
49
50 -def gas(o2, he, depth=0):
51 """
52 Convert oxygen and helium values into Gas data record with id and name.
53 """
54 id = 'air'
55 name = 'Air'
56 if o2 == 100:
57 id = 'o2'
58 name = 'O2'
59 elif o2 > 21 and he == 0:
60 id = 'ean{:02d}'.format(o2)
61 name = 'EAN{:02d}'.format(o2)
62 elif he > 0:
63 id = 'tx{:02d}{:02d}'.format(o2, he)
64 name = 'TX {:02d}/{:02d}'.format(o2, he)
65 return Gas(id=id, name=name, o2=o2, he=he, depth=depth)
66
67
69 """
70 Sort dives by dive datetime.
71 """
72 return sorted(dives, key=attrgetter('datetime'))
73
74
76 """
77 Remove duplicated dives from sorted iterator of dives.
78 """
79 ld = None
80 for d in dives:
81 if ld != d.datetime:
82 yield d
83 ld = d.datetime
84
85
86