Esempio n. 1
0
    def save_ratings(self):
        """Saves ratings to disk """

        print('Saving ratings .. \n')
        ratings_file, prev_ratings_backup = get_ratings_path_info(self)

        if pexists(ratings_file):
            copyfile(ratings_file, prev_ratings_backup)

        # add column names: subject_id,issue1:issue2:issue3,...,notes etc
        # TODO add path(s) to data (images etc) that produced the review
        lines = '\n'.join([
            '{},{},{}'.format(sid, self._join_ratings(rating_set),
                              self.notes[sid])
            for sid, rating_set in self.ratings.items()
        ])
        try:
            with open(ratings_file, 'w') as cf:
                cf.write(lines)
        except:
            raise IOError('Error in saving ratings to file!!\n'
                          'Backup might be helpful at:\n\t{}'.format(
                              prev_ratings_backup))

        # summarize ratings to stdout and id lists
        summarize_ratings(ratings_file)
Esempio n. 2
0
    def restore_ratings(self):
        """Method to restore ratings from previous sessions, if any."""

        print('Restoring ratings from previous session(s), if they exist ..')

        # making a copy
        self.incomplete_list = list(self.id_list)
        prev_done = []  # empty list

        ratings_file, backup_name_ratings = get_ratings_path_info(self)

        if pexists(ratings_file):
            self.ratings, self.notes = load_ratings_csv(ratings_file)
            # finding the remaining
            prev_done = set(self.ratings.keys())
            self.incomplete_list = list(set(self.id_list) - prev_done)
        else:
            self.ratings = dict()
            self.notes = dict()

        if len(prev_done) > 0:
            print('\nRatings for {}/{} subjects were restored.'
                  ''.format(len(prev_done), len(self.id_list)))

        if len(self.incomplete_list) < 1:
            print('No subjects to review/rate - exiting.')
            sys.exit(0)
        else:
            self.num_units_to_review = len(self.incomplete_list)
            print('To be reviewed : {}\n'.format(self.num_units_to_review))