forked from openmobilityfoundation/mds-core
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mds-stream-processor] Add geo labeling for mds-stream-processor #231
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d14d3f2
Add geo labeling for mds-stream-processor
avatarneil 4f1022d
Add tests
avatarneil f5e8c6d
Add Sinon devDependency
avatarneil c0fd4e9
Add LatencyLabeler tests
avatarneil 167f5bf
Filter based on point in shape, then map to geography_id
avatarneil 021b680
Remove now unused import
avatarneil fae06cb
Only compute for published geographies
avatarneil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/mds-stream-processor/tests/labelers/geograpy-labelers.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { GeographyLabeler } from '@mds-core/mds-stream-processor/labelers/geography-labeler' | ||
import * as utils from '@mds-core/mds-utils' | ||
import db from '@mds-core/mds-db' | ||
import Sinon from 'sinon' | ||
import { Geography } from '@mds-core/mds-types' | ||
import { v4 as uuid } from 'uuid' | ||
import assert from 'assert' | ||
|
||
const mockGeographies: Geography[] = Array.from({ length: 100 }, () => ({ | ||
geography_id: uuid(), | ||
geography_json: { | ||
type: 'FeatureCollection', | ||
features: [] | ||
}, | ||
name: uuid() // Usually intended to be a human readable name, but we just need a random string here. | ||
})) | ||
|
||
const mockTelemetry = { | ||
provider_id: uuid(), | ||
device_id: uuid(), | ||
timestamp: utils.now(), | ||
gps: { lat: 34.0522, lng: 118.2437 } | ||
} | ||
|
||
describe('GeographyLabeler tests', async () => { | ||
it('Tests all matched geographies are included in list', async () => { | ||
Sinon.replace(utils, 'pointInShape', () => true) | ||
Sinon.replace(db, 'readGeographies', async () => mockGeographies) | ||
|
||
const { geography_ids } = await GeographyLabeler()({ telemetry: mockTelemetry }) | ||
|
||
geography_ids.forEach(geography_id => | ||
assert(mockGeographies.find(geography => geography.geography_id === geography_id)) | ||
) | ||
}) | ||
|
||
it('Tests that absent gps in telemetry elicits no matches', async () => { | ||
const { geography_ids } = await GeographyLabeler()({}) | ||
assert(geography_ids.length === [].length) | ||
}) | ||
}) |
22 changes: 22 additions & 0 deletions
22
packages/mds-stream-processor/tests/labelers/latency-labeler.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { LatencyLabeler } from '@mds-core/mds-stream-processor/labelers/latency-labeler' | ||
import assert from 'assert' | ||
|
||
describe('LatencyLabeler Tests', async () => { | ||
it('Tests LatencyLabeler detects latency > 0', async () => { | ||
const mockTimeChunks = Array.from({ length: 100 }, (_, index) => ({ | ||
timestamp: 1000 * index, | ||
recorded: 1000 * (index + 1) | ||
})) | ||
const latencyLabels = await Promise.all(mockTimeChunks.map(chunk => LatencyLabeler()(chunk))) | ||
latencyLabels.forEach(({ latency_ms }) => assert(latency_ms === 1000)) | ||
}) | ||
|
||
it('Tests LatencyLabeler returns latency == 0', async () => { | ||
const mockTimeChunks = Array.from({ length: 100 }, (_, index) => ({ | ||
timestamp: 1000 * index, | ||
recorded: 1000 * index | ||
})) | ||
const latencyLabels = await Promise.all(mockTimeChunks.map(chunk => LatencyLabeler()(chunk))) | ||
latencyLabels.forEach(({ latency_ms }) => assert(latency_ms === 0)) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if a geography is changed at some point? I know the idea of versioning definitions has been brought up before, not sure where we landed with it though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We make a new one and the new one references the previous one in the attribute
prev_geographies
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably make it so it only annotates for published geographies, I suppose. Those are immutable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a change to only query for published geographies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might wanna update your test to reflect it only does published geos then.