| @@ -0,0 +1,66 @@ | |||||
| from random import Random | |||||
| gmt7 = ('GMT+7', '-0700', lambda x: x - 7 * 60 * 60) | |||||
| gmt8 = ('GMT+8', '-0800', lambda x: x - 8 * 60 * 60) | |||||
| def maketz(utc, tzinfo): | |||||
| tza, tzb, fun = tzinfo | |||||
| lcl = fun(utc) | |||||
| return '\t'.join(('z', tza, str(lcl), str(utc), tzb)) | |||||
| def makem(utc, tzinfo): | |||||
| reqdel = random.uniform(.5, 2.5) | |||||
| demand = random.uniform(.1, .5) | |||||
| return '\t'.join(('m', str(utc + reqdel), str(tzinfo[2](utc)), 'Connected', '%0.4f' % demand, '1.483000', 'kW', '1.000', '1.000', 'kWh')) | |||||
| def gen(start, step, cnt, tzinfoseq): | |||||
| '''Generate data starting from start, ending at stop. | |||||
| Each entry is step seconds advanced. | |||||
| There will be cnt entries between tzinfo, and cnt entries | |||||
| following the final tzinfo.''' | |||||
| utc = start | |||||
| ret = [] | |||||
| num = 1 | |||||
| prevtz = None | |||||
| for tz in tzinfoseq: | |||||
| if prevtz is None: | |||||
| prevtz = tz | |||||
| for j in xrange(num): | |||||
| ret.append(makem(utc, prevtz)) | |||||
| utc += step | |||||
| if prevtz != tz and j > num / 2: | |||||
| prevtz = tz | |||||
| ret.append(maketz(utc - 1, tz)) | |||||
| num = cnt | |||||
| for j in xrange(num): | |||||
| ret.append(makem(utc, tz)) | |||||
| utc += step | |||||
| return utc, ret | |||||
| if __name__ == '__main__': | |||||
| global random | |||||
| random = Random() | |||||
| random.seed(5) | |||||
| tzs = [ gmt7 ] * 6 + [ gmt8 ] * 3 | |||||
| nextutc, data = gen(1577952662, 10, 10, tzs) | |||||
| print >>open('data.0.log', 'w'), '\n'.join(data) | |||||
| # simulate a restart | |||||
| nextutc += 100 | |||||
| tzs = [ gmt8 ] * 6 + [ gmt7 ] * 3 | |||||
| nextutc, data = gen(nextutc, 10, 10, tzs) | |||||
| print >>open('data.1.log', 'w'), '\n'.join(data) | |||||