DIY fertilizer mixer and plant watering machine https://www.xythobuz.de/giessomat.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

influx-export.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python
  2. from influxdb import InfluxDBClient
  3. from datetime import datetime
  4. import xlsxwriter
  5. # config
  6. host = '10.23.42.14'
  7. port = 8086
  8. user = 'root'
  9. password = 'root'
  10. dbname = 'giessomat'
  11. # data
  12. client = InfluxDBClient(host, port, user, password, dbname)
  13. print("Querying DB " + dbname + " on " + host)
  14. result = client.query('SELECT "id", "duration" FROM "plant";')
  15. #print("Result: {0}".format(result))
  16. data = list(result.get_points())
  17. print("Got " + str(len(data)) + " datapoints")
  18. #print(data)
  19. ids = list(set([ d['id'] for d in data ]))
  20. ids.sort()
  21. #ids = ['1']
  22. print("IDs found: " + str(ids))
  23. values = []
  24. times = []
  25. durations = []
  26. for id in ids:
  27. values.append([d for d in data if d['id'] == id])
  28. times.append([datetime.strptime(d['time'], '%Y-%m-%dT%H:%M:%S.%fZ') for d in data if d['id'] == id])
  29. durations.append([d['duration'] for d in data if d['id'] == id])
  30. workbook = xlsxwriter.Workbook('InfluxExport.xlsx')
  31. worksheet = workbook.add_worksheet()
  32. bold = workbook.add_format({'bold': 1})
  33. date_format = workbook.add_format({'num_format': 'dd.mm.yyyy hh:mm'})
  34. for i in range(len(ids)):
  35. worksheet.write_string(0, (i * 3) + 0, "ID", bold)
  36. worksheet.write_number(0, (i * 3) + 1, int(ids[i]))
  37. worksheet.write_string(1, (i * 3) + 0, "Time", bold)
  38. worksheet.set_column((i * 3) + 0, (i * 3) + 0, 20)
  39. for j in range(len(times[i])):
  40. worksheet.write_datetime(j + 2, (i * 3) + 0, times[i][j], date_format)
  41. worksheet.write_string(1, (i * 3) + 1, "Duration", bold)
  42. for j in range(len(durations[i])):
  43. worksheet.write_number(j + 2, (i * 3) + 1, durations[i][j])
  44. workbook.close()