Comments (5)
@jura-b the stats mixing results in series of data expected to be passed to any chart, said that.
I won't provide the functionality aside of creating series, for instance: If you only want to get the average from a couple of records.
What actually does is to create series of data based on time:
Lets say you have the following records
{ title: "Example 1", result: { score: 10 }, createdAt: '2017/07/15' }
{ title: "Example 2", result: { score: 15 }, createdAt: '2017/07/15' }
{ title: "Example 3", result: { score: 10 }, createdAt: '2017/07/16' }
*Note date should actually be ISODate (Recommended use of loopback-ds-timestamp-mixin)
When using the stats mixing it will return series which in this use case one of the datum would be 12.5 from the average in day 15.
To achieve that you would configure as follows:
"mixins": {
"Stats": [
{
"method": "average", // This can be whatever you want
"endpoint": "/average", // This also can be whatever you want
"description": "A Description for your average method", // As well as this
"type": "model", // We will calculate over this model, not from a related model
"count": {
"on": "createdAt", // This creates time based series
"by": "result.score", // will count by result.score
"avg": true // This will return the average from result.score (12.5 at Aug 15)
}
}
]
}
I hope this clarifies your question and also the mixing functionality.
Regards
Jon
from loopback-stats-mixin.
@jura-b the mixin is actually quite robust, but at the same time complex...
Do you have a specific result in mind? I can help on that... adding all types of examples might also confuse you
from loopback-stats-mixin.
@jonathan-casarrubias
Suppose I have a model schema like this,
{ title: "Example 1", result: { score: 10 } }
I want the average of result.score. How does the config look like?
Thank you in advance!
from loopback-stats-mixin.
@jonathan-casarrubias Really appreciate your help!
from loopback-stats-mixin.
@jonathan-casarrubias
Hi Jon,
I have some relatable question with that of @jura-b , but a little bit more complex.
Suppose I have records with schema like this,
{ title: "Exam A",
answer: [{_id: 1, answer: 'B', timeUsed: 2}, {_id: 2, answer: 'A', timeUsed: 2}, {_id: 3, answer: 'A', timeUsed: 5}],
result: { score: 3 } },
{ title: "Exam A",
answer: [{_id: 1, answer: 'B', timeUsed: 4}, {_id: 2, answer: 'A', timeUsed: 5}, {_id: 3, answer: 'A', timeUsed: 9}],
result: { score: 1 } },
{ title: "Exam A",
answer: [{_id: 1, answer: 'B', timeUsed: 1}, {_id: 2, answer: 'A', timeUsed: 1}, {_id: 3, answer: 'A', timeUsed: 11}],
result: { score: 2 } }
You already answer how to config to find the avg score across records grouped by "createdAt".
How about configuration for finding avg "timeUsed" across records grouped by index "_id" in array.
My expected result would be something like this.
{ avgTimeUsedOfId1: 2.33, // (2 + 4 + 1) / 3
avgTimeUsedOfId2: 2.66, // (2 + 5 + 1) / 3
avgTimeUsedOfId3: 8.33 // (5 + 9 + 11) / 3}
Thank you in advance,
Steve
from loopback-stats-mixin.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loopback-stats-mixin.