-
Notifications
You must be signed in to change notification settings - Fork 0
/
carparks-history.html
190 lines (167 loc) · 5.55 KB
/
carparks-history.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
<html>
<head>
<style>
body {padding:5px;}
tr {
border-bottom: 1px solid #ddd;
}
table {margin:10px;}
th {background-color:#eeeeff;}
tr:nth-child(even) {background-color: #f2f2f2;}
</style>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css" integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<script>
var chartColors = [
'rgba(230, 25, 75, 1)',
'rgba(60, 180, 75, 1)',
'rgba(255, 225, 25, 1)',
'rgba(0, 130, 200, 1)',
'rgba(245, 130, 48, 1)',
'rgba(145, 30, 180, 1)',
'rgba(70, 240, 240, 1)',
'rgba(240, 50, 230, 1)',
'rgba(210, 245, 60, 1)',
'rgba(250, 190, 190, 1)',
'rgba(0, 128, 128, 1)',
'rgba(230, 190, 255, 1)',
'rgba(170, 110, 40, 1)',
'rgba(255, 250, 200, 1)',
'rgba(128, 0, 0, 1)',
'rgba(170, 255, 195, 1)',
'rgba(128, 128, 0, 1)',
'rgba(255, 215, 180, 1)',
'rgba(0, 0, 128, 1)',
'rgba(128, 128, 128, 1)',
'rgba(75, 75, 75, 1)',
'rgba(0, 0, 0, 1)'
]
var GRAPHSIZE=144;
var SKIPFACTOR=1;
var xaxis = new Array(GRAPHSIZE);
var hourcount = 0;
for (var x = 1; x <= GRAPHSIZE; x++){
if (x%12==0){
hourcount++;
xaxis[GRAPHSIZE-x] = "-"+(hourcount*SKIPFACTOR)+" hrs";
} else {
xaxis[GRAPHSIZE-x] = '';
}
}
var config = {
type: 'line',
data: {
labels: xaxis,
datasets: [],
},
options: {
animation:false,
responsive: true,
title: {
display: false,
text: 'Nottingham Car Parks'
},
tooltips: {
mode: 'nearest',
intersect: false,
},
hover: {
mode: 'nearest',
intersect: true,
},
legend: {
position: 'bottom',
},
scales: {
xAxes: [{
display: true,
scaleLabel: {
display: false,
labelString: 'Month'
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: '% Full'
},
ticks: {
beginAtZero: true,
max: 100
}
}]
}
}
};
$(document).ready(function(){
$.ajaxSetup({ cache: false });
var ctx = document.getElementById('canvas').getContext('2d');
window.myLine = new Chart(ctx, config);
$.getJSON("./json-files/defstatus.json%3Ft=637135055585332792",function(result){
$.each(result.carParks.carPark, function(i, field){
var cpname = field.definition.parkingRecord.parkingRecord.parkingName.values.value["#text"];
var cpstatus = field.status.parkingRecord.parkingRecordStatus.parkingSiteStatus;
cpstatus = cpstatus.charAt(0).toUpperCase() + cpstatus.slice(1);
cpstatus = cpstatus.split(/(?=[A-Z])/).join(' ');
var cpfill = Math.round(parseFloat(field.status.parkingRecord.parkingRecordStatus.parkingOccupancy.parkingOccupancy));
$("table").append($("<tr>").append($("<td>").append(cpname)).append($("<td>").append(cpstatus)).append($("<td>").append(cpfill, "%")));
if (cpstatus!="Unknown") {
var newdata = new Array(GRAPHSIZE);
newdata[GRAPHSIZE-1] = cpfill;
var newDataset = {
label: cpname,//+" - "+cpfill+"% ("+cpstatus+")",
pointRadius:0,
backgroundColor: chartColors[i],
borderColor: chartColors[i],
data: newdata,
fill: false
};
config.data.datasets.push(newDataset);
}
});
window.myLine.update();
var loopcount;
for(loopcount = 1; loopcount<GRAPHSIZE; loopcount++ ) {
$.getJSON("./json-files/defstatus.json%3Ft=637135055585332792."+(loopcount*SKIPFACTOR),updategraph(loopcount));
}
});
});
function updategraph(myloopcount){
return function(returneddata){
var carparkcount = 0;
$.each(returneddata.carParks.carPark, function(i, field){
var cpfill = Math.round(parseFloat(field.status.parkingRecord.parkingRecordStatus.parkingOccupancy.parkingOccupancy));
var cpstatus = field.status.parkingRecord.parkingRecordStatus.parkingSiteStatus;
if (cpstatus!="unknown") {
config.data.datasets[carparkcount].data[GRAPHSIZE-1-myloopcount] = cpfill;
carparkcount++;
}
});
window.myLine.update();
};
}
</script>
</head>
<body>
<h1 style='text-align:center;'>Nottingham Carparks</h1>
<canvas id="canvas" width="400" height="200"></canvas>
<script>
</script>
<p><b>Based on data from <a href='https://www.opendatanottingham.org.uk/'>Open Data Nottingham</a></b></p>
<p><b>Please note: data for Talbot St, Wollaton St, and Nottingham Train Station car parks are broken (fixed at 0%, 0%, and 17% respectively). Car parks with a recorded status of "Unknown" are not showing in the line graph.</b></p>
<table width="90%">
<tr>
<th width="50%">Carpark Name</th>
<th width="20%">Official Status</th>
<th width="20%">% Full</th>
</tr>
</table>
</body>
</html>