New agent forest - Using the filter

Hello :wave:

Feature(s) impacted

Dashboard, charts, filter

Observed behavior

In my database, I have a table called beneficiaries, which is related to the nv_contract table

when I set the filter to the right value, it fine

agent.addChart('beneficiariesNVbyDays', async (context, resultBuilder) => {
      try {
        const aggregation = { operation: 'Count', field: 'nv_contract' };
        const filter = {
          conditionTree: { field: 'nv_contract:createdAt', operator: 'Equal', value: ' 2024-06-12T13:13:56.760Z' },
        };
        const beneficiariesList = await context.dataSource
          .getCollection('beneficiaries')
          .aggregate(filter, aggregation);
   
        console.log(beneficiariesList)
        return resultBuilder.objective(235, 300);
      } catch (error) {
        console.error(`Error while count nv beneficiaries by days, error : ${error}`);
        throw error;
      }

I have this log:

[ { value: 1, group: {} } ]

Expected behavior

But I would like to filter only with days, months and years, without time etc…
Example:

conditionTree: { field: 'nv_contract:createdAt', operator: 'Equal', value: '2024-06-12' },

Is it possible to have this kind of behavior?

Context

  • Project name: Nostrum Care v3
  • Team name: Op
  • Environment name: Local
  • Agent (forest package) name & version:
    “@forestadmin/agent”: “^1.0.0”,
    “@forestadmin/datasource-sequelize”: “^1.5.21”,
    “@forestadmin/datasource-sql”: “^1.0.0”,
    “dotenv”: “^16.0.1”,
    “pg”: “^8.8.0”,
    “sequelize”: “^6.33.0”,
    “stripe”: “^14.17.0”
  • Database type: Postgresql

Thanks in advance for your feedback!

Hello @jacques_liao, :wave:

What are you exactly trying to do?

Do you wanna count the number of beneficiaries by days, months, weeks ?

In the current context you will be forced to create multiple charts one for each periods.

You can use the query interface to do so natively.

{
  "operation": "Count",
  "groups": [
    { "field": "nv_contract:createdAt", "operation": "Day" }
  ]
}

Let me know if it helps.

Regards,
Morgan

Currently my nv_contract:createdAt field contains this as the value 2024-06-12T13:13:56.760Z, however I like to make a graph where for each day I count the number of times an nv_contract:createdAtis equal to the day on the graph. But I have a problem with this, for example in my comparison T13:13:56.760Z

You don’t need any filter in your case. This should probably do the trick.

 const aggregation = {
  "operation": "Count",
  "groups": [
    { "field": "nv_contract:createdAt", "operation": "Day" }
  ]
};

const beneficiariesList = await context.dataSource
  .getCollection('beneficiaries')
  .aggregate(null, aggregation);

Regards,
Morgan

1 Like

It good !! Thanks !!

1 Like

Awesome :muscle: You’re welcome, have a nice experience.

Regards,
Morgan

1 Like