-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFIX_DISTRICTS_NOW.ps1
More file actions
101 lines (81 loc) · 3.57 KB
/
FIX_DISTRICTS_NOW.ps1
File metadata and controls
101 lines (81 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# COMPLETE DISTRICT ASSIGNMENT FIX
# Run this script to fix everything in one go
Write-Host "=" -NoNewline; Write-Host ("=" * 79)
Write-Host "DISTRICT ASSIGNMENT - COMPLETE FIX"
Write-Host "=" -NoNewline; Write-Host ("=" * 79)
Write-Host ""
# Step 1: Find the statewide CSV
Write-Host "Step 1: Locate statewide CSV file"
Write-Host "Please provide the path to your STATEWIDE_VOTER_INFO.csv file:"
Write-Host "(The file with columns: id_voter, tx_precinct_code, tx_county_name, voting_method)"
Write-Host ""
$csvPath = Read-Host "CSV file path"
if (-not (Test-Path $csvPath)) {
Write-Host "ERROR: File not found: $csvPath" -ForegroundColor Red
exit 1
}
Write-Host "✓ Found CSV file: $csvPath" -ForegroundColor Green
$csvSize = (Get-Item $csvPath).Length / 1MB
Write-Host " Size: $([math]::Round($csvSize, 1)) MB"
Write-Host ""
# Step 2: Upload CSV to server
Write-Host "Step 2: Uploading CSV to server..."
scp -i WhoVoted/deploy/whovoted-key.pem $csvPath ubuntu@politiquera.com:/opt/whovoted/data/STATEWIDE_VOTER_INFO.csv
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Failed to upload CSV" -ForegroundColor Red
exit 1
}
Write-Host "✓ CSV uploaded successfully" -ForegroundColor Green
Write-Host ""
# Step 3: Upload backfill script
Write-Host "Step 3: Uploading backfill script..."
scp -i WhoVoted/deploy/whovoted-key.pem WhoVoted/deploy/backfill_precincts_from_statewide_csv.py ubuntu@politiquera.com:/opt/whovoted/deploy/
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Failed to upload script" -ForegroundColor Red
exit 1
}
Write-Host "✓ Script uploaded" -ForegroundColor Green
Write-Host ""
# Step 4: Run backfill
Write-Host "Step 4: Backfilling precinct data..."
Write-Host "(This will update 62,876 records with missing precinct data)"
Write-Host ""
ssh -i WhoVoted/deploy/whovoted-key.pem ubuntu@politiquera.com "cd /opt/whovoted && python3 deploy/backfill_precincts_from_statewide_csv.py"
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Backfill failed" -ForegroundColor Red
exit 1
}
Write-Host ""
Write-Host "✓ Precinct data backfilled" -ForegroundColor Green
Write-Host ""
# Step 5: Upload district assignment script
Write-Host "Step 5: Uploading district assignment script..."
scp -i WhoVoted/deploy/whovoted-key.pem WhoVoted/deploy/build_normalized_precinct_system.py ubuntu@politiquera.com:/opt/whovoted/deploy/
Write-Host "✓ Script uploaded" -ForegroundColor Green
Write-Host ""
# Step 6: Run district assignment
Write-Host "Step 6: Assigning districts..."
Write-Host "(This will match precincts to districts for all voters)"
Write-Host ""
ssh -i WhoVoted/deploy/whovoted-key.pem ubuntu@politiquera.com "cd /opt/whovoted && python3 deploy/build_normalized_precinct_system.py"
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: District assignment failed" -ForegroundColor Red
exit 1
}
Write-Host ""
Write-Host "✓ Districts assigned" -ForegroundColor Green
Write-Host ""
# Step 7: Verify results
Write-Host "Step 7: Verifying results..."
scp -i WhoVoted/deploy/whovoted-key.pem WhoVoted/deploy/final_district_assignment_status.py ubuntu@politiquera.com:/opt/whovoted/deploy/
ssh -i WhoVoted/deploy/whovoted-key.pem ubuntu@politiquera.com "cd /opt/whovoted && python3 deploy/final_district_assignment_status.py"
Write-Host ""
Write-Host "=" -NoNewline; Write-Host ("=" * 79)
Write-Host "COMPLETE!" -ForegroundColor Green
Write-Host "=" -NoNewline; Write-Host ("=" * 79)
Write-Host ""
Write-Host "Next steps:"
Write-Host "1. Review the verification results above"
Write-Host "2. If D15 accuracy is 95%+, regenerate district caches"
Write-Host "3. Deploy to production"
Write-Host ""