Exemplo n.º 1
0
 def getExercisesByAthleteName(self, athleteName):      
     connection = Database.connect(self)
     
     result = connection.execute("SELECT * FROM exercise WHERE athleteName = :athl_name", {"athl_name" :athleteName})
     return result.fetchall()
     
     
Exemplo n.º 2
0
 def countAthletes(self):
     connection = Database.connect(self)
     
     result = connection.execute("SELECT count(name) as 'athletes_count' FROM athlete")
     result = result.fetchone()
     
     return result['athletes_count']
Exemplo n.º 3
0
 def store(self, exercise):        
     connection = Database.connect(self)
                     
     connection.execute("INSERT INTO exercise VALUES (null, :athleteName, :date, :avgHeartRate)", 
                       {"athleteName":exercise._athleteName, "date":exercise._date, "avgHeartRate": exercise._averageHeartRate})
     
     connection.commit()
     connection.close()
Exemplo n.º 4
0
    def deletePushup(self, exerciseId):
        connection = Database.connect(self)
        
        connection.execute("DELETE FROM pushup WHERE exerciseId=:id ", {"id": exerciseId})
        connection.execute("DELETE FROM exercise WHERE id=:id",{"id": exerciseId})

        connection.commit()
        connection.close()
Exemplo n.º 5
0
    def countAthletes(self):
        connection = Database.connect(self)

        result = connection.execute(
            "SELECT count(name) as 'athletes_count' FROM athlete")
        result = result.fetchone()

        return result['athletes_count']
Exemplo n.º 6
0
 def delete(self, athleteName):
     database = Database.connect(self)
     pushupDatabase = Pushup_Foundation()
     pushupDatabase.deletePushupsByAthlete(athleteName)
                     
     database.execute("DELETE FROM athlete WHERE name=:name", {"name": athleteName})
     
     database.commit()
     database.close()        
Exemplo n.º 7
0
    def deletePushup(self, exerciseId):
        connection = Database.connect(self)

        connection.execute("DELETE FROM pushup WHERE exerciseId=:id ",
                           {"id": exerciseId})
        connection.execute("DELETE FROM exercise WHERE id=:id",
                           {"id": exerciseId})

        connection.commit()
        connection.close()
Exemplo n.º 8
0
    def delete(self, athleteName):
        database = Database.connect(self)
        pushupDatabase = Pushup_Foundation()
        pushupDatabase.deletePushupsByAthlete(athleteName)

        database.execute("DELETE FROM athlete WHERE name=:name",
                         {"name": athleteName})

        database.commit()
        database.close()
Exemplo n.º 9
0
 def getAthletes(self):
     connection = Database.connect(self)
     
     result = connection.execute("SELECT * FROM athlete")
     result = result.fetchall()
             
     athletesList = []
     for row in result :       
         athlete = self._createAthleteFromRow(row)      
         athletesList.append(athlete)
     
     return athletesList
Exemplo n.º 10
0
    def getAthletes(self):
        connection = Database.connect(self)

        result = connection.execute("SELECT * FROM athlete")
        result = result.fetchall()

        athletesList = []
        for row in result:
            athlete = self._createAthleteFromRow(row)
            athletesList.append(athlete)

        return athletesList
Exemplo n.º 11
0
 def store(self, athlete):    
     if self._nameAlreadyExists(athlete._name):
         print "Error: Name '" + athlete._name + "' already taken.\n" 
     else:
         database = Database.connect(self)
                 
         database.execute("INSERT INTO athlete VALUES (:name, :surname, :sex, :birthDate, :height, :mass)",
                          {"name": athlete._name, "surname": athlete._surname,
                           "sex":athlete._sex, "birthDate":athlete._birthDate,
                           "height":athlete._height, "mass":athlete._mass})
                
         database.commit()
         database.close()
Exemplo n.º 12
0
 def getAllPushups(self):
     connection = Database.connect(self)
     
     cursor = connection.execute("SELECT * FROM pushup inner join exercise on exerciseId=id")
     pushupRows = cursor.fetchall()
     #keys = pushupRows[0].keys() # useful to check row keys.
     
     pushupsList = []        
     
     for row in pushupRows:
         pushupObj = self._getPushupFromRow(row)
         pushupsList.append(pushupObj)   
     
     return pushupsList
Exemplo n.º 13
0
 def _nameAlreadyExists(self, name):
     connection = Database.connect(self)
     
     cursor = connection.execute("SELECT * FROM athlete WHERE name==:name", {"name": name})
     result = cursor.fetchall()
     
     if len(result) == 0:
         nameAlreadyExists = False
     else:
         nameAlreadyExists = True
     
     cursor.close()
     
     return nameAlreadyExists        
Exemplo n.º 14
0
 def getPushupsByAthlete(self, athleteName):
     connection = Database.connect(self)
     
     cursor = connection.execute("SELECT * FROM pushup inner join exercise on " +\
                                 "exerciseId=id WHERE athleteName = :name ORDER BY date",
                                 {"name":athleteName})
     
     pushupsList = []        
     pushupRows = cursor.fetchall()
     
     for row in pushupRows:
         pushupObj = self._getPushupFromRow(row)
         pushupsList.append(pushupObj) 
     
     return pushupsList
