RainEagle library plus script for polling data
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.
 
 

115 lines
3.2 KiB

  1. #!/usr/local/bin/python2.7
  2. """
  3. A simple script to generate guuplot data from meter history
  4. """
  5. __author__ = "Peter Shipley"
  6. __version__ = "0.1.7"
  7. import RainEagle
  8. import time
  9. from pprint import pprint
  10. from RainEagle import Eagle, to_epoch_1970
  11. import json
  12. last_delivered = 0
  13. last_received = 0
  14. max_delta_received = 0
  15. max_delta_delivered = 0
  16. day_delta_received = 0
  17. day_delta_delivered = 0
  18. curr_day = -1
  19. def main(eg) :
  20. print_data(eg)
  21. exit(0)
  22. def print_data(eg) :
  23. rh = eg.get_history_data()
  24. #+ # endtime=None, frequency=None) :
  25. for dat in rh['HistoryData']['CurrentSummation'] :
  26. print_currentsummation(dat)
  27. print "# day_delta_received={0:0.4f}\t" \
  28. + " day_delta_delivered={1:0.4f} : {2:0.4f}".format(
  29. day_delta_received,
  30. day_delta_delivered,
  31. (day_delta_delivered - day_delta_received))
  32. print "# max_delta_received={0:0.4f}\t" \
  33. + " max_delta_delivered={1:0.4f}".format(
  34. max_delta_received, max_delta_delivered)
  35. def print_currentsummation(cs) :
  36. global last_delivered
  37. global last_received
  38. global max_delta_received
  39. global max_delta_delivered
  40. global day_delta_received
  41. global day_delta_delivered
  42. global curr_day
  43. time_stamp = to_epoch_1970(cs['TimeStamp'])
  44. multiplier = int(cs['Multiplier'], 16)
  45. divisor = int(cs['Divisor'], 16)
  46. delivered = int(cs['SummationDelivered'], 16)
  47. received = int(cs['SummationReceived'], 16)
  48. # print "Multiplier=", multiplier, "Divisor=", divisor, "Demand=", demand
  49. if multiplier == 0 :
  50. multiplier = 1
  51. if divisor == 0 :
  52. divisor = 1
  53. reading_received = received * multiplier / float(divisor)
  54. delta_received = (reading_received - last_received)
  55. last_received = reading_received
  56. if (delta_received > max_delta_received and delta_received < 1000) :
  57. max_delta_received = delta_received
  58. #print "new max_delta_received :", max_delta_received
  59. reading_delivered = delivered * multiplier / float(divisor)
  60. delta_delivered = (reading_delivered - last_delivered)
  61. last_delivered = reading_delivered
  62. if (delta_delivered > max_delta_delivered and delta_delivered < 1000) :
  63. max_delta_delivered = delta_delivered
  64. #print "\t\tnew max_delta_delivered :", max_delta_delivered
  65. time_struct = time.localtime(time_stamp)
  66. if curr_day != time_struct.tm_mday :
  67. curr_day = time_struct.tm_mday
  68. print "# day_delta_received={0:0.4f}\tday_delta_delivered={1:0.4f}" \
  69. + ": {2:0.4f}".format(day_delta_received,
  70. day_delta_delivered,
  71. (day_delta_delivered - day_delta_received))
  72. day_delta_received = 0
  73. day_delta_delivered = 0
  74. day_delta_received += delta_received
  75. day_delta_delivered += delta_delivered
  76. print "{0}\t{1:.4f}\t{2:0.4f}\t{3:.4f}\t{4:0.4f}".format(
  77. time.strftime("%Y-%m-%d %H:%M:%S", time_struct),
  78. reading_received,
  79. delta_received,
  80. reading_delivered,
  81. delta_delivered)
  82. if __name__ == "__main__":
  83. # import __main__
  84. # print(__main__.__file__)
  85. # print("syntax ok")
  86. reagle = RainEagle.Eagle(debug=0)
  87. main(reagle)
  88. exit(0)