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.
 
 

67 lines
1.4 KiB

  1. from random import Random
  2. gmt7 = ('GMT+7', '-0700', lambda x: x - 7 * 60 * 60)
  3. gmt8 = ('GMT+8', '-0800', lambda x: x - 8 * 60 * 60)
  4. def maketz(utc, tzinfo):
  5. tza, tzb, fun = tzinfo
  6. lcl = fun(utc)
  7. return '\t'.join(('z', tza, str(lcl), str(utc), tzb))
  8. def makem(utc, tzinfo):
  9. reqdel = random.uniform(.5, 2.5)
  10. demand = random.uniform(.1, .5)
  11. return '\t'.join(('m', str(utc + reqdel), str(tzinfo[2](utc)), 'Connected', '%0.4f' % demand, '1.483000', 'kW', '1.000', '1.000', 'kWh'))
  12. def gen(start, step, cnt, tzinfoseq):
  13. '''Generate data starting from start, ending at stop.
  14. Each entry is step seconds advanced.
  15. There will be cnt entries between tzinfo, and cnt entries
  16. following the final tzinfo.'''
  17. utc = start
  18. ret = []
  19. num = 1
  20. prevtz = None
  21. for tz in tzinfoseq:
  22. if prevtz is None:
  23. prevtz = tz
  24. for j in xrange(num):
  25. ret.append(makem(utc, prevtz))
  26. utc += step
  27. if prevtz != tz and j > num / 2:
  28. prevtz = tz
  29. ret.append(maketz(utc - 1, tz))
  30. num = cnt
  31. for j in xrange(num):
  32. ret.append(makem(utc, tz))
  33. utc += step
  34. return utc, ret
  35. if __name__ == '__main__':
  36. global random
  37. random = Random()
  38. random.seed(5)
  39. tzs = [ gmt7 ] * 6 + [ gmt8 ] * 3
  40. nextutc, data = gen(1577952662, 10, 10, tzs)
  41. print >>open('data.0.log', 'w'), '\n'.join(data)
  42. # simulate a restart
  43. nextutc += 100
  44. tzs = [ gmt8 ] * 6 + [ gmt7 ] * 3
  45. nextutc, data = gen(nextutc, 10, 10, tzs)
  46. print >>open('data.1.log', 'w'), '\n'.join(data)