Skip to content

Commit c9d3bd6

Browse files
added flight duration in the path infobox
1 parent 20308e6 commit c9d3bd6

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

js/app.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,21 @@ var updateTimebox = function(date) {
308308
elm.find(".local").text("Local: "+a+'-'+b+'-'+c+' '+e+':'+f+':'+g+" UTC"+((z<0)?"-":"+")+z);
309309
}
310310

311+
var format_time_friendly = function(start, end) {
312+
var dt = Math.floor((end - start) / 1000);
313+
if(dt < 0) return null;
314+
315+
if(dt < 60) return dt + 's';
316+
else if(dt < 3600) return Math.floor(dt/60)+'m';
317+
else if(dt < 86400) {
318+
dt = Math.floor(dt/60);
319+
return Math.floor(dt/60)+'h '+(dt % 60)+'m';
320+
} else {
321+
dt = Math.floor(dt/3600);
322+
return Math.floor(dt/24)+'d '+(dt % 24)+'h';
323+
}
324+
}
325+
311326
// runs every second
312327
var updateTime = function(date) {
313328
// update timebox
@@ -322,18 +337,8 @@ var updateTime = function(date) {
322337
elm.each(function(k,v) {
323338
var e = $(v);
324339
var ts = e.attr('data-timestamp');
325-
var dt = Math.floor((now - ts) / 1000);
326-
if(dt < 0) return;
327-
328-
if(dt < 60) e.text(dt+'s ago'); // less than a minute
329-
else if(dt < 3600) e.text(Math.floor(dt/60)+'m ago'); // less than an hour
330-
else if(dt < 86400) { // less than a day
331-
dt = Math.floor(dt/60);
332-
e.text(Math.floor(dt/60)+'h '+(dt % 60)+'m ago');
333-
} else {
334-
dt = Math.floor(dt/3600); // hours
335-
e.text(Math.floor(dt/24)+'d '+(dt % 24)+'h ago');
336-
}
340+
var str = format_time_friendly(ts, now);
341+
if(str) e.text(str + ' ago');
337342
});
338343
}
339344
}

js/tracker.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,9 @@ var mapInfoBox_handle_path = function(event) {
867867
value = Math.round(value/10)/100 + " km";
868868
}
869869

870-
mapInfoBox.setContent("<pre><b>Length:</b> " + value + "</pre>");
870+
var duration = ("vehicle" in this) ? "\n<b>Duration:</b> " + format_time_friendly(this.vehicle.start_time, convert_time(this.vehicle.curr_position.gps_time)) : '';
871+
872+
mapInfoBox.setContent("<pre><b>Length:</b> " + value + duration + "</pre>");
871873
mapInfoBox.setPosition(event.latLng);
872874
mapInfoBox.open(map);
873875
}
@@ -1070,7 +1072,8 @@ function addPosition(position) {
10701072
graph_data_updated: false,
10711073
graph_data: [],
10721074
graph_yaxes: [],
1073-
updated: false
1075+
updated: false,
1076+
start_time: 2147483647000
10741077
};
10751078

10761079
// deep copy yaxes config for graph
@@ -1193,6 +1196,12 @@ function addPosition(position) {
11931196
vehicle.curr_position = position;
11941197
}
11951198

1199+
// record the start of flight
1200+
var newts = convert_time(vehicle.curr_position.gps_time);
1201+
if(newts < vehicle.start_time) {
1202+
vehicle.start_time = newts;
1203+
}
1204+
11961205
// record the highest altitude
11971206
if(parseFloat(position.gps_alt) > vehicle.max_alt) {
11981207
vehicle.max_alt = parseFloat(position.gps_alt);

0 commit comments

Comments
 (0)