-
Notifications
You must be signed in to change notification settings - Fork 24
Desktop Attributes #546
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
Merged
Merged
Desktop Attributes #546
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
577cbb6
support for adding/editing desktop attributes
BryonLewis e73fae3
Merge branch 'master' into desktop/attributes
BryonLewis ece2bf5
adding in track.json support for attributes
BryonLewis 5243a4f
refactor attributeProcess
BryonLewis 444cd71
small structure and comment changes
BryonLewis 2b1ea86
Merge branch 'master' into desktop/attributes
BryonLewis 019b8e7
addressing comments
BryonLewis 2456b25
Merge branch 'master' into desktop/attributes
BryonLewis 09d21b0
fixing attribute setting error
BryonLewis 9a6b50a
Merge branch 'desktop/attributes' of https://github.com/VIAME/VIAME-W…
BryonLewis c9629c1
Adding in some tests for attributes
BryonLewis 6b39a6a
enabling all attributes view by default
BryonLewis 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
84 changes: 84 additions & 0 deletions
84
client/platform/desktop/backend/native/attributeProcessor.ts
This file contains hidden or 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,84 @@ | ||
| import { Attributes } from 'platform/desktop/constants'; | ||
| import { MultiTrackRecord } from 'viame-web-common/apispec'; | ||
| import { StringKeyObject, TrackData } from 'vue-media-annotator/track'; | ||
|
|
||
|
|
||
| /** | ||
| * Processes a list of tracks and returns a MultiTrackRecord and an attributes object to be used | ||
| * @param tracks list of tracks to process for the attributes | ||
| */ | ||
| function processTrackAttributes(tracks: TrackData[]): | ||
| {data: MultiTrackRecord; attributes: Attributes} { | ||
| const attributeObj: Attributes = {}; | ||
| const trackMap: MultiTrackRecord = {}; | ||
| const testVals: Record<string, Record<string, number>> = {}; | ||
|
|
||
| function processAttributes(attributes: StringKeyObject, type: 'track' | 'detection') { | ||
| Object.entries(attributes).forEach(([key, val]) => { | ||
| const valstring = `${val}`; | ||
| if (attributeObj[`${type}_${key}`] === undefined) { | ||
| attributeObj[`${type}_${key}`] = { | ||
| belongs: type, | ||
| datatype: 'text', | ||
| name: key, | ||
| _id: `${type}_${key}`, | ||
| }; | ||
| testVals[`${type}_${key}`] = { }; | ||
| testVals[`${type}_${key}`][valstring] = 1; | ||
| } else if (attributeObj[`${type}_${key}`] && testVals[`${type}_${key}`]) { | ||
| if (testVals[`${type}_${key}`][valstring]) { | ||
| testVals[`${type}_${key}`][valstring] += 1; | ||
| } | ||
| } | ||
| }); | ||
| // Now we attempt to process the attributes to infer the type. | ||
| // Cascading based on the attempting to convert and values | ||
| Object.keys(attributeObj).forEach((attributeKey) => { | ||
| if (testVals[attributeKey]) { | ||
| let attributeType: ('number' | 'boolean' | 'text') = 'number'; | ||
| let lowCount = 1; | ||
| const values: string[] = []; | ||
| Object.entries(testVals[attributeKey]).forEach(([key, val]) => { | ||
| if (val <= lowCount) { | ||
| lowCount = val; | ||
| } | ||
| values.push(key); | ||
| if (attributeType === 'number' && Number.isNaN(parseFloat(key))) { | ||
| attributeType = 'boolean'; | ||
| } | ||
| if (attributeType === 'boolean' && key !== 'true' && key !== 'false') { | ||
| attributeType = 'text'; | ||
| } | ||
| }); | ||
| // If all items are used 2 or more times it has discrete set Values otherwise | ||
| if (lowCount >= 2 && attributeType.indexOf('text') !== -1) { | ||
| attributeObj[attributeKey].values = values; | ||
| } | ||
| // eslint-disable-next-line no-param-reassign | ||
| attributeObj[attributeKey].datatype = attributeType; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| function processTrackforAttributes(track: TrackData) { | ||
| if (track.attributes) { | ||
| processAttributes(track.attributes, 'track'); | ||
| } | ||
| if (track.features) { | ||
| track.features.forEach((item) => { | ||
| if (item.attributes) { | ||
| processAttributes(track.attributes, 'detection'); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| tracks.forEach((t) => { | ||
| trackMap[t.trackId.toString()] = t; | ||
| processTrackforAttributes(t); | ||
| }); | ||
|
|
||
| return { data: trackMap, attributes: attributeObj }; | ||
| } | ||
|
|
||
| export default processTrackAttributes; |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.