Example #1
0
	def sample(self) :
		print 'calling core sample'
		start = events.tick()
		value = self.perform_sample()
		duration = max(0, events.tick() - start)
		print 'duration was %d ms' % duration
		measure = self.trace.write(value).result()
		nextcall = max(0, measure.when_ms + self.period - duration)
		print 'running next at %d' % nextcall
		self.schedule(nextcall)
Example #2
0
	def _write(self, value) :
		"""
		Must tolerate tick_error_tolerate ms of drift.
		"""

		now_ms = events.tick()

		# when the last measurement should be, if we've had no timing or restart problems
		end_low = now_ms - self.tick_err_allowed_ms - self.tick_ms
		end_high = now_ms + self.tick_err_allowed_ms - self.tick_ms
		last_measurement = self.cursor.execute('select id,start_ms,end_ms,tick_ms,tick_err_allowed_ms,sample,sample_err_allowed from samples where end_ms <= ? and end_ms >= ? order by end_ms desc', (end_high, end_low)).fetchall()

		create = True
		if last_measurement :
			create = False
			
			id,start_ms,end_ms,tick_ms,tick_err_allowed_ms,sample,sample_err_allowed = last_measurement[0]

			create = create or tick_ms != self.tick_ms			
			create = create or tick_err_allowed_ms != self.tick_err_allowed_ms
			create = create or sample_err_allowed != self.sample_err_allowed
			create = create or value > sample + sample_err_allowed or value < sample - sample_err_allowed
		try :
			if create :
				self.cursor.execute('insert into samples (start_ms,end_ms,tick_ms,tick_err_allowed_ms,sample,sample_err_allowed) values (?,?,?,?,?,?)', (now_ms, now_ms, self.tick_ms, self.tick_err_allowed_ms, value, self.sample_err_allowed))
				return Tick(self, value, now_ms, now_ms, self.tick_ms, self.sample_err_allowed, self.tick_err_allowed_ms)
			else :
				at_ms = end_ms + tick_ms
				self.cursor.execute('update samples set end_ms = ? where id = ?', (at_ms, id))
				return Tick(self, value, start_ms, at_ms, self.tick_ms, self.sample_err_allowed, self.tick_err_allowed_ms)
		finally :
			self.conn.commit()
Example #3
0
import trace
import events

s = trace.Trace('test',"test.db", 5000, 1000, 0)
print s.read(events.tick()).result()
Example #4
0
	def schedule(self, tick=None) :
		if not tick :
			tick = events.tick()
		self.processor.add(events.SampleEvent(tick, self))
Example #5
0
import trace
import events
import pprint

s = trace.Trace("test", "test.db", 5000, 1000, 0)
now = events.tick()
for tick in s.read(now - 1000 * 3600, now).result():
    # pprint.pprint(tick.asdict)
    print tick
Example #6
0
import trace
import time
import events

s = trace.Trace("test", "test.db", 5000, 1000, 0)
s.write(1)
t = events.tick() + 300
time.sleep(2)
print s.read(t).result()
Example #7
0
                                         FULLSCREEN)

events.init()
asset.init()

pg.display.set_caption("A loo in the dark!")

currentDisplayScreen: Screen = TitleScreen()

clock = pg.time.Clock()

while True:
    for event in pg.event.get():
        if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
            pg.quit()
            sys.exit()
        if (type(currentDisplayScreen) == TitleScreen or type(currentDisplayScreen) == EndScreen) \
                and event.type == KEYDOWN and event.key == K_RETURN:
            currentDisplayScreen = GameScreen()

        if event.type == USEREVENT:
            events.tick()

    screen.fill((0, 0, 0))

    screenChange = currentDisplayScreen.draw(screen, clock)
    if screenChange:
        currentDisplayScreen = screenChange()

    pg.display.flip()