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.
 
 

118 lines
3.3 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.8"
  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. global curr_day
  26. curr_day = time.gmtime(1);
  27. for dat in rh['HistoryData']['CurrentSummation'] :
  28. print_currentsummation(dat)
  29. print "# day_delta_received={0:0.4f}\tday_delta_delivered={1:0.4f} : {2:0.4f}".format(
  30. day_delta_received,
  31. day_delta_delivered,
  32. (day_delta_delivered - day_delta_received))
  33. print "# max_delta_received={0:0.4f}\tmax_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.tm_mday != time_struct.tm_mday :
  67. curr_day = time_struct
  68. print "# {0} day_delta_received={1:0.4f}".format( \
  69. time.strftime("%a %Y-%m-%d", curr_day),
  70. day_delta_received) \
  71. + "\tday_delta_delivered={0:0.4f}".format(day_delta_delivered) \
  72. + " : {0:0.4f}".format((day_delta_delivered - day_delta_received))
  73. day_delta_received = 0
  74. day_delta_delivered = 0
  75. day_delta_received += delta_received
  76. day_delta_delivered += delta_delivered
  77. print "{0}\t{1:.4f}\t{2:0.4f}\t{3:.4f}\t{4:0.4f}".format(
  78. time.strftime("%Y-%m-%d %H:%M:%S", time_struct),
  79. reading_received,
  80. delta_received,
  81. reading_delivered,
  82. delta_delivered)
  83. if __name__ == "__main__":
  84. # import __main__
  85. # print(__main__.__file__)
  86. # print("syntax ok")
  87. reagle = RainEagle.Eagle(debug=0)
  88. main(reagle)
  89. exit(0)