|
| 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