-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImportBehaviors.py
68 lines (58 loc) · 1.31 KB
/
ImportBehaviors.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
import sqlite3 as lite
import csv
def main():
filename = "PredatorPreyAlphaGammaChi-find_cyles-table.csv"
dbname = "PredatorPreyAlphaGammaChi-find_cyles.db"
createDB(dbname)
f = open(filename).readlines()
f = f[7:]
reader = csv.reader(f, delimiter=',')
insertDB(dbname, reader)
print "All data imported"
def insertDB(dbname, reader):
conn = lite.connect(dbname, isolation_level=None)
c = conn.cursor()
sql = """ INSERT INTO Cycles
(
RunNumber,
alpha,
gamma,
initRabbits,
initFoxes,
steps,
countRabbits,
countFoxes,
hash)
VALUES (?,?,?,?,?,?,?,?,?)
"""
for row in reader:
h = str(row[1])+'-'+str(row[2])+'-'+str(row[3])+'-'+str(row[4])
row.append(h)
#print row
c.execute(sql,row)
conn.commit()
conn.close()
def createDB(dbname):
conn = lite.connect(dbname, isolation_level=None)
c = conn.cursor()
c.execute("DROP TABLE IF EXISTS Cycles")
createTableCycles = """
CREATE TABLE Cycles
(
Id INTEGER PRIMARY KEY AUTOINCREMENT,
RunNumber INTEGER,
alpha REAL,
gamma REAL,
initRabbits INTEGER,
initFoxes INTEGER,
steps INTEGER,
countRabbits INTEGER,
countFoxes INTEGER,
hash VARCHAR
)
"""
c.execute(createTableCycles)
conn.commit()
conn.close()
if __name__ == '__main__':
main()