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

relase 0.2 - poll-db-2 #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
723 changes: 723 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions politicians.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name,party,location,grade_current
Aaron Schock,R,IL,11.5362423
Adam Kinzinger,R,IL,8.995621754
Adam Schiff,D,LA,13.0347375
Adam Smith,D,WA,10.23695519
Anna Eshoo,D,WA,10.65351543
Bill Cassidy,R,LA,9.285165569
Candice Miller,R,WA,11.70865922
Carolyn Maloney,D,NY,13.03522892
Dana Rohrabacher,R,NY,10.64634133
Duncan Hunter,R,IL,13.66509733
Erik Paulsen,R,LA,11.69134788
Frank Guinta,R,HI,10.94131093
Frank LoBiondo,R,HI,13.08452404
John Kerry,D,LA,11.01029616
Joseph Lieberman,I,NY,7.95536381
Michael Bennet,D,IL,7.98091322
Olympia Snowe,R,WA,13.80125838
Richard Shelby,R,HI,11.31326157
Yvette Clarke,D,NY,12.45211362
Zoe Lofgren,D,HI,12.76643582
Binary file added poll2.db
Binary file not shown.
19 changes: 19 additions & 0 deletions release0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('poll2.db');

db.serialize(function() {

db.all("SELECT name, location, grade_current, (SELECT COUNT(*) FROM votes WHERE politiciansId = politicians.id) AS totalVote FROM politicians ORDER BY grade_current LIMIT 3", [], function(err, row){
if(err){ console.log(err)}
else{ console.log(row)}
});

db.all("SELECT name AS politicianName,(SELECT COUNT(*) FROM votes WHERE politiciansId = politicians.id) AS totalVote FROM politicians ORDER BY totalVote DESC LIMIT 3", [], function(err, row){
if(err){console.log(err)}
else{console.log(row)}
});


});

db.close();
46 changes: 46 additions & 0 deletions seed-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const fs = require('fs');

let dataPoliticians = fs.readFileSync('./politicians.csv', 'utf8').trim().split('\n');
let dataVoters = fs.readFileSync('./voters.csv', 'utf8').trim().split('\n');
let dataVotes = fs.readFileSync('./votes.csv', 'utf8').trim().split('\n');

var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('poll2.db');

db.serialize(function() {

let stmt1 = db.prepare("INSERT INTO politicians (name, party, location, grade_current) VALUES (?,?,?,?)");
for (let i = 1; i < dataPoliticians.length; i++) {
let dataPoliticiansArr = dataPoliticians[i].split(',')
let name = dataPoliticiansArr[0];
let party = dataPoliticiansArr[1];
let location = dataPoliticiansArr[2];
let gradeCurrent = dataPoliticiansArr[3];
stmt1.run(name, party, location, gradeCurrent);
}
stmt1.finalize();


let stmt2 = db.prepare("INSERT INTO voters (firstName, lastName, gender, age) VALUES (?,?,?,?)");
for(let i = 1; i < dataVoters.length; i++){
let dataVotersArr = dataVoters[i].split(',');
let fname = dataVotersArr[0];
let lname = dataVotersArr[1];
let gender = dataVotersArr[2];
let age = dataVotersArr[3];
stmt2.run(fname, lname, gender, age);
}
stmt2.finalize();

let stmt3 = db.prepare("INSERT INTO votes (votersId, politiciansId) VALUES (?,?)");
for(let i = 1; i < dataVotes.length; i++){
let dataVotesArr = dataVotes[i].split(',');
let politicId = dataVotesArr[1];
let voterId = dataVotesArr[0];
stmt3.run(voterId, politicId);
}
stmt3.finalize();

});

db.close();
12 changes: 12 additions & 0 deletions setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('poll2.db');

db.serialize(function() {
db.run("CREATE TABLE IF NOT EXISTS politicians (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, party TEXT, location TEXT, grade_current REAL)");

db.run("CREATE TABLE IF NOT EXISTS voters (id INTEGER PRIMARY KEY AUTOINCREMENT, firstName TEXT, lastName TEXT, gender TEXT, age TEXT)");

db.run("CREATE TABLE IF NOT EXISTS votes (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, votersId INTEGER, politiciansId INTEGER, FOREIGN KEY(votersId) REFERENCES voters(id), FOREIGN KEY(politiciansId) REFERENCES politicians(id))");
});

