update to json
This commit is contained in:
12
format.py
12
format.py
@@ -4,7 +4,7 @@ import pandas
|
|||||||
import numpy
|
import numpy
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from dateutil.relativedelta import *
|
from dateutil.relativedelta import *
|
||||||
|
import json
|
||||||
|
|
||||||
conn = sqlite3.connect("data.sqlite3")
|
conn = sqlite3.connect("data.sqlite3")
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
@@ -31,7 +31,7 @@ cur.execute("PRAGMA foreign_keys = ON;")
|
|||||||
categories = """CREATE TABLE IF NOT EXISTS categories(id INTEGER PRIMARY KEY AUTOINCREMENT , name TEXT)"""
|
categories = """CREATE TABLE IF NOT EXISTS categories(id INTEGER PRIMARY KEY AUTOINCREMENT , name TEXT)"""
|
||||||
subcat = """CREATE TABLE IF NOT EXISTS subcat(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, cat_id INTEGER, FOREIGN KEY(cat_id) REFERENCES categories(id))"""
|
subcat = """CREATE TABLE IF NOT EXISTS subcat(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, cat_id INTEGER, FOREIGN KEY(cat_id) REFERENCES categories(id))"""
|
||||||
location = """CREATE TABLE IF NOT EXISTS location(id INTEGER PRIMARY KEY AUTOINCREMENT , subdiv TEXT, LGA TEXT)"""
|
location = """CREATE TABLE IF NOT EXISTS location(id INTEGER PRIMARY KEY AUTOINCREMENT , subdiv TEXT, LGA TEXT)"""
|
||||||
stat = """CREATE TABLE IF NOT EXISTS statistics(id INTEGER PRIMARY KEY AUTOINCREMENT , category_id INTEGER, subcat_id INTEGER DEFAULT 0, location_id INTEGER, month TEXT NOT NULL, count INTEGER NOT NULL,FOREIGN KEY(category_id) REFERENCES categories(id), FOREIGN KEY(subcat_id) REFERENCES subcat(id), FOREIGN KEY(location_id) REFERENCES location(id))"""
|
stat = """CREATE TABLE IF NOT EXISTS statistics(id INTEGER PRIMARY KEY AUTOINCREMENT , category_id INTEGER, subcat_id INTEGER DEFAULT 0, location_id INTEGER, month TEXT NOT NULL, count TEXT NOT NULL,FOREIGN KEY(category_id) REFERENCES categories(id), FOREIGN KEY(subcat_id) REFERENCES subcat(id), FOREIGN KEY(location_id) REFERENCES location(id))"""
|
||||||
cur.execute(categories)
|
cur.execute(categories)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
cur.execute(subcat)
|
cur.execute(subcat)
|
||||||
@@ -73,11 +73,13 @@ for i in range(len(biglst)):
|
|||||||
subcatid = None
|
subcatid = None
|
||||||
init_date = numpy.datetime64('1995-01')
|
init_date = numpy.datetime64('1995-01')
|
||||||
init_lst = []
|
init_lst = []
|
||||||
|
dat_lst = []
|
||||||
for j in range(4,220):
|
for j in range(4,220):
|
||||||
|
|
||||||
#witchcraft datetime I hate it
|
#witchcraft datetime I hate it
|
||||||
init_lst.append({"cat_id": catid, "subcat_id": subcatid, "loc_id": locid, "mnth": pandas.to_datetime(str(init_date+numpy.timedelta64(j-4, 'M'))).strftime('%Y.%m'),"cnt":biglst[i][j]})
|
dat_lst.append(biglst[i][j])
|
||||||
|
|
||||||
|
|
||||||
|
init_lst.append({"cat_id": catid, "subcat_id": subcatid, "loc_id": locid, "mnth": pandas.to_datetime(str(init_date+numpy.timedelta64(j-4, 'M'))).strftime('%Y.%m'),"cnt":json.dumps(dat_lst)})
|
||||||
print(str(i))
|
print(str(i))
|
||||||
cur.executemany(stat_ins, init_lst)
|
cur.executemany(stat_ins, init_lst)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user