Skip to content

Refactor: centralize config, improve logging, and clean up code#4

Draft
d-roho wants to merge 1 commit into
mainfrom
claude/identify-improvements-Bcm23
Draft

Refactor: centralize config, improve logging, and clean up code#4
d-roho wants to merge 1 commit into
mainfrom
claude/identify-improvements-Bcm23

Conversation

@d-roho
Copy link
Copy Markdown
Owner

@d-roho d-roho commented May 6, 2026

Summary

This PR significantly improves code maintainability and observability by extracting hardcoded configuration values into a central config module, adding comprehensive logging throughout the application, and refactoring several functions for clarity and robustness.

Key Changes

Configuration Management

  • Created new config.py module to centralize all configuration values (GSI settings, prediction thresholds, map codes, weapon classifications)
  • Moved hardcoded values from gsi_pinger.py, snapshot_parser.py, and MainApp.py into config
  • Updated weapon classification lists to use frozenset for better performance and immutability
  • Fixed de_ancient map code collision (now uses code 8 instead of 4)

Logging Infrastructure

  • Added structured logging throughout the application with appropriate log levels (DEBUG, INFO, WARNING)
  • Configured logging in MainApp.py with -v flag support for verbose output
  • Replaced print statements with logger calls for better observability and control
  • Added debug logging for transient errors and GSI server activity

Code Quality Improvements

  • Refactored snapshot_parser.py:

    • Simplified player iteration using enumerate and f-strings
    • Consolidated weapon counting into a single pass over players
    • Improved error handling with try-except for missing/malformed data
    • Enhanced docstrings with detailed attribute ordering
  • Refactored MainApp.py:

    • Made Windows-only imports conditional with graceful fallback
    • Simplified welcome message display with better file handling
    • Consolidated match-start checking logic
    • Improved pause detection and prediction output formatting
    • Cleaner exception handling with more informative messages
  • Refactored gsi_pinger.py:

    • Improved HTTP server implementation with better authentication
    • Used mutable container pattern to avoid global state
    • Added proper exception handling and logging
    • Suppressed per-request HTTP noise in logs

Robustness

  • Added defensive .get() calls with defaults throughout to handle missing GSI data
  • Improved error recovery in main prediction loop
  • Better handling of edge cases (empty servers, warmup detection, bomb timer)

Notable Implementation Details

  • Freezetime prediction override now uses configurable constant instead of magic number
  • Bomb near-expiry threshold is now configurable
  • Weapon classification uses frozensets for O(1) lookup performance
  • GSI authentication and server configuration centralized for easier deployment customization

https://claude.ai/code/session_01BpRrR55tsrkVo9W5rtwYMK

…ctor

1. config.py — Centralises all hardcoded values (GSI auth token, port,
   timing thresholds, map codes, weapon lists) so they are easy to find
   and change without touching logic files.

2. Logging + exception hygiene — Replaces every print() with the stdlib
   logging module (INFO to console, DEBUG with -v flag).  Fixes bare
   `except:` clauses in gsi_pinger.py and MainApp.py that were silently
   swallowing KeyboardInterrupt and SystemExit.  Adds graceful handling
   for the missing pywin32 dependency on non-Windows platforms.

3. de_ancient collision fix + snapshot_arrayfier single-pass refactor —
   de_ancient was mapped to code 4 (same as de_nuke), causing the model
   to silently misclassify the map.  It now gets its own code (8).
   The four separate player-iteration loops in snapshot_arrayfier are
   consolidated into one pass, halving the number of dict lookups and
   removing duplicated key-construction logic.

https://claude.ai/code/session_01BpRrR55tsrkVo9W5rtwYMK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants