+ self.client.serInit();
+
+ def glitchvoltages(self,time):
+ """Returns list of voltages to train at."""
+ c=self.db.cursor();
+ #c.execute("""select
+ # (select min(vcc) from glitches where time=? and count=1),
+ # (select max(vcc) from glitches where time=? and count=0);""",
+ # [time, time]);
+ c.execute("select min,max from glitchrange where time=? and max-min>0;",[time]);
+ rows=c.fetchall();
+ for r in rows:
+ min=r[0];
+ max=r[1];
+ if(min==None or max==None): return [];
+
+ spread=max-min;
+ return range(min,max,1);
+ #If we get here, there are no points. Return empty set.
+ return [];
+ def crunch(self):
+ """This builds tables for glitching voltage ranges from the training set."""
+ print "Precomputing glitching ranges. This might take a long while.";
+ print "Times...";
+ sys.stdout.flush();
+ self.db.execute("drop table if exists glitchrange;");
+ self.db.execute("create table glitchrange(time integer primary key asc,max,min);");
+ self.db.execute("insert into glitchrange(time,max,min) select distinct time, 0, 0 from glitches;");
+ self.db.commit();
+ print "Maximums...";
+ sys.stdout.flush();
+ self.db.execute("update glitchrange set max=(select max(vcc) from glitches where glitches.time=glitchrange.time and count=0);");
+ self.db.commit();
+ print "Minimums...";
+ sys.stdout.flush();
+ self.db.execute("update glitchrange set min=(select min(vcc) from glitches where glitches.time=glitchrange.time and count>0);");
+ self.db.commit();
+ print "Ranges calculated.";