-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #510 from microbit-foundation/refactor-confidence
Refactor confidence
- Loading branch information
Showing
8 changed files
with
80 additions
and
60 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* (c) 2023, Center for Computational Thinking and Design at Aarhus University and contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
import { | ||
Readable, | ||
Subscriber, | ||
Unsubscriber, | ||
Writable, | ||
get, | ||
writable, | ||
} from 'svelte/store'; | ||
import { GestureID } from './gesture/Gesture'; | ||
|
||
type GestureConfidenceMap = Map<GestureID, number>; | ||
|
||
class Confidences implements Readable<GestureConfidenceMap> { | ||
private confidenceStore: Writable<GestureConfidenceMap>; | ||
|
||
constructor() { | ||
this.confidenceStore = writable(new Map<GestureID, number>()); | ||
} | ||
|
||
public subscribe( | ||
run: Subscriber<GestureConfidenceMap>, | ||
invalidate?: ((value?: GestureConfidenceMap | undefined) => void) | undefined, | ||
): Unsubscriber { | ||
return this.confidenceStore.subscribe(run, invalidate); | ||
} | ||
|
||
public setConfidence(gestureId: GestureID, confidence: number): void { | ||
this.confidenceStore.update((map: GestureConfidenceMap) => { | ||
map.set(gestureId, confidence); | ||
return map; | ||
}); | ||
} | ||
|
||
public getConfidence(gestureId: GestureID): number { | ||
const confidence = get(this.confidenceStore).get(gestureId); | ||
if (confidence === undefined) { | ||
throw new Error(`No confidence value found for gesture with ID ${gestureId}`); | ||
} | ||
return confidence; | ||
} | ||
} | ||
|
||
export default Confidences; |
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
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