-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject2.html
119 lines (95 loc) · 3.32 KB
/
Project2.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
<!DOCTYPE html>
<html>
<head>
<meta charset = "UTF-8" />
<script src = "http://maps.google.com/maps/api/js?sensor=true"></script>
<!-- <script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src = "http://maps.google.com/maps/api/js"> </script> -->
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
</head>
<body>
<script>
var myroutes;
function calculateRoute(from, to)
{
var directionsService = new google.maps.DirectionsService();
var directionsRequest = {
origin: from,
destination: to,
travelMode: google.maps.DirectionsTravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.IMPERIAL
};
directionsService.route(directionsRequest, function(response, status)
{
if (status == google.maps.DirectionsStatus.OK)
{
// new google.maps.DirectionsRenderer({
// //map: mapObject,
// directions: response
// });
myroutes= (response.routes[0]).overview_path;
}
else
{
console.log("no route found");
//$("#error").append("Unable to retrieve your route<br />");
}
}
);
}
var nyc_speed_limit= 30;
// var pickup_lat, pickup_long, dropoff_lat, dropoff_long, trip_time, trip_distance, date, start_time, am_pm,
var pickup, dropoff, time_in_hours, curr_speed;
//d3.csv("trip_data_january.csv", function(d) {
d3.csv("TEST2.csv", function(d) {
return {
pickup_lat: +d.pickup_latitude,
pickup_long: +d.pickup_longitude,
dropoff_lat: +d.dropoff_latitude,
dropoff_long: +d.dropoff_longitude,
trip_time: +d.trip_time_in_secs,
trip_distance: +d.trip_distance,
date: d.trip_date,
start_time: d.trip_start,
am_pm: d.trip_tod
};
}, function(error, rows) {
console.log(rows);
for (var k = 0; k < rows.length; k++) {
//if time of day is pm, add 12 hours to time help distinguish between am or pm
if(rows[k].am_pm == "PM")
{
//get hour value
var index_of = rows[k].start_time.indexOf(":");
//console.log(index_of);
var hour_str = rows[k].start_time.substring(0, index_of);
//console.log(hour_str);
var rest = rows[k].start_time.substring(index_of);
//console.log(rest);
//convert hour to int
var hour_int = parseInt(hour_str);
//add 12 hours
hour_int = hour_int + 12;
//convert back to string
hour_str = hour_int.toString();
//concatenate with seconds to obtain start_time
start_time = hour_str.concat(rest);
}
pickup = new google.maps.LatLng(rows[k].pickup_lat, rows[k].pickup_long, true);
dropoff = new google.maps.LatLng(rows[k].dropoff_lat,
rows[k].dropoff_long, true);
calculateRoute(pickup, dropoff);
//Note to Gabby: myroutes contains an array of LatLngs representing the entire course of this route. Array<LatLng>
time_in_hours= rows[k].trip_time/3600;
curr_speed = rows[k].trip_distance/time_in_hours;
//plotTraffic();
}
});
//console.log(myroutes);
// console.log(time_in_hours);
// console.log(curr_speed);
function plotTraffic(){}
</script>
<p id="error"></p>
</body>
</html>