db.close();
151 changes: 151 additions & 0 deletions voters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
first_name,last_name,gender,age
Aaliyah,Langworth,male,61
Aaliyah,VonRueden,male,73
Aaliyah,Konopelski,female,39
Abdullah,Block,male,66
Amaya,Satterfield,male,23
Barbara,Ortiz,female,76
Barney,Lubowitz,female,76
Berniece,Sanford,female,23
Betsy,Blick,male,23
Buster,Hodkiewicz,male,56
Cade,Batz,female,61
Cameron,Walsh,female,30
Cameron,Dickinson,female,36
Camilla,Feil,male,23
Candice,Torp,female,23
Courtney,Spinka,female,42
Devon,Kutch,female,26
Devon,Mayer,female,71
Devon,Waters,female,70
Devonte,Erdman,female,27
Devonte,Pfeffer,male,29
Dora,Schinner,male,78
Dora,Cole,female,18
Duncan,Dach,male,70
Duncan,O'Reilly,male,75
Durward,Stroman,male,37
Elias,Watsica,female,50
Eliezer,Predovic,female,30
Elinore,Collier,female,75
Emmett,Corkery,female,88
Emmie,Swaniawski,female,76
Fabian,Murphy,female,85
Fabian,Keeling,male,76
Fabian,Nolan,male,70
Fabiola,Klocko,female,45
Furman,Crist,male,23
Furman,Waelchi,female,26
Gabriel,Ledner,male,62
Gabriel,Dicki,female,87
Gerald,Bernier,male,23
Graciela,Berge,female,21
Grady,Grady,female,34
Graham,Hoppe,female,19
Graham,Padberg,male,58
Harley,Murphy,male,72
Harley,Runolfsdottir,female,37
Hudson,Streich,male,25
Hudson,Donnelly,male,20
Hugh,Feil,male,33
Hunter,Erdman,male,68
Hyman,Grant,male,74
Ian,Dibbert,male,40
Isaac,Ratke,male,81
Isabell,Price,male,73
Iva,Roob,female,44
Ivah,Raynor,male,71
Ivory,Gorczany,female,61
Ivory,Wolf,female,38
Ivy,Stehr,female,89
Janice,Zboncak,male,48
Janice,Erdman,male,57
Jason,Erdman,male,37
Jason,Lang,female,56
Jenifer,Lind,male,47
Jennie,Mante,female,21
Margarett,Wilkinson,male,73
Margarett,Schultz,female,36
Margaretta,Koepp,male,72
Neoma,Gottlieb,male,38
Nona,Murazik,female,88
Norbert,Kozey,male,41
Ottilie,Lakin,female,88
Prudence,Bergstrom,female,33
Prudence,Brakus,female,67
Prudence,Goldner,male,37
Prudence,Kilback,female,88
Queen,White,female,64
Ricardo,Koss,female,65
Richie,Eichmann,male,85
Richie,Sanford,female,70
Santino,Labadie,male,18
Santino,Nienow,female,62
Santos,Hintz,female,20
Santos,Jaskolski,female,79
Sarah,Feeney,female,64
Sarah,Hyatt,female,26
Theodore,Ferry,female,89
Theodore,Stamm,male,56
Theresa,Price,female,83
Theresia,Fay,male,64
Theresia,Rohan,female,20
Tobin,Streich,male,77
Toby,Terry,female,19
Toby,Wehner,male,18
Tom,Huel,female,45
Ursula,Bednar,male,65
Ursula,Mayer,male,63
Ursula,Hahn,female,87
Vanessa,O'Hara,male,28
Vanessa,Rodriguez,female,40
Walker,Sauer,male,19
Walker,Reichert,male,21
Walker,Stoltenberg,female,59
Walker,Stiedemann,female,32
Wallace,Klein,female,41
Walter,Franecki,female,68
Walter,Kuvalis,male,22
Walton,Jerde,female,73
Xavier,Harber,female,38
Xavier,Braun,female,41
Xavier,Streich,female,28
Yadira,Krajcik,female,81
Yasmeen,Lubowitz,male,41
Yasmeen,Thompson,female,80
Yasmine,Keeling,male,61
Yasmine,Rippin,female,77
Yesenia,Schaden,female,55
Yesenia,Watsica,female,26
Yessenia,Hudson,female,42
Yolanda,Jones,male,24
Yolanda,Reynolds,female,26
Yolanda,Abernathy,male,90
Yoshiko,Zulauf,male,42
Yoshiko,Klein,male,37
Yvette,Schuster,male,76
Yvette,Russel,male,88
Yvonne,Wolff,male,31
Zachariah,Dach,male,18
Zachary,Hackett,female,45
Zachary,Durgan,male,69
Zachery,Metz,female,52
Zachery,Lehner,female,25
Zackary,Funk,female,77
Zackery,Schuster,female,53
Zakary,Schiller,male,78
Zakary,Lehner,female,19
Zakary,Hodkiewicz,female,62
Zakary,Padberg,male,30
Zander,Runte,male,50
Zane,Little,female,59
Zaria,Reichert,male,55
Zaria,Towne,male,85
Zechariah,Wolff,female,60
Zechariah,Johnson,female,61
Zelma,Langworth,male,87
Zoe,Bernier,female,55
Zoe,Crona,male,32
Zoie,Waters,female,21
Zoila,Leffler,male,72
Zoila,Cummings,male,52
Loading