-
-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): CurrentStatisticsCapability
- Loading branch information
Showing
7 changed files
with
122 additions
and
50 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
backend/lib/core/capabilities/CurrentStatisticsCapability.js
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,26 @@ | ||
const Capability = require("./Capability"); | ||
const NotImplementedError = require("../NotImplementedError"); | ||
const ValetudoDataPoint = require("../../entities/core/ValetudoDataPoint"); | ||
|
||
/** | ||
* @template {import("../ValetudoRobot")} T | ||
* @extends Capability<T> | ||
*/ | ||
class CurrentStatisticsCapability extends Capability { | ||
/** | ||
* The amount and type of stuff returned here depends on the robots implementation | ||
* | ||
* @return {Promise<Array<ValetudoDataPoint>>} | ||
*/ | ||
async getStatistics() { | ||
throw new NotImplementedError(); | ||
} | ||
|
||
getType() { | ||
return CurrentStatisticsCapability.TYPE; | ||
} | ||
} | ||
|
||
CurrentStatisticsCapability.TYPE = "CurrentStatisticsCapability"; | ||
|
||
module.exports = CurrentStatisticsCapability; |
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
6 changes: 3 additions & 3 deletions
6
...outers/TotalStatisticsCapabilityRouter.js → ...lityRouters/StatisticsCapabilityRouter.js
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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
const CapabilityRouter = require("./CapabilityRouter"); | ||
const Logger = require("../../Logger"); | ||
|
||
class TotalStatisticsCapabilityRouter extends CapabilityRouter { | ||
class StatisticsCapabilityRouter extends CapabilityRouter { | ||
initRoutes() { | ||
this.router.get("/", async (req, res) => { | ||
try { | ||
res.json(await this.capability.getStatistics()); | ||
} catch (e) { | ||
Logger.warn("Error while fetching total statistics", e); | ||
Logger.warn("Error while fetching statistics", e); | ||
res.status(500).json(e.message); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
module.exports = TotalStatisticsCapabilityRouter; | ||
module.exports = StatisticsCapabilityRouter; |
89 changes: 89 additions & 0 deletions
89
backend/lib/webserver/capabilityRouters/doc/StatisticsCapabilityRouter.openapi.json
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,89 @@ | ||
{ | ||
"/api/v2/robot/capabilities/TotalStatisticsCapability": { | ||
"get": { | ||
"tags": [ | ||
"TotalStatisticsCapability" | ||
], | ||
"summary": "Get total statistics", | ||
"responses": { | ||
"200": { | ||
"description": "Ok", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/components/schemas/ValetudoDataPoint" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/api/v2/robot/capabilities/TotalStatisticsCapability/properties": { | ||
"get": { | ||
"tags": [ | ||
"TotalStatisticsCapability" | ||
], | ||
"summary": "Get various capability-related properties", | ||
"responses": { | ||
"200": { | ||
"description": "Ok", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"type": "object" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
|
||
"/api/v2/robot/capabilities/CurrentStatisticsCapability": { | ||
"get": { | ||
"tags": [ | ||
"CurrentStatisticsCapability" | ||
], | ||
"summary": "Get statistics about the current (or last) task", | ||
"responses": { | ||
"200": { | ||
"description": "Ok", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "#/components/schemas/ValetudoDataPoint" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/api/v2/robot/capabilities/CurrentStatisticsCapability/properties": { | ||
"get": { | ||
"tags": [ | ||
"CurrentStatisticsCapability" | ||
], | ||
"summary": "Get various capability-related properties", | ||
"responses": { | ||
"200": { | ||
"description": "Ok", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"type": "object" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
45 changes: 0 additions & 45 deletions
45
backend/lib/webserver/capabilityRouters/doc/TotalStatisticsCapabilityRouter.openapi.json
This file was deleted.
Oops, something went wrong.
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