generals.io User Stats: A New Streamlit App

Selim Yaman
3 min readApr 30, 2023

I present to you, ladies and gentleman, my newest Python-based web app: https://generalsio.streamlit.app/

Please visit the website, play with it, and tell me what you think, what to improve. And no, I’m not making any money.

A little bit backstory:

I confess, I am addicted to this fast-paced strategy game, generals.io.

“It will only take a couple of minutes”, I tell myself, every time I get stuck in a research project. Sometimes it really takes only a couple of minutes, hell even seconds; but other times, it doesn’t. One game follows another.

So in my spare time, I wanted to make a web app where we the visitors can just see their favorite user’s game stats. How many times this user has won? Does the user play generals.io mostly days vs. nights? How about rank, and stars? Who are your arch enemies? etc. etc.

Long story short, here is the website:

User Stats

I am still developing the app — so if you see a bug or an idea, just let me know!

The first graph you’re seeing, the calendar heatmap, is my favourite. It’s like the Github app, but for the games played. Let me show you the code for that plot:

with st.container():
c1, c2, c3 = st.columns([1, 2, 1])
# Count the number of games played per day
daily_games = df['date'].value_counts().reset_index()
daily_games.columns = ['date', 'count']
# Sort the daily_games DataFrame by the 'date' column
daily_games = daily_games.sort_values('date')
# Convert 'date' column to datetime
daily_games['date'] = pd.to_datetime(daily_games['date'])
fig = calplot(
daily_games,
x="date",
y="count",
gap=0,
month_lines=False,
years_title=True,
colorscale="teal",
name = "Games Played",
space_between_plots = 0.2,
total_height=700,
dark_theme=True,
)
# Display the plot
c2.plotly_chart(fig)

What this plot tells me is that I may have spent just too much time on generals.io in the last three years.

I scraped the user data for a bunch of users, so whenever you change the selected the user, the app imports that dataset and generates plots based on that user’s dataset.

I initially wanted to put a text box only: you simply type the username, and wola, all stats for that user is generated!

But it turns out that wasn’t an easy task.

Why? Take a random user’s game stats webpage: https://generals.io/profiles/yurtlujohn. (OK, it may not be that random)

We can only see about ~20 games for that user. But the user has played looots of game previously, so we need to click on the ‘Load More’ at the bottom of the page. And that, my friends, are possible by Selenium. But Selenium uses my chromedriver on my personal machine to open a browser and click on that button. So that’s just not possible in Streamlit, or in any web app. There might be some workaround — but still, it would take a very long time to fetch the whole data even for a single user.

This was my first experience using Streamlit, and oh boy, it really is great; can’t complain. I used to do RShiny apps, like this survey one, but I have to admit that Streamlit is more flexible, and faster. It has a wider community support, it has great ‘components’, fast, and easy to write. In any RShiny app, the functions can easily become a mess — but in Streamlit, you can keep the code tidy and shiny. It’s great that both are just one app file, and that’s it.

--

--

Selim Yaman

Political (Data) Scientist. Does ML and NLP with political data.