Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Fargo 06/2024 election for City Commissioner #16

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ npm run build

You can preview the production build with `npm run preview`.

## Adding results to the dataset

To keep this very simple the dataset is statically hosted in this github repo in `./data.db`
fsargent marked this conversation as resolved.
Show resolved Hide resolved

To add to the report, edit `./load-report.js` with the data from the election.

Submit a pull request with the updated `data.db`.

## Deployment
Copy link

Choose a reason for hiding this comment

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

Ensure headings are surrounded by blank lines for proper markdown formatting.

+ 
## Deployment
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## Deployment
## Deployment
Tools
Markdownlint

30-30: Expected: 1; Actual: 0; Below (MD022, blanks-around-headings)
Headings should be surrounded by blank lines


fsargent marked this conversation as resolved.
Show resolved Hide resolved
Site is hosted on github pages. Merge to main and it'll auto deploy.
fsargent marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Binary file modified data.db
Binary file not shown.
80 changes: 80 additions & 0 deletions load-report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import Database from "better-sqlite3";

// Path to your SQLite database file
const db = new Database("data.db");

const insertReport = db.prepare(`
INSERT INTO reports (name, date, jurisdictionPath, electionPath, office, officeName, jurisdictionName, electionName, website, notes, ballotCount, path, hidden)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`);

const insertCandidate = db.prepare(`
INSERT INTO candidates (report_id, name, votes, winner)
VALUES (?, ?, ?, ?)
`);

function addReportAndCandidates(report, candidates) {
// Start a transaction
const transaction = db.transaction(() => {
// Insert the report
const result = insertReport.run(
report.name,
report.date,
report.jurisdictionPath,
report.electionPath,
report.office,
report.officeName,
report.jurisdictionName,
report.electionName,
report.website,
report.notes,
report.ballotCount,
report.path,
report.hidden
);

// Get the last inserted row ID
const reportId = result.lastInsertRowid;

// Insert candidates
for (const candidate of candidates) {
insertCandidate.run(reportId, candidate.name, candidate.votes, candidate.winner);
}
});

// Execute the transaction
transaction();
}
fsargent marked this conversation as resolved.
Show resolved Hide resolved

// Example data to insert
const report = {
name: "June 11, 2024 Commissioner Fargo",
date: "2024-06-11",
jurisdictionPath: "us/nd/fargo",
electionPath: "2024/06",
office: "commissioner",
officeName: "City Commissioner",
jurisdictionName: "Fargo, ND",
electionName: "Primary Election",
website: "https://results.sos.nd.gov/resultsSW.aspx?text=All&type=CIALL&map=CTY&area=Fargo&name=Fargo",
notes: "",
ballotCount: 14781,
path: "us/nd/fargo/2024/06",
hidden: 0
};

const candidates = [
{ name: "Michelle Turnberg", votes: 6850, winner: 1 },
{ name: "John Strand", votes: 6579, winner: 1 },
{ name: "Al Carlson", votes: 5746, winner: 0 },
{ name: "Arlette Preston", votes: 5560, winner: 0 },
{ name: "Anna Johnson", votes: 3545, winner: 0 },
{ name: "Delson Saintal", votes: 2378, winner: 0 },
{ name: "Nathan Pullen", votes: 1879, winner: 0 },
{ name: "write-in", votes: 85, winner: 0 }
];

// Add the report and candidates to the database
addReportAndCandidates(report, candidates);

console.log("Report and candidates added successfully");
fsargent marked this conversation as resolved.
Show resolved Hide resolved
58 changes: 0 additions & 58 deletions load-reports.js

This file was deleted.

58 changes: 0 additions & 58 deletions load-reports.ts

This file was deleted.

Loading