-
Notifications
You must be signed in to change notification settings - Fork 3
/
database.py
105 lines (87 loc) · 2.34 KB
/
database.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""#
# Module to initialize Sqlite Database.
#"""
#imports
import sqlite3
#global variables
database = "memory.sql"
def initInputs(conn, curs):
#initialize the inputs table and insert default values
inputs = (
(1, "['goodbye', 'sayonara']", 'Are you going away for a while?', 1),
(2, "['goodbye']", 'Should I go to sleep now?', 1)
)
curs.execute (
"""CREATE TABLE IF NOT EXISTS
inputs (
id INTEGER PRIMARY KEY,
input BLOB,
clarification TEXT,
output_id INTEGER
)"""
)
curs.executemany (
"""REPLACE INTO inputs VALUES (
?, ?, ?, ?
)""", inputs
)
conn.commit()
def initOutputs(conn, curs):
#initialize the outputs table and insert default values
outputs = (
(1, 1, 1, "['Goodbye!', 'See you later!', 'Goodnight!']"),
)
curs.execute (
"""CREATE TABLE IF NOT EXISTS
outputs (
id INTEGER PRIMARY KEY,
mood INTEGER,
action INTEGER,
output TEXT
)"""
)
curs.executemany (
"""REPLACE INTO outputs VALUES (
?, ?, ?, ?
)""", outputs
)
conn.commit()
def initInteractions(conn, curs):
#initialize the interactions table
curs.execute (
"""CREATE TABLE IF NOT EXISTS
interactions (
id INTEGER PRIMARY KEY,
start_time TIMESTAMP,
stop_time TIMESTAMP,
duration REAL,
type INTEGER
)"""
)
conn.commit()
def initInteractionTypes(conn, curs):
#initialize the interaction_types table and insert default values
interactions = (
(1, 1, 'General Interaction'),
)
curs.execute(
"""CREATE TABLE IF NOT EXISTS
interaction_types (
id INTEGER PRIMARY KEY,
interaction_id INTEGER,
description TEXT
)"""
)
curs.executemany (
"""REPLACE INTO interaction_types VALUES (
?, ?, ?
)""", interactions
)
conn.commit()
if __name__ == "__main__":
conn = sqlite3.connect(database)
curs = conn.cursor()
initInputs(conn, curs)
initOutputs(conn, curs)
initInteractions(conn, curs)
initInteractionTypes(conn, curs)