def test_data():
    testSessions = []

    testSessions.append(Session(datetime.strptime('2020-04-01', '%Y-%m-%d')))

    exercises = []

    exercises.append(Exercise('Snatch', 'Snatch'))
    exercises.append(Exercise('Clean and Jerk', 'Clean and Jerk'))

    exercises[0].sets = [
        Set(3, 2, 1, 30),
        Set(1, 1, 0, 10),
        Set(2, 2, 0, 20),
        Set(3, 3, 0, 15)
    ]
    exercises[1].sets = [
        Set(3, 2, 1, 50),
        Set(3, 3, 0, 20),
        Set(3, 3, 0, 30),
        Set(3, 3, 0, 45)
    ]

    testSessions[0].addExercise(exercises[0])
    testSessions[0].addExercise(exercises[1])

    testSessions.append(Session(datetime.strptime('2020-05-01', '%Y-%m-%d')))
    testSessions[1].competition = True

    exercises = []

    exercises.append(Exercise('Snatch', 'Snatch'))
    exercises.append(Exercise('Clean and Jerk', 'Clean and Jerk'))

    exercises[0].sets = [
        Set(1, 0, 1, 50),
        Set(1, 1, 0, 50),
        Set(1, 1, 0, 40),
        Set(1, 1, 0, 30)
    ]
    exercises[1].sets = [
        Set(1, 0, 1, 70),
        Set(1, 1, 0, 60),
        Set(1, 1, 0, 50),
        Set(1, 1, 0, 40)
    ]

    testSessions[1].addExercise(exercises[0])
    testSessions[1].addExercise(exercises[1])

    return testSessions
Example #2
0
    def __init__(self, file: str):
        
        logging.debug('initialising DataReader... ')
        logging.debug('cwd: %s' % (os.getcwd()))
        self.file = file
        self.dataset = []
        self.sessions = {}
        self.dates = []

        with open(file, mode='r', newline='') as csv_file:
            self.reader = csv.reader(csv_file)

            for data in self.reader:
                self.dataset.append(data)

                # How about here, while we're reading in the data we translate and store in sessions. 
                if datetime.strptime(data[0], '%Y/%m/%d') in self.sessions:
                    # add this line to existing session
                    exercise = Exercise(data[1], data[5])

                    # Translate reps from this line
                    totalRepetitions, successfulRepetitions, failedRepetitions = self.translateRepetitions(data[2])
                    exercise.sets.append(Set(totalRepetitions, successfulRepetitions, failedRepetitions, int(data[3])))

                    # add exercise to this session
                    self.sessions[datetime.strptime(data[0], '%Y/%m/%d')].addExercise(exercise)

                else:
                    # add date to dates list and initialise the exercises list
                    self.dates.append(data[0])

                    # create new session
                    session = Session(datetime.strptime(data[0], '%Y/%m/%d'))
                    exercise = Exercise(data[1], data[5])

                    # Translate reps from this line
                    totalRepetitions, successfulRepetitions, failedRepetitions = self.translateRepetitions(data[2])
                    exercise.sets.append(Set(totalRepetitions, successfulRepetitions, failedRepetitions, int(data[3])))

                    # Add this exercise to this session, need to update addExercise to handle duplicates.
                    session.addExercise(exercise)

                    # Check if it's a competition session or not
                    if data[4] != '':
                        session.competition = True

                    self.sessions[datetime.strptime(data[0], '%Y/%m/%d')] = session

        logging.debug('DataReader initialised')
Example #3
0
class Test_Session():

    def setup_method(self):
        logging.info('Setting up before test... ')
        self.session = Session(datetime(2020, 4, 1))
        self.session.addExercise(Exercise('Snatch', 'Snatch'))

    def teardown_method(self):
        logging.info('Tearing down after test... ')
        self.session = None

    def test_session(self):
        expected = 'Snatch'
        result = self.session.exercises[0].name

        assert result == expected
    def translateData(self, dataset: list, repetitionTranslator):
        ''' Converts a list of csv data into a list of Session objects

        Parameters
        ----------
        dataset: a list

        Returns
        -------
        A list of Session objects
        '''
        logging.debug('translating data... ')

        dates = list(set([x[0] for x in dataset]))
        dates.sort()
        sessions = [
            Session(datetime.strptime(date, '%Y/%m/%d')) for date in dates
        ]

        for session in sessions:

            # Get all the exercises for this date
            uniqueExercisesForDate = list({
                data[1]: data
                for data in dataset
                if datetime.strptime(data[0], '%Y/%m/%d') == session.date
            }.values())

            # this sort of does nothing rn, I'm not sure sort on strings is alphabetical by default or not?
            uniqueExercisesForDate.sort(key=lambda x: x[1], reverse=True)

            # Add them to the sessions' exercise list
            session.exercises = [
                Exercise(exercise[1], exercise[5])
                for exercise in uniqueExercisesForDate
            ]

            for exercise in session.exercises:

                # Get all the sets for this session's date, for this exercise
                exerciseSets = [
                    data for data in dataset
                    if datetime.strptime(data[0], '%Y/%m/%d') == session.date
                    and data[1] == exercise.name
                ]

                # add set to the exercise for each row with this exercise and date
                for exerciseSet in exerciseSets:
                    totalRepetitions, successfulRepetitions, failedRepetitions = repetitionTranslator(
                        exerciseSet[2])
                    exercise.sets.append(
                        Set(totalRepetitions, successfulRepetitions,
                            failedRepetitions, int(exerciseSet[3])))

                    # while we're here, let's check if any sets have an attempt value, if so, mark this session as a competition one
                    if exerciseSet[4] != '':
                        session.competition = True

        logging.debug('data translated')
        return sessions
Example #5
0
 def setup_method(self):
     logging.info('Setting up before test... ')
     self.session = Session(datetime(2020, 4, 1))
     self.session.addExercise(Exercise('Snatch', 'Snatch'))