Exemplo n.º 15
0
    def _nameAlreadyExists(self, name):
        connection = Database.connect(self)

        cursor = connection.execute("SELECT * FROM athlete WHERE name==:name",
                                    {"name": name})
        result = cursor.fetchall()

        if len(result) == 0:
            nameAlreadyExists = False
        else:
            nameAlreadyExists = True

        cursor.close()

        return nameAlreadyExists
Exemplo n.º 16
0
    def getPushupsByAthlete(self, athleteName):
        connection = Database.connect(self)

        cursor = connection.execute("SELECT * FROM pushup inner join exercise on " +\
                                    "exerciseId=id WHERE athleteName = :name ORDER BY date",
                                    {"name":athleteName})

        pushupsList = []
        pushupRows = cursor.fetchall()

        for row in pushupRows:
            pushupObj = self._getPushupFromRow(row)
            pushupsList.append(pushupObj)

        return pushupsList
Exemplo n.º 17
0
    def getAllPushups(self):
        connection = Database.connect(self)

        cursor = connection.execute(
            "SELECT * FROM pushup inner join exercise on exerciseId=id")
        pushupRows = cursor.fetchall()
        #keys = pushupRows[0].keys() # useful to check row keys.

        pushupsList = []

        for row in pushupRows:
            pushupObj = self._getPushupFromRow(row)
            pushupsList.append(pushupObj)

        return pushupsList
Exemplo n.º 18
0
    def store(self, pushup):
        
        connection = Database.connect(self)
        
        connection.execute("INSERT INTO exercise VALUES (null, :athleteName, :date, :avgHeartRate)", 
                          {"athleteName":pushup._athleteName, "date":pushup._date, "avgHeartRate": pushup._averageHeartRate})
        
        cursor = connection.execute("SELECT max(id) as lastId FROM exercise")
        exerciseId = cursor.fetchone()["lastId"]
        

        connection.execute("INSERT INTO pushup VALUES(:exerciseId, :repetitions, :series)",
                           {"exerciseId":exerciseId, "repetitions":pushup._repetitions, "series":pushup._series})
         
        connection.commit()
        connection.close()
Exemplo n.º 19
0
 def load(self, athleteName):
     connection = Database.connect(self)
     
     result = connection.execute("SELECT * FROM athlete WHERE name=:searchParam",
                                 {"searchParam" :athleteName})
     result = result.fetchall()
     
     resultLength = len(result)
     
     if resultLength == 1:
         athlete = self._createAthleteFromRow(result[0])
     elif resultLength == 0:
         print "Error. No profile found for " + "'" + athleteName + "'"
         athlete = False
     elif resultLength > 1:
         print "Database corrupted. More than one tuple for the same Primary Key"
         athlete = False
           
     return athlete
Exemplo n.º 20
0
    def store(self, athlete):
        if self._nameAlreadyExists(athlete._name):
            print "Error: Name '" + athlete._name + "' already taken.\n"
        else:
            database = Database.connect(self)

            database.execute(
                "INSERT INTO athlete VALUES (:name, :surname, :sex, :birthDate, :height, :mass)",
                {
                    "name": athlete._name,
                    "surname": athlete._surname,
                    "sex": athlete._sex,
                    "birthDate": athlete._birthDate,
                    "height": athlete._height,
                    "mass": athlete._mass
                })

            database.commit()
            database.close()
Exemplo n.º 21
0
    def load(self, athleteName):
        connection = Database.connect(self)

        result = connection.execute(
            "SELECT * FROM athlete WHERE name=:searchParam",
            {"searchParam": athleteName})
        result = result.fetchall()

        resultLength = len(result)

        if resultLength == 1:
            athlete = self._createAthleteFromRow(result[0])
        elif resultLength == 0:
            print "Error. No profile found for " + "'" + athleteName + "'"
            athlete = False
        elif resultLength > 1:
            print "Database corrupted. More than one tuple for the same Primary Key"
            athlete = False

        return athlete
Exemplo n.º 22
0
    def store(self, pushup):

        connection = Database.connect(self)

        connection.execute(
            "INSERT INTO exercise VALUES (null, :athleteName, :date, :avgHeartRate)",
            {
                "athleteName": pushup._athleteName,
                "date": pushup._date,
                "avgHeartRate": pushup._averageHeartRate
            })

        cursor = connection.execute("SELECT max(id) as lastId FROM exercise")
        exerciseId = cursor.fetchone()["lastId"]

        connection.execute(
            "INSERT INTO pushup VALUES(:exerciseId, :repetitions, :series)", {
                "exerciseId": exerciseId,
                "repetitions": pushup._repetitions,
                "series": pushup._series
            })

        connection.commit()
        connection.close()