From 039d2bf6890e8a764136b7148a421fd66ef89ad8 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Thu, 2 Jan 2020 00:34:11 -0800 Subject: [PATCH] add a program to generate bogus data --- fixtures/gendata.py | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 fixtures/gendata.py diff --git a/fixtures/gendata.py b/fixtures/gendata.py new file mode 100644 index 0000000..6b1b3f8 --- /dev/null +++ b/fixtures/gendata.py @@ -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)