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.
 
 

137 lines
3.6 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. import sys
  7. sys.path.append('/usr/home/shipley/Projects/Eagle') # temp
  8. import RainEagle
  9. import time
  10. from pprint import pprint
  11. from RainEagle import Eagle, to_epoch_1970
  12. import json
  13. last_delivered = 0
  14. last_received = 0
  15. max_delta_received = 0
  16. max_delta_delivered = 0
  17. day_delta_received = 0
  18. day_delta_delivered = 0
  19. curr_day=-1
  20. def main(eg) :
  21. # print_header()
  22. print_data(eg)
  23. # print_footer()
  24. exit(0)
  25. def print_header() :
  26. print """
  27. set terminal png size 2600,500
  28. set datafile separator "\t"
  29. set xlabel "time"
  30. set ylabel "power"
  31. set grid
  32. set key off
  33. set pointsize 0.5
  34. set xtics 3600
  35. set xdata time
  36. set timefmt "%Y-%m-%d %H:%M:%S"
  37. set format x "%a %b %d %H:%M"
  38. #set xrange [ "2014-03-04 00:00:00" : ]
  39. # set xrange [ "2014-03-04 00:00:00" : "2014-03-09 17:20:00" ]
  40. set style data lines
  41. set autoscale y
  42. set title "Power Use"
  43. set output "poweruse.png"
  44. plot "-" using 1:3 t "inbound" w lines, "-" using 1:5 t "outbound"
  45. """
  46. def print_footer() :
  47. pass
  48. def print_data(eg) :
  49. rh = eg.get_history_data()
  50. #+ # endtime=None, frequency=None ) :
  51. for dat in rh['HistoryData']['CurrentSummation'] :
  52. print_currentsummation(dat)
  53. print "# day_delta_received={0:0.4f}\tday_delta_delivered={1:0.4f} : {2:0.4f}".format(day_delta_received, day_delta_delivered, ( day_delta_delivered - day_delta_received ) )
  54. print "# max_delta_received={0:0.4f}\tmax_delta_delivered={1:0.4f}".format(max_delta_received, max_delta_delivered)
  55. def print_currentsummation(cs) :
  56. global last_delivered
  57. global last_received
  58. global max_delta_received
  59. global max_delta_delivered
  60. global day_delta_received
  61. global day_delta_delivered
  62. global curr_day
  63. time_stamp = to_epoch_1970(cs['TimeStamp'])
  64. multiplier=int(cs['Multiplier'], 16)
  65. divisor=int(cs['Divisor'], 16)
  66. delivered=int(cs['SummationDelivered'], 16)
  67. received=int(cs['SummationReceived'], 16)
  68. # print "Multiplier=", multiplier, "Divisor=", divisor, "Demand=", demand
  69. if multiplier == 0 :
  70. multiplier=1
  71. if divisor == 0 :
  72. divisor=1
  73. reading_received = received * multiplier / float (divisor )
  74. delta_received = (reading_received - last_received)
  75. last_received = reading_received
  76. if ( delta_received > max_delta_received and delta_received < 1000) :
  77. max_delta_received = delta_received
  78. #print "new max_delta_received :", max_delta_received
  79. reading_delivered = delivered * multiplier / float (divisor )
  80. delta_delivered = (reading_delivered - last_delivered)
  81. last_delivered = reading_delivered
  82. if ( delta_delivered > max_delta_delivered and delta_delivered < 1000) :
  83. max_delta_delivered = delta_delivered
  84. #print "\t\tnew max_delta_delivered :", max_delta_delivered
  85. time_struct = time.localtime(time_stamp)
  86. if curr_day != time_struct.tm_mday :
  87. curr_day = time_struct.tm_mday
  88. print "# day_delta_received={0:0.4f}\tday_delta_delivered={1:0.4f} : {2:0.4f}".format(day_delta_received, day_delta_delivered, ( day_delta_delivered - day_delta_received ) )
  89. day_delta_received = 0
  90. day_delta_delivered = 0
  91. day_delta_received += delta_received
  92. day_delta_delivered += delta_delivered
  93. print "{0}\t{1:.4f}\t{2:0.4f}\t{3:.4f}\t{4:0.4f}".format(
  94. time.strftime("%Y-%m-%d %H:%M:%S", time_struct),
  95. reading_received,
  96. delta_received,
  97. reading_delivered,
  98. delta_delivered)
  99. if __name__ == "__main__":
  100. # import __main__
  101. # print(__main__.__file__)
  102. # print("syntax ok")
  103. reagle = RainEagle.Eagle( debug=0 , addr="10.1.1.39")
  104. main(reagle)
  105. exit(0)