Skip to content
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

More Configuration Example #5

Open
jura-b opened this issue Aug 11, 2017 · 5 comments
Open

More Configuration Example #5

jura-b opened this issue Aug 11, 2017 · 5 comments
Assignees

Comments

@jura-b
Copy link

jura-b commented Aug 11, 2017

Could you provide more example of each type of boot option, please?

@jonathan-casarrubias jonathan-casarrubias self-assigned this Aug 11, 2017
@jonathan-casarrubias
Copy link
Collaborator

@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

@jura-b
Copy link
Author

jura-b commented Aug 12, 2017

@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!

@jonathan-casarrubias
Copy link
Collaborator

jonathan-casarrubias commented Aug 17, 2017

@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

@jura-b
Copy link
Author

jura-b commented Aug 20, 2017

@jonathan-casarrubias Really appreciate your help!

@sitthinutk
Copy link

sitthinutk commented Aug 20, 2017

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants