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

need feedback #20

Open
wants to merge 4 commits 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
725 changes: 725 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "poll-db-2",
"version": "1.0.0",
"description": "",
"main": "seed-data.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/platinum-fox-2017/poll-db-2.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/platinum-fox-2017/poll-db-2/issues"
},
"homepage": "https://github.com/platinum-fox-2017/poll-db-2#readme",
"dependencies": {
"sqlite3": "^3.1.13"
}
}
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 pollDB
Binary file not shown.
47 changes: 47 additions & 0 deletions seed-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('pollDB');

const fs = require ('fs');
var politicians = fs.readFileSync('politicians.csv','UTF-8')
.split('\n');
var voters = fs.readFileSync('voters.csv','UTF-8')
.split('\n');
var votes = fs.readFileSync('votes.csv','UTF-8')
.split('\n');

db.serialize(function() {
let insertPoliticians = db.prepare("INSERT INTO Politicians (name,party,location,gradeCurrent) VALUES (?,?,?,?)");
for (let i=1; i<politicians.length-1; i++){
let politician = politicians[i].split(',');
let nama = politician[0];
let party = politician[1];
let location = politician[2];
let gradeCurrent = politician[3];
insertPoliticians.run(nama,party,location,gradeCurrent);
}
insertPoliticians.finalize();

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

let insertVotes = db.prepare("INSERT INTO Votes (voterId,politicianId) VALUES (?,?)");
for (let i=1; i<votes.length-1; i++){
let vote = votes[i].split(',');
let voteId = vote[0];
let politicianId = vote[1];
insertVotes.run(voteId,politicianId);
}
insertVotes.finalize();
console.log('Insert All Data, Complete');

});

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

db.serialize(function() {
db.run("DROP TABLE IF EXISTS Politicians");

db.run("DROP TABLE IF EXISTS Voters");

db.run("DROP TABLE IF EXISTS Votes");

db.run("CREATE TABLE Politicians (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(50), party VARCHAR(2), location VARCHAR(2), gradeCurrent REAL)");

db.run("CREATE TABLE Voters (id INTEGER PRIMARY KEY AUTOINCREMENT, firstName VARCHAR(25), lastName VARCHAR(25), gender VARCHAR(10), age REAL)");

db.run("CREATE TABLE Votes (id INTEGER PRIMARY KEY AUTOINCREMENT, voterId INTEGER, politicianId INTEGER, FOREIGN KEY(voterId) REFERENCES Voters (id), FOREIGN KEY (politicianId) REFERENCES Politicians (id))");
});

db.close();
52 changes: 52 additions & 0 deletions view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const sqlite3 = require('sqlite3').verbose();
const db = new sqlite3.Database('pollDB');

db.serialize(function(){
// 1. nama politisi grade dibawah 9, urutkan asc
// db.all(`SELECT name,location,gradeCurrent,COUNT(*) AS totalVote
// FROM Votes
// JOIN Politicians on
// Votes.politicianId = Politicians.id
// WHERE gradeCurrent < 9
// GROUP BY name
// ORDER BY gradeCurrent ASC`,function(err, rows){
// if(err){
// console.log(err);
// } else {
// console.log(rows);
// }
// });

// 2. 3 politisi dengan vote terbanyak dan siapa saja yang memilih politisi tersebut
db.all(`SELECT totalVote, politicianName, firstName||' '||lastName AS voterName, gender, Three.id
FROM (SELECT count(*) AS totalVote, name AS politicianName, Politicians.id FROM Votes
JOIN Politicians ON Votes.politicianId = Politicians.id GROUP BY name ORDER BY totalVote DESC
LIMIT 3) AS Three
JOIN Votes ON Votes.politicianId = Three.id
JOIN Voters ON Voters.id = Votes.voterId
ORDER BY Three.id DESC`
, function(err,rows){
if(err){
console.log(err);
} else {
console.log(rows);
}
}); // belom selesai

// 3. orang curang vote >1
// db.all(`SELECT count(*) AS totalVote, firstName||' '||lastName AS name, gender, age
// FROM Votes
// JOIN Voters
// ON Voters.id = Votes.voterId
// GROUP BY name
// HAVING totalVote > 1
// ORDER BY totalVote DESC`, function(err,rows){
// if(err){
// console.log(err);
// } else {
// console.log(rows);
// }
// });
});

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