Skip to content

Commit 914d51a

Browse files
committed
amalgamation
1 parent eb985d7 commit 914d51a

File tree

3 files changed

+62
-9
lines changed

3 files changed

+62
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*~
22
*.pyc
3+
*.sqlite

oncampus.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
# draw : whetheer it would be a good idea to try to plot graphs to the screen. This will be false if you are offcampus or are using SSH without X forwarding
55
import os, subprocess, string
66

7-
if "STY" in os.environ or "TMUX" in os.environ: #we are inside gnu screen or tmux
8-
#It's not obvious what behaviour is correct in this case - same session can be used in multiple places.
9-
#Simplest is to treat this as off campus.
10-
#When on campus just do graphing in another terminal.
11-
oncampus = False
12-
elif "SSH_CLIENT" in os.environ:
13-
oncampus = -1 < subprocess.check_output(["who", "-m"]).find(b"warwick")
7+
if os.name=="posix":
8+
if "STY" in os.environ or "TMUX" in os.environ: #we are inside gnu screen or tmux
9+
#It's not obvious what behaviour is correct in this case - same session can be used in multiple places.
10+
#Simplest is to treat this as off campus.
11+
#When on campus just do graphing in another terminal.
12+
oncampus = False
13+
elif "SSH_CLIENT" in os.environ:
14+
oncampus = -1 < subprocess.check_output(["who", "-m"]).find(b"warwick")
15+
else:
16+
oncampus = True
17+
18+
draw = oncampus and "DISPLAY" in os.environ
1419
else:
20+
#You are probably sitting at your machine
21+
draw = True
1522
oncampus = True
16-
17-
draw = oncampus and "DISPLAY" in os.environ

results/amalgamateResults.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import sys
2+
import os
3+
import sqlite3
4+
#Creates a file resultsAmalgam.sqlite which is an amalgamation of all the results files named on the command line
5+
#at the moment, assume they are are all new format
6+
filename = "resultsAmalgam.sqlite"
7+
if os.path.isfile(filename):
8+
raise RuntimeError("file "+filename+" already exists")
9+
10+
con = sqlite3.connect(filename)
11+
c=con.cursor()
12+
13+
if not os.path.isfile(sys.argv[1]):
14+
raise RuntimeError("no file "+sys.argv[1])
15+
c.execute("attach ? as o",(sys.argv[1],))
16+
runColList="(COUNT INTEGER PRIMARY KEY, TIME TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL, CONTINUATION TEXT, ARCHITECTURE TEXT, SOLVER TEXT, CODE TEXT)"
17+
setup=["create table if not exists RUNS"+runColList,#these default keys start at 1
18+
"create table if not exists STEPS(STEP INTEGER PRIMARY KEY, RUN int, OBJECTIVE real, TRAINACC real, TESTOBJECTIVE real, TESTACC REAL )",
19+
"create table if not exists TIMES(RUN INT, TIME real)", # stores the time of the tenth step of each run, allowing speed to be measured
20+
"create table if not exists ATTRIBS(RUN INT, NAME TEXT, ISRESULT INT, VALUE TEXT)"
21+
]
22+
for s in setup:
23+
c.execute(s)
24+
25+
print (sys.argv[1])
26+
c.execute("insert into RUNS SELECT * FROM o.RUNS") #Thus proving the DB is new format
27+
nrun=c.lastrowid
28+
c.execute("insert into STEPS SELECT * FROM o.STEPS")
29+
c.execute("insert into TIMES SELECT * FROM o.TIMES")
30+
c.execute("insert into ATTRIBS SELECT * FROM o.ATTRIBS")
31+
c.execute("detach o")
32+
33+
for t in sys.argv[2:]:
34+
if not os.path.isfile(t):
35+
raise RuntimeError("no file "+t)
36+
c.execute("attach ? as o",(t,))
37+
if c.execute("select sql like '%LAYERTYPE%' from sqlite_master where tbl_name='RUNS'").fetchone()[0]:
38+
raise RuntimeError(t + " has old columns, can't deal with it here")
39+
print (t)
40+
c.execute("insert into RUNS SELECT COUNT+?,TIME,CONTINUATION,ARCHITECTURE,SOLVER,CODE FROM o.RUNS",(nrun,))
41+
next_nrun=c.lastrowid
42+
c.execute("insert into STEPS(RUN,OBJECTIVE,TRAINACC,TESTOBJECTIVE,TESTACC) SELECT RUN+?,OBJECTIVE,TRAINACC,TESTOBJECTIVE,TESTACC FROM O.STEPS",(nrun,))
43+
c.execute("insert into TIMES select RUN+?, TIME FROM O.TIMES",(nrun,))
44+
c.execute("insert into ATTRIBS SELECT RUN+?, NAME, ISRESULT, VALUE FROM O.ATTRIBS",(nrun,))
45+
nrun=next_nrun
46+
c.execute("detach o")
47+

0 commit comments

Comments
 (0)