Skip to content

Commit

Permalink
Merge pull request #320 from SmartCambridge/jw35-fix-carpark-capacity-2
Browse files Browse the repository at this point in the history
Fix capacity annotation on car park graphs
  • Loading branch information
Jon Warbrick authored May 30, 2019
2 parents 44a307d + 1221d9f commit 94dfebe
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 38 deletions.
1 change: 0 additions & 1 deletion tfc_web/parking/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class ParkingConfigSerializer(serializers.Serializer):
parking_id = serializers.CharField()
parking_name = serializers.CharField()
parking_type = serializers.CharField()
spaces_capacity = serializers.IntegerField(source='capacity')


class ParkingListSerializer(serializers.Serializer):
Expand Down
79 changes: 43 additions & 36 deletions tfc_web/parking/templates/parking/parking_plot.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@

var parking_config = JSON.parse('{{ config_parking_config|escapejs }}');

try {
// **********************************************************************************
// ********** Here is where we load the parking plot data ***********************
// **********************************************************************************
var json_data = JSON.parse("{{ config_parking_data|escapejs }}");
// **********************************************************************************
// **********************************************************************************
// **********************************************************************************
if (!json_data)
{
console.log('no parking data received');
}
} catch(err) {
console.log('error parsing config_parking_data '+err);
rita_data = new Array();
}


var YYYYMMDD = '{{config_YYYY}}/{{config_MM}}/{{config_DD}}';
//********************************************************************************
//********************************************************************************
Expand Down Expand Up @@ -211,13 +229,15 @@

heading_date.textContent = day_of_week[plot_date.getDay()] + " " + DD + " " + month_of_year[MM] + " " + YYYY;

// get max occupancy for this car park from parking_config and adjust CHART_Y_MAX
try {
parking_capacity = parking_config.request_data.capacity;
console.log('Capacity of this car park is: '+parking_capacity);
CHART_Y_MAX = (1.2 * parking_capacity);
document.getElementById('parking_capacity').innerHTML = "(max "+parking_capacity+")";
} catch (err) {
// get max occupancy for this car park from the final occupancy record
// for the day the graph is being drawn

if (json_data && json_data[0].request_data.length > 0) {
final_record = json_data[0].request_data[json_data[0].request_data.length-1]
parking_capacity = final_record.spaces_capacity
console.log('Capacity of this car park is: '+parking_capacity);
CHART_Y_MAX = (1.2 * parking_capacity);
document.getElementById('parking_capacity').innerHTML = "(max "+parking_capacity+")";
}

// ******************************************************
Expand All @@ -231,41 +251,28 @@

// Initialize data structure to hold parking occupancy messages inserted by server
// And call draw_chart for each day's data
try {
// **********************************************************************************
// ********** Here is where we load the parking plot data ***********************
// **********************************************************************************
var json_data = JSON.parse("{{ config_parking_data|escapejs }}");
// **********************************************************************************
// **********************************************************************************
// **********************************************************************************
if (!json_data)
{
console.log('no parking data received');
}
else



if (json_data)
{
console.log('Rendering '+json_data.length+' days of data');

// note we draw requested day's data last so it is on top...
for (i=json_data.length-1;i>=0;i--)
{
console.log('Rendering '+json_data.length+' days of data');
rita_data = json_data[i].request_data;
console.log('Day '+i+': Received '+rita_data.length+' records');

// note we draw requested day's data last so it is on top...
for (i=json_data.length-1;i>=0;i--)
if (rita_data.length > 0)
{
rita_data = json_data[i].request_data;
console.log('Day '+i+': Received '+rita_data.length+' records');

if (rita_data.length > 0)
{
console.log('Day '+i+': init calling draw_chart()');
console.log('Day '+i+': init calling draw_chart()');

// draw chart with the data embedded by the template into rita_data
draw_chart(rita_data, i);
}
console.log('Day '+i+': rita_data.length is '+rita_data.length);
// draw chart with the data embedded by the template into rita_data
draw_chart(rita_data, i);
}
console.log('Day '+i+': rita_data.length is '+rita_data.length);
}
} catch(err) {
console.log('error parsing config_parking_data '+err);
rita_data = new Array();
}

}
Expand Down
1 change: 0 additions & 1 deletion tfc_web/parking/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def get_parking_metadata(parking_id):

data = do_api_call('/api/v1/parking/' + parking_id)
# Fix for change between old and new API field names
data['capacity'] = data['spaces_capacity']
return {'request_data': data}


Expand Down

0 comments on commit 94dfebe

Please sign in to comment.