Created
May 28, 2017 02:12
-
-
Save zopyx/16e772facbdd91a2ea2d73d7d9ba204f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import random | |
import psycopg2 | |
import pdb; pdb.set_trace() | |
conn = psycopg2.connect(database='foo', user='root', host='localhost', port=26257) | |
cursor = conn.cursor() | |
cursor.execute('create table series(created timestamp, unit text, unit2 text, measurement text, ym text, value int)') | |
result = list() | |
count =0 | |
for yr in range(1970, 2021): | |
ref_date = datetime.datetime(yr, 1, 1) | |
print(yr) | |
for day in range(0, 365): | |
for hour in range(0, 24): | |
dt = ref_date + datetime.timedelta(days=day, hours=hour) | |
ym = "{}-{}".format(dt.year, dt.month) | |
for m in ('gas', 'strom'): | |
for unit in range(4): | |
for unit2 in range(5): | |
value = random.randint(10, 30) | |
created = dt.isoformat() | |
cmd = "insert into series(created, unit, unit2, measurement, ym, value) values('{}', '{}', '{}', '{}', '{}', {})".format(created, unit, unit2, m, ym, value) | |
cursor.execute(cmd) | |
count += 1 | |
print(count) | |
conn.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment