123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- demeter database
- name:data.py
- author:rabin
- """
- from base import Base
- class Data(Base):
- __table__ = 'data'
- def setTable(self, data):
- self.table = self.__table__ + '_' + data['farm'] + '_' + data['device']
- def insert(self, data):
- self.setTable(data)
- json = self.insert_json(data)
- self.db.write_points(json)
- self.select()
- def insert_json(self, data):
- json = [
- {
- "measurement": self.table,
- "tags": {
- "hard": data['hard'],
- "type":data['type'],
- "gateway": data['gateway']
- },
- #"time": data['time'],
- "fields": {
- 'source' : data['source'],
- 'value' : data['value']
- }
- }]
- return json
- def select(self, data):
- self.setTable(data)
- result = self.db.query('select * from ' + self.table)
- print("Result: {0}".format(result))
|