def main(): initialized = False storage = None # Init the Concept2 # #ErgStats.connectToErg() #this waits for workouts to start, then stores them into a SQLite DB print("Waiting for workout to start...") while True: try: isActive = ErgStats.isWorkoutActive() except: print("Connecting to Ergometer...") ErgStats.connectToErg() time.sleep(1) continue if not isActive: if initialized: #this checks if workout was active before print("Workout ended...") ErgStats.resetStatistics() storage = None initialized = False else: if not initialized: print("Workout started...") storage = SQLiteStorage() initialized = True ErgStats.update() storage.storeState(ErgStats.time)
class BoatGhost(Boat): def __init__(self, name, filename, distance=0): super(BoatGhost, self).__init__(name, distance) self.storage = SQLiteStorage(filename) def move(self, timeGone): data = self.storage.getDataTuple(timeGone) if not data == None: self.distance = data[0] self.pace = data[2]
class Playground(): def __init__(self): self.boats = [] self.position = 0.0 self.storage = SQLiteStorage() #needed to store the current workout to file (needed for ghosting) def getCurrentPosition(self): return self.position def addBoat(self, boat): self.boats.append(boat) def getBoats(self): return self.boats def getPlayerBoat(self): return self.playerBoat def setPlayerBoat(self, boat): self.playerBoat = boat def reset(self): for boat in self.boats: boat.reset() self.playerBoat.reset() def update(self, timeGone): #move all the bots for boat in self.boats: boat.move(timeGone) #move the player self.playerBoat.move(timeGone) #store the current state into the storage self.storage.storeState(timeGone)
def __init__(self, name, filename, distance=0): super(BoatGhost, self).__init__(name, distance) self.storage = SQLiteStorage(filename)
def __init__(self): self.boats = [] self.position = 0.0 self.storage = SQLiteStorage() #needed to store the current workout to file (needed for ghosting)