-
Notifications
You must be signed in to change notification settings - Fork 1
Bundle predictor #21
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
base: main
Are you sure you want to change the base?
Bundle predictor #21
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -32,8 +32,9 @@ export const Predictor = class Predictor { | |||||
| * @param {string[]} labels | ||||||
| * @param {{ center: { [featureName: string]: number }, scale: { [featureName: string]: number } }} scaler | ||||||
| * @param {{ windowingMode: "time" | "sample" }} options | ||||||
| * @param {boolean} useDeviceTime - True if you want to use timestamps generated by the server | ||||||
| */ | ||||||
| constructor(predictor, sensors, windowSize, labels, scaler, { windowingMode = "sample" } = {}) { | ||||||
| constructor(predictor, sensors, windowSize, labels, scaler, { windowingMode = "sample", useDeviceTime = false } = {}) { | ||||||
| /** @type {(input: number[]) => number[]} */ | ||||||
| this.predictor = predictor; | ||||||
| /** @type {string[]} */ | ||||||
|
|
@@ -47,6 +48,9 @@ export const Predictor = class Predictor { | |||||
|
|
||||||
| /** @type {boolean} */ | ||||||
| this.windowModeMs = windowSize < 0 || windowingMode === "time" | ||||||
| /** @type {boolean} */ | ||||||
| this.useDeviceTime = useDeviceTime | ||||||
|
|
||||||
| this.lastPruneTime = 0; | ||||||
| this.lastAddTime = 0; | ||||||
|
|
||||||
|
|
@@ -58,15 +62,24 @@ export const Predictor = class Predictor { | |||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * addDatapoint | ||||||
| * addDataPoint | ||||||
| * @param {number} time - The timestamp assigned to the datapoint | ||||||
| * @param {string} sensorName | ||||||
| * @param {number} value | ||||||
| * @param {number | null} time use a predefined timestamp, or null if the timestamp should be generated | ||||||
| */ | ||||||
| addDatapoint = (sensorName, value, time = null) => { | ||||||
| if (typeof value !== 'number') throw new TypeError('Datapoint is not a number'); | ||||||
| addDataPoint = (time, sensorName, value) => { | ||||||
| if (typeof value !== 'number') throw new TypeError('DataPoint value is not a number'); | ||||||
| if (!this.sensors.includes(sensorName)) throw new TypeError('Sensor is not valid'); | ||||||
| if (time === null) time = Date.now() | ||||||
| // TODO: see #16 use if (time === null) time = Date.now() | ||||||
riedel marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| if (!this.useDeviceTime && typeof time !== "number") { | ||||||
| throw new TypeError("Provide a valid timestamp"); | ||||||
| } | ||||||
| if (this.useDeviceTime) { | ||||||
| time = Date.now(); | ||||||
| } | ||||||
|
|
||||||
| //TODO: see #17 no clue why see Collector | ||||||
|
||||||
| //TODO: see #17 no clue why see Collector | |
| // TODO: Investigate the relevance of "Collector" in this context and document why rounding the value is necessary. |
Uh oh!
There was an error while loading. Please reload this page.