forked from bmlt-enabled/usa-tally
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphoneline.html
169 lines (153 loc) · 6.73 KB
/
phoneline.html
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE html>
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=Droid+Sans' rel='stylesheet' type='text/css'>
<style>
body {
font-family: "Droid Sans";
}
</style>
</head>
<body>
<div align="center" style="margin-top: 20px;">
<h1>USA Nationwide Phone Number</h1>
<div style="display: block">
<span id="current-count"></span> currently of <span id="truth-count"></span> (~<span id="pct-total"></span>%) possible service body volunteer targets in the USA are available.
<div>This list does not include areas that are not yet on the BMLT in the USA.</div>
<div id="tally" style="margin-top: 20px"></div>
</div>
<h5>
<div style="margin-top: 20px;">Areas with found with 0 meetings: <br><span id="areas-with-no-meetings"></span></div>
</h5>
</div>
</body>
<script src="croutonjs/crouton.min.js"></script>
<script type="text/javascript">
var lastYearOfTruth = 2020;
var tomatoResults = [];
var serviceBodiesDetails;
var truth;
var useTomatoStub = false;
var activePhoneNumbersCount = 0;
var totalServiceBodyTargets = 0;
var tallyHtml = "";
var areasWithNoMeetings = "";
function getServiceBodyById(id) {
for (var i = 0; i < tomatoResults.length; i++) {
var service_body = tomatoResults[i];
if (service_body['url'] === id) {
return service_body;
}
}
return null;
}
function getServiceBodyDetailsByIdInt(id) {
for (var i = 0; i < serviceBodiesDetails.length; i++) {
var service_body = serviceBodiesDetails[i];
if (service_body['id'] === id) {
return service_body;
}
}
}
function getChildrenForParent(id) {
var children = [];
for (var i = 0; i < serviceBodiesDetails.length; i++) {
var service_body = serviceBodiesDetails[i];
if (service_body['parent_id'] === id) {
children.push(service_body);
}
}
return children;
}
function appendServiceBodyInfo(tomatoIdInt, serviceBodyParentName, serviceBodyName, phoneNumber, num_meetings) {
if (num_meetings > 0) {
tallyHtml += "<tr><td>" + tomatoIdInt + "</td>";
tallyHtml += "<td>" + serviceBodyParentName + "</td>";
tallyHtml += "<td>" + serviceBodyName + "</td>";
tallyHtml += "<td>" + phoneNumber + "</td>";
tallyHtml += "<td>" + num_meetings + "</td></tr>";
if (phoneNumber !== "") activePhoneNumbersCount++;
totalServiceBodyTargets++;
} else {
areasWithNoMeetings += serviceBodyName + " (" + serviceBodyParentName + ")<br>";
}
}
function appendChildren(tomatoIdInt, serviceBodyParentName) {
var children = getChildrenForParent(tomatoIdInt);
for (var c = 0; c < children.length; c++) {
var child = children[c];
if (child['type'] === "AS") {
var serviceBodyInfo = getServiceBodyById("https://tomato.bmltenabled.org/rest/v1/servicebodies/" + child['id'] + "/")
if (serviceBodyInfo === null) {
console.log(child['id'])
}
appendServiceBodyInfo(
child['id'],
serviceBodyParentName,
child['name'],
child['helpline'],
serviceBodyInfo['num_meetings']
);
} else {
appendChildren(child['id'], serviceBodyParentName);
}
}
}
function getServiceBodiesFromTomato(page, payload, callback) {
if (payload == null) {
payload = []
}
$.getJSON(useTomatoStub ? "tally/tomatoStub.json" : "https://tomato.bmltenabled.org/rest/v1/servicebodies/?page=" + page, function (data) {
payload = payload.concat(data['results']);
if (data['next'] !== null) {
getServiceBodiesFromTomato(++page, payload, callback)
} else {
callback(payload);
}
});
}
function getTomatoData() {
$.ajaxSetup({timeout:30000});
getServiceBodiesFromTomato(1, null, function(data) {
tomatoResults = data;
$.getJSON(useTomatoStub ? "tally/serviceBodiesDetailsStub.json" : "https://tomato.bmltenabled.org/main_server/client_interface/json/?switcher=GetServiceBodies", function(data) {
serviceBodiesDetails = data;
tallyHtml = "<table border='1'><tr><th>TomatoId</th><th>Parent</th><th>Service Body</th><th>Phone Number</th><th>Meetings</th></tr>";
for (var j = 0; j < truth.length; j++) {
var truthItem = truth[j];
for (var t = 0; t < truthItem['tomatoIds'].length; t++) {
var tomatoId = truthItem['tomatoIds'][t];
var tomatoServiceBody = getServiceBodyById(tomatoId);
if (tomatoServiceBody != null) {
var tomatoIdInt = tomatoServiceBody['url'].match(".*\/servicebodies\/([0-9]*)\/")[1];
var serviceBodyDetail = getServiceBodyDetailsByIdInt(tomatoIdInt);
if (serviceBodyDetail['type'] === "RS") {
var serviceBodyParentName = serviceBodyDetail['name'];
appendChildren(tomatoIdInt, serviceBodyParentName);
} else if (serviceBodyDetail['type'] === "AS") {
appendServiceBodyInfo(
tomatoIdInt,
"",
tomatoServiceBody['name'],
serviceBodyDetail['helpline'],
tomatoServiceBody['num_meetings']
);
}
}
}
}
tallyHtml += "</table>";
document.getElementById("tally").innerHTML = tallyHtml;
document.getElementById("current-count").innerText = activePhoneNumbersCount.toString();
document.getElementById("truth-count").innerText = totalServiceBodyTargets.toString();
document.getElementById("pct-total").innerText = Math.ceil((activePhoneNumbersCount / totalServiceBodyTargets) * 100).toString()
document.getElementById("areas-with-no-meetings").innerHTML = areasWithNoMeetings;
});
});
}
$.getJSON("tally/" + lastYearOfTruth + ".json", function(data) {
truth = data;
getTomatoData()
});
</script>
</html>