Skip to content

nictsc/weather-python-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weather Utilities (Python)

This repository contains a small, dependency-free Python module for parsing simple daily weather records from CSV and producing human-readable summaries. It’s designed to be easy to reason about, testable end-to-end, and straightforward to extend.

Why it matters

  • Focuses on composable, pure functions to simplify reasoning and testing.
  • Clear separation between data access/formatting and core logic.
  • Zero third-party dependencies for portability and reliability.

Repository Structure

Public API (core functions)

  • convert_f_to_c(value_f): Fahrenheit to Celsius conversion.
  • calculate_mean(values): Numeric mean for an iterable of numbers.
  • find_min(values), find_max(values): Helpers used by summaries to identify extrema.
  • convert_date(iso_string): Converts an ISO-like date string into a human-readable form.
  • load_data_from_csv(path): Loads daily weather records from CSV into in-memory structures.
  • generate_summary(data): Produces an overall summary string across the dataset.
  • generate_daily_summary(data): Produces a per-day summary string across the dataset.

These functions are intentionally small, deterministic, and composable. Business formatting (e.g., user-facing strings) is centralized in the summary functions, while numeric operations and parsing are kept isolated and reusable.

Data Contract

  • Inputs: Simple CSV files with daily readings (see examples in tests/data).
  • Outputs: Human-readable summary strings (see expected results in tests/expected_output).
  • Error handling: Non-numeric or malformed rows are safely skipped or normalized during load; downstream functions operate on already-sanitised inputs.

Design Notes

  • Purity and isolation: Most functions are pure (no I/O), enabling targeted unit tests and easy reuse.
  • Cohesion: Numeric helpers (mean, min, max, conversions) are decoupled from formatting.
  • Extensibility: New metrics (e.g., median, range), units, or output formats can be added without touching existing logic.
  • Testability: Golden-file style tests document the contract and prevent regressions.

Complexity and Performance

  • Parsing is linear in the number of rows, O(n).
  • Summary generation is linear in the number of daily records, O(n).
  • Memory footprint is proportional to the number of rows parsed.

Getting Started

  1. Ensure Python 3.10+ is available on your PATH.
  2. Run the test suite:
python -m unittest tests/*.py
  1. Explore the example inputs and expected outputs:
  1. Optional: Inspect or adapt the minimal runner in print_weather.py.

Extension Ideas

  • Add aggregation windows (weekly/monthly) or additional statistics (median, stdev).
  • Support alternate input formats (JSON, NDJSON) behind a parsing interface.
  • Provide multiple renderers (plain text, Markdown) via strategy pattern.
  • Add a lightweight CLI with subcommands for “summary” and “daily-summary”.

Notes for Reviewers

  • The tests act as executable documentation of the expected behavior and string formatting.
  • The API surface is intentionally small and focused on clarity over cleverness.

About

Parses and normalises file data for backend consumption in Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages