Skip to content

feat(analytics): add local validation analytics and CLI - #12

Merged
ankitgadling merged 3 commits into
ankitgadling:mainfrom
adisingh396:feature/analytics-dashboard
Oct 3, 2025
Merged

feat(analytics): add local validation analytics and CLI#12
ankitgadling merged 3 commits into
ankitgadling:mainfrom
adisingh396:feature/analytics-dashboard

Conversation

@adisingh396

@adisingh396 adisingh396 commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

📌 Pull Request

Description

This PR introduces a local, opt-in analytics feature to help developers monitor postal code validation usage within their projects. It tracks valid and invalid counts per country and provides both a CLI dashboard and Python functions for interaction, as outlined in the issue. All data is stored locally in the user's home directory (~/.postalregex_stats.json) with no network requests.

Related Issue

Fixes #8

Changes Made

  • Added src/postal_regex/analytics.py to handle all stat tracking logic (load, save, reset).
  • Added src/postal_regex/cli.py to create the postal-regex stats command.
  • Updated pyproject.toml to register the new CLI command.
  • Modified core.validate() to automatically call record_validation() on every attempt.
  • Exposed the new analytics functions in __init__.py.

Checklist

  • Tests added/updated
  • Code follows project style guidelines
  • pytest -v passes locally
  • Documentation updated (if needed)

Additional Notes

Some Screenshots
Screenshot 2025-10-02 163147

This adds an optional, local-only analytics feature to track postal code validation stats.

- Implements API functions: record_validation, show_stats, and reset_stats.
- Adds a CLI command 'postal-regex stats' to display a dashboard.
- Integrates stat recording directly into the core validate() function.
- All data is stored locally in ~/.postalregex_stats.json.

@ankitgadling ankitgadling left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove print() from core analytics and keep validate() pure; use record_validation() optionally and let the CLI handle all output/visualization.

Comment thread src/postal_regex/core.py Outdated
@adisingh396
adisingh396 force-pushed the feature/analytics-dashboard branch from 9e63ba0 to 8e7b9ed Compare October 2, 2025 16:05
@adisingh396

Copy link
Copy Markdown
Contributor Author

Hey @ankitgadling,
thanks for the feedback, it makes sense:

I've pushed up the changes:

  1. The call to record_validation() has been removed from core.validate() to keep it pure and make the analytics opt-in.
  2. I've refactored the analytics module, creating a new get_stats() function that returns the raw data. The show_stats() function and the CLI now use this, separating the logic from the presentation.
    Let me know what you think

@adisingh396
adisingh396 force-pushed the feature/analytics-dashboard branch from 8e7b9ed to 94862de Compare October 2, 2025 16:10

@ankitgadling ankitgadling left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all changes looks good. Do Format and lint your code

Comment thread src/postal_regex/core.py Outdated
@adisingh396

Copy link
Copy Markdown
Contributor Author

@ankitgadling alright removed the unused import and added the new get_stats function in __init__.py imports.

@ankitgadling

Copy link
Copy Markdown
Owner

@zendrix396 Thanks for the update! but tests on Python 3.12 are failing Please check the CI logs, run tests locally, and update the PR so we can merge.

@adisingh396
adisingh396 force-pushed the feature/analytics-dashboard branch from aac9feb to e233268 Compare October 3, 2025 06:55
@adisingh396

adisingh396 commented Oct 3, 2025

Copy link
Copy Markdown
Contributor Author

@ankitgadling fixed the tests!
image

@ankitgadling ankitgadling changed the title Analytics Dashboard feat(analytics): add local validation analytics and CLI Oct 3, 2025
@ankitgadling
ankitgadling merged commit 1a7bff9 into ankitgadling:main Oct 3, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add optional local analytics/dashboard for postal code validation

2 participants