Example #1
0
 def set_statusbar(self):
     """Resets the application statusbar."""
     displayname = parse.get_profile_name(self.stats)
     lastplayed = parse.get_last_played(self.stats)
     status = 'Profile: {} // Last played: {}'.format(displayname,
                                                      lastplayed)
     self.setStatusTip(status)
Example #2
0
def report(stats, mode, difficulties, theme):
    """Prints the plain text report."""

    if stats is None:
        print("Error: Could not find a Stats.xml file")
        exit(1)

    displayname = parse.get_profile_name(stats)
    lastplayed = parse.get_last_played(stats)
    print("Profile name is " + displayname)
    print("Last played date was " + lastplayed)

    for song in stats.find("SongScores"):
        location = song.attrib['Dir'].split('/')
        title = location[2]
        group = location[1]
        print(group + " - " + title)

        step_counter = 0
        for diff in difficulties:
            # IndexError is raised after we reach the final <Step> on the song
            # using step_counter
            try:
                if (song[step_counter].attrib['Difficulty'] == diff and
                        song[step_counter].attrib['StepsType'] == mode):
                    try:
                        grade = smformat.highscore_grade(song[step_counter], theme)
                        percent = float(parse.highscore_stat(song[step_counter],
                                                             "PercentDP")) * 100
                        print('+++ {:10}: {:3} ({:.2f})'.format(diff, grade, percent))
                    except AttributeError:
                        print("--- " + diff)
                    step_counter = step_counter + 1
                else:
                    print("--- " + diff)
            except IndexError:
                print("--- " + diff)
Example #3
0
def generate(stats, mode, difficulties, theme):
    """Generates an HTML file with all the scores from the Stats file.

    Arguments:
    stats        -- an pre-rooted ElementTree of the Stats.xml file
                    (as in 'stats = etree.parse(statsxml).getroot()
    mode         -- the game mode to output scores from
    difficulties -- the difficulties which should be printed
    theme        -- which metrics should be used for printing grades
    """

    # Get profile name from tree
    profile_name = parse.get_profile_name(stats)
    last_played = parse.get_last_played(stats)

    songs = []
    song_tuple = namedtuple('Song', ['group', 'title', 'scores'])
    score_tuple = namedtuple('Score', ['diff', 'grade', 'perc', 'W1', 'W2',
                                       'W3', 'W4', 'W5', 'Miss'])

    for song in stats.find("SongScores"):
        location = song.attrib['Dir'].split('/')
        group = location[1]
        title = location[2]

        scores = []
        step_counter = 0
        for diff in difficulties:
            try:
                if song[step_counter].attrib['Difficulty'] == diff and \
                   song[step_counter].attrib['StepsType'] == mode:
                    try:
                        grade = smformat.highscore_grade(song[step_counter], theme)
                        percent = "{:.2f}%".format(float(parse.highscore_stat(
                            song[step_counter], "PercentDP")) * 100)
                        timings = parse.highscore_timings(song[step_counter])

                        scores.append(score_tuple(
                            diff=diff,
                            grade=grade,
                            perc=percent,
                            W1=timings['W1'],
                            W2=timings['W2'],
                            W3=timings['W3'],
                            W4=timings['W4'],
                            W5=timings['W5'],
                            Miss=timings['Miss']))

                    except AttributeError:
                        scores.append({'diff': diff})
                    step_counter = step_counter + 1
                else:
                    scores.append({'diff': diff})
            except IndexError:
                scores.append({'diff': diff})

        songs.append(song_tuple(group, title, scores))

    env = Environment(loader=PackageLoader('smtracker', 'templates'))
    template = env.get_template('template.html')
    return(template.render(name=profile_name,
                           last_played=last_played,
                           difficulties=difficulties,
                           songs=songs))