Add UUID support to candidate data for unique identification #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds UUID (Universally Unique Identifier) support to all candidate data in the repository, resolving issue #[issue_number]. Previously, candidate records had no unique identifiers, making it difficult to reference specific candidates across different parts of the application.
Changes Made
1. Created UUID Update Script
Added
scripts/add_uuid_to_candidates.py- a standalone, executable script that:Example usage:
python3 scripts/add_uuid_to_candidates.py # or ./scripts/add_uuid_to_candidates.py2. Updated Data Models
Modified
app/models/candidate.pyto include UUID fields:uuidfield toLokSabhaCandidatemodeluuidfield toAssemblyCandidatemodelBefore:
After:
3. Updated Scrapers
Modified both scrapers to automatically generate UUIDs for newly scraped candidates:
app/scrapers/lok_sabha.py- generates UUIDs when scraping Lok Sabha dataapp/scrapers/vidhan_sabha.py- generates UUIDs when scraping Vidhan Sabha dataThis ensures all future scraped data will include unique identifiers.
4. Updated Existing Data
Ran the UUID update script to add identifiers to all existing candidate records:
All UUIDs follow the standard UUID4 format (e.g.,
baa14e3d-00e4-49de-8c56-75e06a069eb2).5. Added Documentation
Created
scripts/README.mdwith comprehensive documentation including:Sample Data Structure
Before:
{ "Constituency Code": "DL-1", "Name": "RAJ KARAN KHATRI", "Party": "Bharatiya Janata Party", "Status": "WON", "Votes": "87215", "Margin": "8596" }After:
{ "uuid": "baa14e3d-00e4-49de-8c56-75e06a069eb2", "Constituency Code": "DL-1", "Name": "RAJ KARAN KHATRI", "Party": "Bharatiya Janata Party", "Status": "WON", "Votes": "87215", "Margin": "8596" }Benefits
Testing
All changes have been thoroughly tested:
Notes
The Lok Sabha 2024 candidates file is currently empty, so no UUIDs were added to it. When data is scraped for this election, the scraper will automatically generate UUIDs.
Original prompt
Fixes #3
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.