Skip to content

Commit

Permalink
[Task] #33 moved ignore to its own file since it creates data rather …
Browse files Browse the repository at this point in the history
…than validating it
  • Loading branch information
Type-Style committed Feb 6, 2024
1 parent 0ca2a85 commit 8fb1057
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/models/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getTime } from '@src/scripts/time';
import { getSpeed } from '@src/scripts/speed';
import { getDistance } from '@src/scripts/distance';
import { getAngle } from '@src/scripts/angle';
import { getIgnore } from '@src/scripts/ignore';
import logger from '@src/scripts/logger';


Expand All @@ -33,7 +34,7 @@ export const entry = {

if (lastEntry) { // so there is a previous entry
entry.time = getTime(Number(req.query.timestamp), lastEntry);
lastEntry.ignore = checkIgnore(lastEntry, entry);
lastEntry.ignore = getIgnore(lastEntry, entry);
entry.angle = getAngle(lastEntry, entry);
entry.distance = getDistance(entry, lastEntry)
entry.speed = getSpeed(Number(req.query.speed), entry);
Expand Down Expand Up @@ -115,20 +116,6 @@ export function checkTime(value: string) {
return true
}

function checkIgnore(lastEntry: Models.IEntry, entry: Models.IEntry): boolean {
let threshold = 6; // hdop not allowed to be higher
const maxThreshold = 25;

const timing = Math.max(lastEntry.time.diff, entry.time.diff)

// Threshold increases with older previous entries or farther future entries.
if (timing > 32) {
threshold += Math.min(lastEntry.time.diff / 60, maxThreshold);
}

return lastEntry.hdop > threshold;
}


function checkKey(value: string) {
if (process.env.NODE_ENV != "production" && value == "test") {
Expand Down
13 changes: 13 additions & 0 deletions src/scripts/ignore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function getIgnore(lastEntry: Models.IEntry, entry: Models.IEntry): boolean {
let threshold = 6; // hdop not allowed to be higher
const maxThreshold = 25;

const timing = Math.max(lastEntry.time.diff, entry.time.diff)

// Threshold increases with older previous entries or farther future entries.
if (timing > 32) {
threshold += Math.min(lastEntry.time.diff / 60, maxThreshold);
}

return lastEntry.hdop > threshold;
}

0 comments on commit 8fb1057

Please sign in to comment.