Skip to content

Commit

Permalink
tracking view
Browse files Browse the repository at this point in the history
  • Loading branch information
strukturart committed Sep 16, 2023
1 parent e09c76c commit 5d3eb4f
Show file tree
Hide file tree
Showing 12 changed files with 312 additions and 162 deletions.
24 changes: 1 addition & 23 deletions application/assets/css/grid.css
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@
flex-direction: column;
}


.justify-content-start {
-webkit-align-items: flex-start;
align-items: flex-start;
Expand Down Expand Up @@ -562,6 +561,7 @@

.width-50 {
min-width: 50%;
max-width: 50%;
}

.width-30 {
Expand All @@ -573,28 +573,6 @@
transform: translate(50%, -0%);
}

.col-3 {
-webkit-column-count: 3;
-moz-column-count: 3;
column-count: 3;
-webkit-column-count: 3;
-webkit-column-gap: 30px;
-moz-column-count: 3;
-moz-column-gap: 30px;
column-count: 3;
column-gap: 30px;
}

.col-dont-break-inside {
-webkit-column-break-inside: avoid;
/* Chrome, Safari, Opera */
page-break-inside: avoid;
/* Firefox */
break-inside: avoid;
/* IE 10+ */
}

.block {
display: block;
}

36 changes: 34 additions & 2 deletions application/assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ html,
body {
font-family: "Lato-Regular";
font-weight: 100;
width: 100%;
position: relative;
margin: 0px;
padding: 0px;
font-size: 0.95rem;
line-height: 1.4rem;
-webkit-appearance: none;
scroll-behavior: smooth;
height: 100%;
margin: 0;
Expand Down Expand Up @@ -903,3 +901,37 @@ div#osm-upload-panel {
display: none;
padding: 10px;
}

div#tracking-view {
max-width: 100vw;
min-height: 100vh;
position: absolute;
z-index: 15;
left: 0;
top: 0;
background: black;
color: white;
font-size: 14px;
padding: 5px;
display: none;
}

div#tracking-view div {
outline: 2px solid white;
position: relative;
padding: 3px;
}
div#tracking-view div div {
outline: 0px solid white;
font-size: 1.2rem;
height: 20px;
}

