-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
449 lines (403 loc) · 13.8 KB
/
index.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<!DOCTYPE html>
<!--
author: Joshua Giardino
license: Affero GPL
purpose: Quick Analysis of Foursquare Venue Search API for a given lat & long.
-->
<!--[if IE 9]><html class="lt-ie10" lang="en" > <![endif]-->
<html class="no-js" lang="en" >
<head>
<title>FourSquare API Dashboard Demo</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/foundation.css">
<link rel="stylesheet" href="css/jquery.jqplot.min.css">
<link href="css/no-theme/jquery-ui-1.10.3.custom.min.css" rel="stylesheet">
<script type="text/javascript" src="js/vendor/modernizr.js"></script>
<script type="text/javascript" src="js/vendor/jquery.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.10.3.custom.min.js"></script>
<script type="text/javascript" src="js/foundation.min.js"></script>
<script type="text/javascript" src="js/jquery.jqplot.min.js"></script>
<script type="text/javascript" src="js/plugins/jqplot.canvasAxisLabelRenderer.min.js"></script>
<script type="text/javascript" src="js/plugins/jqplot.canvasTextRenderer.min.js"></script>
<script type="text/javascript" src="js/plugins/jqplot.dateAxisRenderer.min.js"></script>
<script type="text/javascript" src="js/plugins/jqplot.canvasAxisTickRenderer.min.js"></script>
<script type="text/javascript" src="js/plugins/jqplot.categoryAxisRenderer.min.js"></script>
<script type="text/javascript" src="js/plugins/jqplot.pieRenderer.min.js"></script>
<script type="text/javascript" src="js/plugins/jqplot.donutRenderer.min.js"></script>
<script type="text/javascript" src="js/plugins/jqplot.barRenderer.min.js"></script>
<style media="screen" type="text/css">
.jqplot-data-label{color:#000000;}
</style>
</head>
<body>
<div>
<div class="row">
<div class="small-12 columns">
<h3 class="small">Foursquare Search Results For: 37.562992, -122.325525</h3>
</div>
</div>
<div class="row">
<div class="small-12 columns">
<hr />
</div>
</div>
<div class="row">
<div class="small-12 columns" align="center">
<p>
<div id="recordCount"></div>
<strong>Known Venues</strong>
</p>
</div>
</div>
<div class="row">
<div class="small-12 columns">
<hr />
</div>
</div>
<div class="row">
<div class="small-12 columns" align="center">
<p><strong>Number of Unique Venues by Search Intent</strong></p>
</div>
</div>
<div class="row">
<div class="small-12 medium-6 medium-push-6 columns">
<div id="barChart"></div>
</div>
<div class="small-12 medium-6 medium-pull-6 columns">
<p><strong>Legend:</strong></p>
<div class="row">
<div class="small-1 columns"><div style="height:15px; width:15px; background-color:#f04124"></div></div>
<div class="small-11 columns">Unique Venues from "Checkin" Intent Search</div>
</div>
<div class="row">
<div class="small-12">
<hr />
</div>
</div>
<div class="row">
<div class="small-1 columns"><div style="height:15px; width:15px; background-color:#008cba"></div></div>
<div class="small-11 columns">Unique Venues from "Browse" Intent Search</div>
</div>
<div class="row">
<div class="small-12">
<hr />
</div>
</div>
<div class="row">
<div class="small-1 columns"><div style="height:15px; width:15px; background-color:#aaaaaa"></div></div>
<div class="small-11 columns">Shared Venues occuring in both searches</div>
</div>
</div>
</div>
<div class="row">
<div class="small-12 columns">
<hr />
</div>
</div>
<div class="row">
<div class="small-12 columns" align="center">
<p><strong>Ratio of Unique Venues by Search Intent</strong></p>
</div>
</div>
<div class="row">
<div class="small-12 medium-6 columns">
<div id="pieChart"></div>
</div>
<div class="small-12 medium-6 columns">
<p><strong>Legend:</strong></p>
<div class="row">
<div class="small-1 columns"><div style="height:15px; width:15px; background-color:#f04124"></div></div>
<div class="small-11 columns">Unique Venues from "Checkin" Intent Search</div>
</div>
<div class="row">
<hr />
</div>
<div class="row">
<div class="small-1 columns"><div style="height:15px; width:15px; background-color:#008cba"></div></div>
<div class="small-11 columns">Unique Venues from "Browse" Intent Search</div>
</div>
<div class="row">
<hr />
</div>
<div class="row">
<div class="small-1 columns"><div style="height:15px; width:15px; background-color:#aaaaaa"></div></div>
<div class="small-11 columns">Shared Venues occuring in both searches</div>
</div>
</div>
</div>
<div class="row">
<div class="small-12 columns">
<hr />
</div>
</div>
<div class="row">
<div class="small-12 columns" align="center">
<p><strong>Table of Venues Returned with Search Intent</strong></p>
</div>
</div>
<div class="row">
<div class="small-12 large-12 large-centered columns">
<div id="tableData"></div>
</div>
</div>
</div>
<!-- body content here -->
<script language="javascript" type="text/javascript">
// foundation ui-kit instantiation
$(document).foundation();
// 4square api credentials
var id = '';
var secret = '';
var loc = '37.562992,-122.325525';
// array for holding venue data
var venueData = new Array();
// venue counts object
var venueCounts = new Object();
// to handle searches of an array of objects
function findObjectByProperty(arr, needle, propertyName) {
for(element in arr)
{
if(arr[element][propertyName] === needle)
{
// return array id of element that is first match
return element;
}
}
// else return -1
return -1;
};
// 4square api venue search w/ checkin intent
function fetchCheckinIntent(id,secret,loc)
{
var base = 'https://api.foursquare.com/v2/';
var endpoint = 'venues/search';
var query = '?ll=' + loc + '&client_id=' + id + '&client_secret=' + secret + '&intent=checkin&v=20140312&limit=50';
var url = base + endpoint + query;
url = 'proxy.php?q=' + encodeURIComponent(url);
$.ajax({
url: url,
dataType:"json",
success: function(data) {
venues = data.response.venues;
//window.console.log(venues);
venueCounts.CheckinTotal = venues.length;
venueCounts.CheckinUnique = venues.length;
for(i in venues)
{
thisVenue = new Object();
thisVenue.id = venues[i].id;
thisVenue.name = venues[i].name;
thisVenue.intents = new Array();
thisVenue.intents.push("checkin");
venueData.push(thisVenue);
};
window.console.log(venueData);
fetchBrowseIntent(id,secret,loc);
},
});
};
// 4square api venue search w/ browse intent
function fetchBrowseIntent(id,secret,loc)
{
var base = 'https://api.foursquare.com/v2/';
var endpoint = 'venues/search';
var query = '?ll=' + loc + '&client_id=' + id + '&client_secret=' + secret + '&intent=browse&radius=100000&v=20140312&limit=50';
var url = base + endpoint + query;
url = 'proxy.php?q=' + encodeURIComponent(url);
$.ajax({
url: url,
dataType:"json",
success: function(data) {
window.console.log(data);
var venues = data.response.venues;
venueCounts.BrowseTotal = venues.length;
venueCounts.BrowseUnique = 0;
for(i in venues)
{
var tmpId = findObjectByProperty(venueData,venues[i].id,"id");
if(tmpId > -1)
{
venueData[tmpId].intents.push("browse");
venueCounts.CheckinUnique = venueCounts.CheckinUnique - 1;
} else {
thisVenue = new Object();
thisVenue.id = venues[i].id;
thisVenue.name = venues[i].name;
thisVenue.intents = new Array();
thisVenue.intents.push("browse");
venueData.push(thisVenue);
venueCounts.BrowseUnique = venueCounts.BrowseUnique + 1;
};
};
//fetchMatchIntent(id,secret,loc);
displayStats();
},
});
};
/*
// 4square api venue search w/ match intent
function fetchMatchIntent(id,secret,loc)
{
var base = 'https://api.foursquare.com/v2/';
var endpoint = 'venues/search';
var query = '?ll=' + loc + '&client_id=' + id + '&client_secret=' + secret + '&intent=match&query=a&v=20140312&limit=50';
var url = base + endpoint + query;
url = 'proxy.php?q=' + encodeURIComponent(url);
$.ajax({
url: url,
dataType:"json",
success: function(data) {
window.console.log(data);
var venues = data.response.venues;
venueCounts.MatchTotal = venues.length;
venueCounts.MatchUnique = 0;
for(i in venues)
{
var tmpId = findObjectByProperty(venueData,venues[i].id,"id");
if(tmpId > -1)
{
venueData[tmpId].intents.push("match");
if(venueData[tmpId].intents.find("browse") > -1)
{
if(venueCounts.BrowseUnique > 0)
{
venueCounts.BrowseUnique = venueCounts.BrowseUnique -1;
}
}
if(venueData[tmpId].intents.find("checkin") > -1)
{
if(venueCounts.CheckinUnique > 0)
{
venueCounts.CheckinUnique = venueCounts.CheckinUnique -1;
}
}
} else {
thisVenue = new Object();
thisVenue.id = venues[i].id;
thisVenue.name = venues[i].name;
thisVenue.intents = new Array();
thisVenue.intents.push("match");
venueData.push(thisVenue);
};
};
displayStats();
},
});
};
*/
function displayStats()
{
var count = venueData.length;
$('#recordCount').append("<div style=\"font-size:48px; color:#f04124; font-weight:bold;\">" + count.toString() + "</div>");
generatePie(venueCounts,count);
generateBar(venueCounts,count);
generateTable(venueData);
};
function generatePie(venueCounts,totalCount)
{
var data = [['Checkin Intent',venueCounts.CheckinUnique],['Browse Intent',venueCounts.BrowseUnique],['Shared Venues',totalCount-(venueCounts.CheckinUnique+venueCounts.BrowseUnique)]];
var plot1 = jQuery.jqplot('pieChart', [data],
{
seriesColors:['#f04124','#008cba','#aaa'],
seriesDefaults: {
// Make this a pie chart.
renderer: jQuery.jqplot.PieRenderer,
rendererOptions: {
// Put data labels on the pie slices.
// By default, labels show the percentage of the slice.
showDataLabels: true
}
},
legend: {
show:false, location: 'e'
},
grid: {
drawGridLines: true, // wether to draw lines across the grid or not.
gridLineColor: '#cccccc', // *Color of the grid lines.
background: '#ffffff', // CSS color spec for background color of grid.
borderColor: '#ffffff', // CSS color spec for border around grid.
borderWidth: 0.0, // pixel width of border around grid.
shadow: false,
},
});
$(window).resize(function() {
plot1.replot({ resetAxes: true });
});
}
function generateBar(venueCounts,totalCount)
{
var data = [[venueCounts.CheckinUnique],[venueCounts.BrowseUnique],[totalCount-(venueCounts.CheckinUnique+venueCounts.BrowseUnique)]]
// Can specify a custom tick Array.
// Ticks should match up one for each y value (category) in the series.
var plot2 = $.jqplot('barChart', data, {
// The "seriesDefaults" option is an options object that will
// be applied to all series in the chart.
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
rendererOptions: {fillToZero: true}
},
// Custom labels for the series are specified with the "label"
// option on the series option. Here a series option object
// is specified for each series.
seriesColors:['#f04124','#008cba','#aaa'],
legend: {
show: false,
},
axes: {
// Use a category axis on the x axis and use our custom ticks.
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
ticks: ["API Search"],
},
// Pad the y axis just a little so bars can get close to, but
// not touch, the grid boundaries. 1.2 is the default padding.
yaxis: {
pad: 1.05,
}
},
grid: {
drawGridLines: true, // wether to draw lines across the grid or not.
gridLineColor: '#cccccc', // *Color of the grid lines.
background: '#ffffff', // CSS color spec for background color of grid.
borderColor: '#cccccc', // CSS color spec for border around grid.
borderWidth: 0.0, // pixel width of border around grid.
shadow: false,
},
});
$(window).resize(function() {
plot2.replot({ resetAxes: true });
});
}
function generateTable(venueData)
{
var output = "<table width=\"100%\">";
output = output + "<thead><tr>";
output = output + "<th>#</th>";
output = output + "<th>Venue Name</th>";
output = output + "<th>Venue Intent</th>";
output = output + "</tr></thead>";
for(i in venueData)
{
var name = venueData[i].name;
var id = parseInt(i)+1;
var intents = '';
for(x in venueData[i].intents)
{
intents = intents + venueData[i].intents[x] + '<br />';
}
output = output + "<tr><td>";
output = output + id.toString();
output = output + "</td><td>";
output = output + name + "</td><td>";
output = output + intents + "</td>";
output = output + "</td></tr>";
};
output = output + "</table>";
$('#tableData').append(output);
}
fetchCheckinIntent(id,secret,loc);
</script>
</body>
</html>