Mercurial > code > home > repos > homeauto
comparison lib/export_to_influxdb.py @ 1153:e4f49cd9dda3
add :pointsAtLeastEvery control
Ignore-this: 9d0236b56b2a7592211ca68b87b4a5d1
darcs-hash:76e4d358cb6b039351c9b6f8e3bb825aaaefcc57
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Sun, 15 Apr 2018 04:41:00 -0700 |
parents | eb36b30f53b9 |
children | b50a13ef20ba |
comparison
equal
deleted
inserted
replaced
1152:6d2eba4d0dfd | 1153:e4f49cd9dda3 |
---|---|
29 for t in graph.objects(meas, ROOM['tag']): | 29 for t in graph.objects(meas, ROOM['tag']): |
30 k = graph.value(t, ROOM['key']).toPython() | 30 k = graph.value(t, ROOM['key']).toPython() |
31 tags[k] = graph.value(t, ROOM['value']).toPython() | 31 tags[k] = graph.value(t, ROOM['value']).toPython() |
32 | 32 |
33 value = self.influxValue(stmt[2]) | 33 value = self.influxValue(stmt[2]) |
34 pale = 3600 | |
35 if graph.value(meas, ROOM['pointsAtLeastEvery'], default=None): | |
36 pale = graph.value(meas, ROOM['pointsAtLeastEvery']).toPython() | |
34 | 37 |
35 if not self.shouldSendNewPoint(now, stmt[0], measurementName, | 38 if not self.shouldSendNewPoint(now, stmt[0], measurementName, |
36 tags, value): | 39 tags, value, pointsAtLeastEvery=pale): |
37 continue | 40 continue |
38 | 41 |
39 points.append({ | 42 points.append({ |
40 'measurement': measurementName, | 43 'measurement': measurementName, |
41 "tags": tags, | 44 "tags": tags, |
55 value = rdfValue.toPython() | 58 value = rdfValue.toPython() |
56 if not isinstance(value, (int, float)): | 59 if not isinstance(value, (int, float)): |
57 raise NotImplementedError('value=%r' % value) | 60 raise NotImplementedError('value=%r' % value) |
58 return value | 61 return value |
59 | 62 |
60 def shouldSendNewPoint(self, now, subj, measurementName, tags, value): | 63 def shouldSendNewPoint(self, now, subj, measurementName, tags, value, pointsAtLeastEvery): |
61 key = (subj, measurementName, tuple(sorted(tags.items()))) | 64 key = (subj, measurementName, tuple(sorted(tags.items()))) |
62 if key in self.lastSent: | 65 if key in self.lastSent: |
63 lastTime, lastValue = self.lastSent[key] | 66 lastTime, lastValue = self.lastSent[key] |
64 if lastValue == value and lastTime > now - 3600: | 67 if lastValue == value and lastTime > now - pointsAtLeastEvery: |
65 log.debug('skip influx point %r', key) | 68 log.debug('skip influx point %r', key) |
66 return False | 69 return False |
67 | 70 |
68 self.lastSent[key] = (now, value) | 71 self.lastSent[key] = (now, value) |
69 return True | 72 return True |