div#tracking-view div span {
position: absolute;
left: 0px;
top: 0px;
width: 100%;
text-align: center;
font-size: 0.7rem;
}
150 changes: 99 additions & 51 deletions application/assets/js/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ const module = (() => {
}
if (general.measurement_unit == "mil") {
dis = dis / 1000;
let dis = dis / 1.60934;
dis = dis / 1.60934;
}
return dis;
};
Expand Down Expand Up @@ -617,32 +617,38 @@ const module = (() => {
////PATH & TRACKING
///////////////////

//calculation of altitude ascents and descents
let elevation = function (t) {
let up_e = 0;
let down_e = 0;
//calc gain & loss
function calculateGainAndLoss(altitudes, threshold) {
let gain = 0;
let loss = 0;
let previousValidAltitude = null;

for (let i = 1; i < t.length; i++) {
if (t[i] === null || t[i - 1] === null) {
// Skip null values
continue;
}
for (let i = 0; i < altitudes.length; i++) {
const currentAltitude = altitudes[i];

const diff = t[i] - t[i - 1];
if (Math.abs(diff) > 15) {
// The GPS data is too inaccurate; skip this point
// Skip null or inaccurate altitude values
if (currentAltitude === null || isNaN(currentAltitude)) {
continue;
}
if (diff > 0) {
up_e += diff;
} else if (diff < 0) {
down_e -= diff;

if (previousValidAltitude !== null) {
const altitudeDifference = currentAltitude - previousValidAltitude;

if (Math.abs(altitudeDifference) <= threshold) {
if (altitudeDifference > 0) {
gain += altitudeDifference;
} else {
loss -= altitudeDifference; // Convert negative difference to positive for loss
}
}
}

previousValidAltitude = currentAltitude;
}
let r = { up: up_e, down: down_e };

return r;
};
return { gain, loss };
}

//json to gpx
let toGPX = function () {
let e = tracking_group.toGeoJSON();
Expand All @@ -655,8 +661,6 @@ const module = (() => {
};

function isDivisible(number, divisor) {
console.log(number, divisor);
console.log(number % divisor);
return number % divisor === 0;
}

Expand Down Expand Up @@ -687,6 +691,45 @@ const module = (() => {
tracking_group
);

let update_tracking_view = () => {
document.querySelector("#tracking-view .duration div").innerText =
tracking.duration;

document.querySelector("#tracking-view .distance div").innerText =
tracking.distance;

document.querySelector("#tracking-view .gain div").innerText = isNaN(
tracking.gain
)
? "-"
: tracking.gain;

document.querySelector("#tracking-view .loss div").innerText = isNaN(
tracking.loss
)
? "-"
: tracking.loss;

document.querySelector("#tracking-view .altitude div").innerText = isNaN(
tracking.altitude
)
? "-"
: tracking.altitude;

document.querySelector("#tracking-view .average-speed div").innerText =
isNaN(tracking.speed_average) ? "-" : tracking.speed_average;

document.querySelector("#tracking-evo-down span").innerText = tracking.loss;
document.querySelector("#tracking-evo-up span").innerText = tracking.gain;
document.getElementById("tracking-altitude").innerText = tracking.altitude;

document.querySelector("#tracking-speed-average-time").innerText =
tracking.speed_average;

document.querySelector("div#tracking-distance").innerText =
tracking.distance;
};

const measure_distance = function (action) {
if (action == "destroy") {
status.path_selection = false;
Expand Down Expand Up @@ -730,7 +773,6 @@ const module = (() => {
status.tracking_running = true;

if ("requestWakeLock" in navigator) {
// gps_lock = window.navigator.requestWakeLock("gps");
if (setting.tracking_screenlock) screenWakeLock("lock", "screen");
}

Expand Down Expand Up @@ -768,18 +810,17 @@ const module = (() => {
}
}
let lastIntegerPart = 0;
k = 0.8;
tracking_interval = setInterval(function () {
if (mainmarker.accuracy > 10000) return false;
// Only record data if accuracy is high enough
if (mainmarker.accuracy > 10000) return false;

//store time
let ts = new Date();
tracking_timestamp.push(ts.toISOString());
//store altitude
let alt = 0;

let alt = "";
if (mainmarker.device_alt) {
if (isNaN(mainmarker.device_alt)) return false;
alt = mainmarker.device_alt;
}

Expand Down Expand Up @@ -808,60 +849,60 @@ const module = (() => {
JSON.stringify(tracking_cache)
);

const { gain, loss } = calculateGainAndLoss(tracking_altitude, 100);

//get tracking data to display in view
new L.GPX(toGPX(), { async: true }).on("loaded", function (e) {
//meter

if (general.measurement_unit == "km") {
// Calculate the distance along the polyline
let a = calcDistance(polyline_tracking);
document.querySelector("div#tracking-distance").innerText =
a.toFixed(2) + general.measurement_unit;
tracking.distance = a.toFixed(2) + general.measurement_unit;

//gain
let b = e.target._info.elevation.gain;
document.querySelector("#tracking-evo-up span").innerText =
parseInt(elevation(tracking_altitude).up);
tracking.gain = gain;

//loss
let c = e.target._info.elevation.loss;
document.querySelector("#tracking-evo-down span").innerText =
parseInt(elevation(tracking_altitude).down);
tracking.loss = loss;
//alt

document.getElementById("tracking-altitude").innerText =
mainmarker.device_alt;
tracking.altitude = mainmarker.device_alt;

//speed
let d = e.target.get_moving_speed();
document.querySelector("#tracking-speed-average-time").innerText =
d.toFixed(2);
tracking.speed_average = d.toFixed(2);
}
//miles
if (general.measurement_unit == "mil") {
// Calculate the distance along the polyline
let a = calcDistance(polyline_tracking);
document.querySelector("div#tracking-distance").innerText =
a.toFixed(2) + general.measurement_unit;
tracking.distance = a.toFixed(2) + general.measurement_unit;

//gain
let b = e.target.get_elevation_gain_imp();
document.querySelector("#tracking-evo-up span").innerText =
b.toFixed(2);
tracking.gain = b.toFixed(2);

//loss
let c = e.target.get_elevation_loss_imp();
document.querySelector("#tracking-evo-down span").innerText =
c.toFixed(2);
tracking.loss = c.toFixed(2);

document.getElementById("tracking-altitude").innerText =
mainmarker.device_alt * 3.280839895;
//alt
tracking.altitude = mainmarker.device_alt * 3.280839895;

//speed
let d = e.target.get_moving_speed_imp();
d ? d.toFixed(2) : "-";
document.querySelector("#tracking-speed-average-time").innerText =
d;
tracking.speed_average = d.toFixed(2);
}

document.querySelector("#tracking-moving-time span").innerText =
format_ms(e.target.get_total_time());
tracking.duration = format_ms(e.target.get_total_time());

//tracking notification

//distance

if (setting.tracking_notification_distance > 0) {
Expand All @@ -880,22 +921,27 @@ const module = (() => {
) {
// If the integer part has changed or the interval missed an integer
// Trigger the notification
module.pushLocalNotification("o.map", "o.map distance");
module.pushLocalNotification(
"o.map",
"o.map distance " + tracking.distance
);
// Update the last seen integer part
lastIntegerPart = distance;
}
}

//time
if (setting.tracking_notification_time > 0) {
return;
if (
isDivisible(
Math.round(e.target.get_total_time() / 1000),
setting.tracking_notification_time * 60
)
) {
module.pushLocalNotification("o.map", "o.map duration");
module.pushLocalNotification(
"o.map",
"o.map duration " + tracking.duration
);
}
}
});
Expand Down Expand Up @@ -926,6 +972,8 @@ const module = (() => {
clearInterval(tracking_interval);
if (setting.tracking_screenlock) screenWakeLock("unlock", "screen");
}

update_tracking_view();
}, 10000);
}

Expand Down
Loading

0 comments on commit 5d3eb4f

Please sign in to comment.