Day 83 of 100 Days Coding Challenge: Python
I’ve loved history for as long as I can remember. By fourth grade, I was devouring children’s versions of The Histories by Herodotus while other kids were still stuck on Goosebumps. My parents’ library was my playground, and I spent hours flipping through volumes that smelled faintly of dust and mystery. By the time school took history seriously in high school, I was already knee-deep in maps and timelines.
Back then, I didn’t know the word “mind mapping,” but that’s essentially what I was doing. I’d draw crude maps, sketch arrows, and connect civilizations like I was building my own analog version of Wikipedia. Today’s task reminded me of that hobby: giving my timeline builder a taxonomy of event kinds—wars, dynasties, tech, culture, economy, religion—so that I can glance at a timeline and instantly know what kind of drama unfolded. Think of it as giving history not just a shape, but also a color palette.
Today’s Motivation / Challenge
Why bother with taxonomies? Because not all events are created equal. A war feels very different from an invention, and a dynasty change isn’t the same as a religious reform. By categorizing events and slapping on colors and icons, the app becomes more than a list of “things that happened.” It becomes a visual storybook where you can spot patterns at a glance—wars clustering together, bursts of culture, or dynasties toppling like dominoes.
Purpose of the Code (Object)
The code assigns each event a category (“kind”) and gives it a color and icon. When you view a civilization’s timeline, events appear as dots along its bar, each colored by type. A neat legend ties it all together, letting you see not just when things happened, but what kind of things they were. It’s like adding subtitles to history.
AI Prompt
Today is the day 8 of this project. Please add the following script:
Day 8 — Event types & icons
- Kind taxonomy (war/dynasty/tech/culture/economy/religion).
- Accept: legend renders; event dots color by kind.
Functions & Features
- Define taxonomy of event types (war, dynasty, tech, culture, economy, religion, other).
- Assign each taxonomy a color and icon for clarity.
- Display event dots along timeline bars, grouped and color-coded by type.
- Add a clean legend so users know exactly what each dot means.
Requirements / Setup
You’ll need:
- Python 3.11
Installs:
pip install plotly streamlit
Minimal Code Sample
KIND_COLORS = {
“war”: “red”, “dynasty”: “blue”, “tech”: “green”,
“culture”: “purple”, “economy”: “orange”, “religion”: “gold”
}
for kind, group in grouped_events.items():
fig.add_scatter(
x=group[“year”], y=group[“civ”],
mode=”markers”, name=kind.capitalize(),
marker=dict(color=KIND_COLORS.get(kind, “gray”))
)
Each event type gets its own scatter trace with a color-coded legend.
The Civilization Timeline Builder
Notes / Lessons Learned
We started by defining the taxonomy—deciding which categories mattered most. I learned from yesterday’s naming mishap that consistency is everything, so I double-checked each description to keep it tidy. Each taxonomy got a color, and if an event didn’t fit, we just shoved it into “Other.” Practical and honest.
One fun surprise: Python 3.11’s str | None is cleaner than Optional[str], though you may see both depending on your version. Reddit was full of debates about this, but personally, I like the shorthand.
The real magic came when we modified the build_time_band function to group events by kind and add scatter traces only if there were points. That way, the legend didn’t become cluttered with empty categories. Now the timelines look like candy-colored storylines, dotted with wars, dynasties, and cultural sparks. The result? A clean legend across the top and timelines that actually feel alive.
Optional Ideas for Expansion
- Add tiny event icons (like swords for wars or scrolls for culture) alongside the dots.
- Let users filter the timeline by event kind (e.g., “Show me only tech”).
- Stack events into mini-bands under each civ for an even clearer breakdown.
