# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3.6
#     language: python
#     name: python36
# ---

# This program uses the srcomapi module to retrieve all speedruns of the No SBA category of the game SpongeBob SquarePants: Battle for Bikini Bottom, and then goes through those runs to find the world record, mean, and median times. In the future we will make this program accept user input to search for games and categories. It will also display the times in hours, minutes, and seconds instead of just seconds. Sadly, permission is denied to install the module on the terminal, so it has to be installed here.

# !pip install srcomapi

# +
import srcomapi, srcomapi.datatypes as dt
api = srcomapi.SpeedrunCom()
api.debug = 0

import statistics

print('done')
# -

api.search(srcomapi.datatypes.Game, {"name": "battle for bikini bottom"})

game = _[0]

game.categories

game_runs = {}
for category in game.categories:
    if not category.name in game_runs:
            game_runs[category.name] = {}
    if category.type == 'per-level':
        for level in game.levels:
            game_runs[category.name][level.name] = dt.Leaderboard(api, data=api.get("leaderboards/{}/level/{}/{}?embed=variables".format(game.id, level.id, category.id)))
    else:
        game_runs[category.name] = dt.Leaderboard(api, data=api.get("leaderboards/{}/category/{}?embed=variables".format(game.id, category.id)))
print('done')

# +
category_runs = game_runs['No SBA'].runs
run_times = []
num_runs = 0
for run in range(0,len(category_runs)):
    run_times.append(category_runs[run]['run'].times['primary_t'])
    num_runs = num_runs + 1

wr_time = category_runs[0]['run'].times['primary_t']
mean = round(statistics.mean(run_times))
median = round(statistics.median(run_times))

print('mean: ' , mean , 'seconds')
print('median: ' , median , 'seconds')
print('world record: ', wr_time, 'seconds')
# -





StarcoderdataJupyterScriptsDedupFiltered