Skip to content

feat: add nighttime rendering and improve place disambiguation#6

Closed
Ninjona wants to merge 1 commit intoVG-dev1:mainfrom
Ninjona:main
Closed

feat: add nighttime rendering and improve place disambiguation#6
Ninjona wants to merge 1 commit intoVG-dev1:mainfrom
Ninjona:main

Conversation

@Ninjona
Copy link
Copy Markdown

@Ninjona Ninjona commented Apr 9, 2026

Summary

This PR addresses three major enhancements to weathery:

  1. Nighttime Rendering Support – Full day/night awareness with dedicated clear-sky animation and moon icons
  2. Location Disambiguation Fix – Robust handling of ambiguous place names that exist in multiple states/countries
  3. Weather Code Integration – Day/night aware weather descriptions and reliable animation selection using weather codes

Changes

Feature 1: Nighttime Support

Files Modified: src/animate.rs, src/weather.rs, src/main.rs

  • Added is_night: bool flag to WeatherData by parsing Open-Meteo's is_day field
  • Implemented dedicated animate_clear_night() function that renders twinkling stars on dark backgrounds
  • Added night-aware icon display (moon 🌙 instead of sun ☀️ for clear conditions)
  • Applied night_tint() color filter to all weather animations during nighttime
  • Implemented fixed-position star placement with time-based twinkle effect to avoid "precipitation" appearance

User Benefit:

  • Realistic nighttime visualization with distinct animations
  • Proper icon representation of nighttime conditions
  • No false precipitation appearance during clear nights

Feature 2: Place Disambiguation & Resolution

Files Modified: src/weather.rs, src/image_fetch.rs, src/main.rs

Geocoding Improvements:

  • Changed Open-Meteo search from single result (count=1) to top 10 candidates (count=10)
  • Implemented fallback query strategy:
    1. Try original full query
    2. Fall back to comma-normalized query
    3. Fall back to city-only query
  • Preserved query priority order using HashSet deduplication
  • Added weighted disambiguation scoring:
    • Exact admin1/country match: +5M points
    • Partial haystack match: +1M points
    • No match in secondary parts: -500K points
    • Population tiebreaker
  • Extended GeoResult deserialize to capture name, admin1, country, population fields
  • Added format_location_name() to generate canonical display names

Image Resolution Improvements:

  • Implemented Wikipedia search fallback in get_city_image_url()
  • Try direct Wikipedia title lookup first
  • Fall back to Wikipedia search with top 8 results if no thumbnail found
  • Iterate through search results to find one with an image
  • Ensures ambiguous places resolve to pages with actual imagery
  • Automatic fallback to user's original query if canonical name has no Wikipedia image
  • Robust handling of place disambiguation across API boundaries

Feature 3: Weather Code Integration & Day/Night Icons

Files Modified: src/animate.rs, src/main.rs, src/weather.rs

  • Extracted weather_code: u32 field into WeatherData struct for direct access
  • Implemented weather_from_code() function mapping codes to animation types:
    • Codes 51, 53, 55, 61, 63, 65, 80, 81, 82 → Rain
    • Codes 71, 73, 75, 77, 85, 86 → Snow
    • Codes 95, 96, 99 → Thunderstorm
    • All others → Clear
  • Updated animation selection to use weather codes directly (bypasses description parsing)
  • Made weather_description() day/night aware:
    • Daytime: ☀️ Clear sky, 🌤 Mainly clear, ⛅ Partly cloudy
    • Nighttime: 🌙 Clear sky, 🌙 Mainly clear, ☁️ Partly cloudy
  • Removed unused string-based Weather::from_str() parser

User Benefit:

  • More reliable animation selection based on official codes, not fragile text parsing
  • Proper nighttime icon representation (moon instead of sun)
  • Cleaner codebase with dead code removed

This PR adds:

  • Full nighttime animation system
  • Production-grade place disambiguation
  • Robust code-based weather classification
  • Wikipedia search fallback for images

Lines Changed:

  • src/weather.rs: +121/-18 (net +103)
  • src/animate.rs: +130/-12 (net +118)
  • src/image_fetch.rs: +32/-8 (net +24)
  • src/main.rs: +16/-6 (net +10)

Testing Checklist

  • weathery "Rochester, NY" – resolves correctly
  • Clear-night mode renders with twinkling stars (no false precipitation)
  • Nighttime weather shows moon icon instead of sun
  • Rain/snow animations don't trigger on clear days
  • Weather code mapping covers all Open-Meteo codes
  • Daytime behavior unchanged

- Add night/day detection with Open-Meteo is_day field
- Implement clear-night animation with twinkling stars
- Add moon icon display for nighttime clear skies
- Fix weather classification to use weather codes instead of text parsing
- Improve geocoding with fallback queries for ambiguous place names
- Add weighted disambiguation scoring for location candidates
- Implement Wikipedia search fallback for better image resolution
- Apply night tint to all weather conditions during nighttime
- Preserve query fallback priority order for accurate disambiguation
@VG-dev1
Copy link
Copy Markdown
Owner

VG-dev1 commented Apr 9, 2026

Thank you so much for a massive PR! That's awesome!

I’m really excited about your changes. They address a lot of issues and add great improvements. The timing is a bit tricky, though: I have some local features I’ve been working on that I haven’t committed yet.

Because of that, I need to carefully integrate your PR with my local changes to make sure everything works together.

I just wanted to give you a heads-up in case I take a little extra time to make sure everything is fully compatible.

Thanks again for the huge contribution, I really appreciate it!

@VG-dev1 VG-dev1 added bug Something isn't working enhancement New feature or request labels Apr 9, 2026
@VG-dev1
Copy link
Copy Markdown
Owner

VG-dev1 commented Apr 11, 2026

I've baked everything together into one commit I just pushed to my branch, so I can't merge your PR. I'm closing it. But again, thank you so much for your amazing contribution!

@VG-dev1 VG-dev1 closed this Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants