diff --git a/src/client/components/Map.tsx b/src/client/components/Map.tsx
index 3eb782a..abfe558 100644
--- a/src/client/components/Map.tsx
+++ b/src/client/components/Map.tsx
@@ -23,7 +23,9 @@ function Map({ entries }: { entries: Models.IEntry[] }) {
if (!entries?.length) {
return No Data to be displayed
}
+
const lastEntry = entries.at(-1);
+ const cleanEntries = entries.filter((entry) => !entry.ignore);
return (
@@ -32,11 +34,14 @@ function Map({ entries }: { entries: Models.IEntry[] }) {
attribution='© OpenStreetMap contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
-
-
- {JSON.stringify(lastEntry, null, 2)}
-
-
+ {cleanEntries.map((entry) =>
+
+
+ {JSON.stringify(entry, null, 2)}
+
+
+ )}
+
)
}
diff --git a/src/client/pages/Start.tsx b/src/client/pages/Start.tsx
index a84ef6e..25cf726 100644
--- a/src/client/pages/Start.tsx
+++ b/src/client/pages/Start.tsx
@@ -62,18 +62,32 @@ function Start() {
setLastFetch(now);
response = await axios({
method: 'get',
- url: "/read?index=" + index.current + "&noCache=" + now,
+ url: "/read?index=" + (Math.max(index.current - 1, 0)) + "&noCache=" + now,
headers: {
'Authorization': `Bearer ${token}`
}
});
const newEntries = response.data.entries;
- if (newEntries.length) {
- setEntries((prevEntries) => [...prevEntries, ...newEntries]);
- index.current += newEntries.length;
+
+ if (newEntries.length == 1) {
+ setEntries(newEntries);
}
+ if (newEntries.length > 1) {
+ setEntries((prevEntries) => {
+ const allButLastPrevEntries = prevEntries.slice(0, prevEntries.length -1);
+ console.log("newEntries %o", newEntries);
+ const mergedEntries = [...allButLastPrevEntries, ...newEntries];
+ index.current = mergedEntries.length;
+ console.log("mergedEntries %o", mergedEntries);
+ console.log("index.current %o", index.current);
+
+ return mergedEntries;
+ });
+
+ }
+
setMessageObj({ isError: null, status: null, message: null });
setNextFetch(new Date().getTime() + fetchIntervalMs);
} catch (error) {
@@ -97,7 +111,7 @@ function Start() {
return (
<>
- {console.info("entries %o", entries)}
+ {console.info("entries %o", entries)}
{messageObj.isError &&
diff --git a/src/models/entry.ts b/src/models/entry.ts
index e7fc107..02b0bd8 100644
--- a/src/models/entry.ts
+++ b/src/models/entry.ts
@@ -21,6 +21,7 @@ export const entry = {
}
const entries = fileObj.content.entries;
const lastEntry = fileObj.content.entries.at(-1);
+ let previousEntry = fileObj.content.entries.at(-1); // potentially overwritten if entry is set to ignore
const entry = {} as Models.IEntry;
entry.altitude = Number(req.query.altitude);
@@ -32,11 +33,27 @@ export const entry = {
entry.user = req.query.user as string;
entry.ignore = false;
- if (lastEntry) { // so there is a previous entry
- entry.time = getTime(Number(req.query.timestamp), lastEntry);
- lastEntry.ignore = getIgnore(lastEntry, entry);
- entry.angle = getAngle(lastEntry, entry);
- entry.distance = getDistance(entry, lastEntry)
+ if (lastEntry && previousEntry) {
+ entry.time = getTime(Number(req.query.timestamp), lastEntry); // time data is needed for ignore calculation
+
+ if (entries.length > 1) { // the very first entry one shall never be ignored
+ lastEntry.ignore = getIgnore(lastEntry, entry);
+ } else {
+ lastEntry.ignore = false;
+ }
+
+ if (lastEntry.ignore) { // rectify or replace previousEntry with last non ignored element
+ for (let i = entries.length - 1; i >= 0; i--) {
+ if (!entries[i].ignore) {
+ previousEntry = entries[i];
+ break;
+ }
+ }
+ }
+
+ entry.time = getTime(Number(req.query.timestamp), previousEntry); // overwrite time in case previousEnty was changed
+ entry.angle = getAngle(previousEntry, entry);
+ entry.distance = getDistance(entry, previousEntry)
entry.speed = getSpeed(Number(req.query.speed), entry);
} else {
entry.angle = undefined;
@@ -46,7 +63,7 @@ export const entry = {
if (entries.length >= 1000) {
logger.log(`File over 1000 lines: ${fileObj.path}`);
- if (entry.hdop < 12 || (lastEntry && entry.hdop < lastEntry.hdop)) {
+ if (entry.hdop < 12 || (previousEntry && entry.hdop < previousEntry.hdop)) {
entries[entries.length - 1] = entry; // replace last entry
}
} else {
diff --git a/src/scripts/ignore.ts b/src/scripts/ignore.ts
index 3e92857..d16bb1c 100644
--- a/src/scripts/ignore.ts
+++ b/src/scripts/ignore.ts
@@ -4,10 +4,10 @@ export function getIgnore(lastEntry: Models.IEntry, entry: Models.IEntry): boole
const timing = Math.max(lastEntry.time.diff, entry.time.diff)
- // Threshold increases with older previous entries or farther future entries.
+ // Threshold increases with older previous entries
if (timing > 32) {
threshold += Math.min(lastEntry.time.diff / 60, maxThreshold);
}
-
+
return lastEntry.hdop > threshold;
}
\ No newline at end of file
diff --git a/views/index.ejs b/views/index.ejs
index 6ccb8bf..b194ff6 100644
--- a/views/index.ejs
+++ b/views/index.ejs
@@ -6,10 +6,10 @@
LOREX - Osmand Webtracking Frontend
-
-
+
+
-
+