-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.js
More file actions
102 lines (89 loc) · 2.89 KB
/
data.js
File metadata and controls
102 lines (89 loc) · 2.89 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
102
function loadData(){
d3.queue()
//.defer(d3.json, "16-17.json")
//.defer(d3.json, "17-18.json")
.defer(d3.json, "term6.json")
.defer(d3.csv, "member.csv")
.await(ready);
function ready(error, dataTerm6, memberList){
console.log("Merge data: all votes in legco term 6 so far (up tp March 22th 2018)");
console.log(dataTerm6);
stats(dataTerm6, memberList);
}
}
function stats(data, memberList){
//meeting date list
var meetingDates = [];
var choiceOfMotion;
data["legcohk-vote"]['meeting'].forEach(function(d){
meetingDates.push(d['_start-date']);
})
console.log(meetingDates);
var numberOfVotes = 0;
data["legcohk-vote"]['meeting'].forEach(function(d){
//console.log(d);
numberOfVotes += d['vote'].length;
})
console.log("numberOfVotes: " + numberOfVotes);
//try absent times of lam cheuck ting
var memberName_en = "Tony TSE";
function createRecord(__name){//function to iterate record
var count = 0;
var abstainCount = 0;
var yesCount =0;
var noCount =0;
var absentCount =0;
var presentCount= 0;
var memberVotes = []; // to store one member's all vote
var memberRecord = {"_name-en":"", "_name-ch":"", "yes":0, "no":0, "absent":0, "abstain":0, "present":0, "count":0, "party_division": 0};
data["legcohk-vote"]['meeting'].forEach(function(d){
//meeting
d['vote'].forEach(function(d){
//vote
d["individual-votes"]["member"].forEach(function(d){
//member
/* general analysis
count++; // count every vote
if (d['vote'][0] === "Yes"){yesCount ++;}
else if (d['vote'][0] === "No"){noCount ++;}
else if (d['vote'][0] === "Absent"){absentCount ++;}
else if (d['vote'][0] === "Abstain"){abstainCount ++;}
else if (d['vote'][0] === "Present"){presentCount ++;}
else {console.log(d['vote'][0])}
*/
//console.log(d["_name-en"] + "," + d["_name-ch"]);
if (d["_name-en"] === __name){
memberVotes.push(d);
}
})
})
})
//console.log(memberVotes); see the member's all votes
memberRecord["_name-en"] = __name;
memberVotes.forEach(function(d){
if (d['vote'][0] === "Yes"){memberRecord["yes"] +=1;}
else if (d['vote'][0] === "No"){memberRecord["no"] +=1;}
else if (d['vote'][0] === "Absent"){memberRecord["absent"] +=1;}
else if (d['vote'][0] === "Abstain"){memberRecord["abstain"] +=1;}
else if (d['vote'][0] === "Present"){memberRecord["present"] +=1;}
memberRecord["count"] +=1;
});
//console.log(memberRecord);
return memberRecord;
/*
console.log("count: " + count);
console.log("yesCount: " + yesCount);
console.log("noCount: " + noCount);
console.log("abstainCount: " + abstainCount);
console.log("absentCount: " + absentCount);
console.log("presentCount: " + presentCount);
*/
}//function to iterate record
var recordList = [];
memberList.forEach(function(d){
recordList.push(createRecord(d["_name-en"]));
});
console.log(recordList);
//stringify json object
//console.log(JSON.stringify(recordList));
}