-
Notifications
You must be signed in to change notification settings - Fork 1
/
UpdateDatabase.py
66 lines (55 loc) · 2.33 KB
/
UpdateDatabase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import Options
"""
Input run_codes in study and create appropriate tables
"""
class UpdateDatabase(Options.ScenarioOptions):
def __init__(self, modelRunTitle):
Options.ScenarioOptions.__init__(self, modelRunTitle)
cur = self.conn.cursor()
# create schema, drop schema if it already existed
cur.execute("DROP SCHEMA IF EXISTS %s CASCADE" % (modelRunTitle))
cur.execute("CREATE SCHEMA %s" % (modelRunTitle))
self.conn.commit()
def createTables(self, feedstock):
# create tables (based on feedstock)
# TODO: Insert Primary Keys
query = """
CREATE TABLE %s_raw
(
FIPS char(5) ,
SCC char(10) ,
HP int ,
fuel_consumption float ,
THC float ,
VOC float ,
CO float ,
NOx float ,
CO2 float ,
SOx float ,
PM10 float ,
PM25 float ,
NH3 float ,
Description text ,
run_code text ,
fug_pm10 float ,
fug_pm25 float)""" % (feedstock)
self.__executeQuery__(query)
if feedstock != 'FR':
query = """
CREATE TABLE %s_NFert
(
FIPS char(5) ,
NOx float ,
NH3 float ,
SCC char(10) ,
description text)""" % (feedstock)
self.__executeQuery__(query)
if feedstock == 'SG' or feedstock == 'CG':
query = """
CREATE TABLE %s_CHEM
(
FIPS char(5),
SCC char(10) ,
VOC float ,
description text)""" % (feedstock)
self.__executeQuery__(query)