So i have a adonis model where i store propertyValue and each entry has a timestamp (ISO 8601). There are several properties which is related via a propertyId.
So my objective is to aggregate data and get averages over a day for a particular property and show it in a graph.
Similarly I also need to average over a week, when a month's graph has to be shown.
I looked into aggregates and avg but im not able to achieve what i expect.
- Posted 7 days ago by
- swarnim (@swarnim)

Join The Discussion! (2 Replies)
Please sign in or sign up for free to join in on the dicussion.
swarnim
I'll attach the models for your reference:
// backend/app/models/archive.ts
export default class Archive extends BaseModel {
@column({ isPrimary: true })
declare id: number;
@column()
declare timestamp: DateTime;
@column()
declare gensetPropertyId: number; //
@belongsTo(() => GensetProperty)
declare gensetProperty: BelongsTo<typeof GensetProperty>;
@column()
declare propertyValue: number;
@column()
declare isAnomaly: boolean;
}
Please sign in or sign up for free to reply
swarnim
// backend/app/models/genset_property.ts
export default class GensetProperty extends BaseModel {
@column({ isPrimary: true })
declare id: number;
@column()
declare propertyName: string;
@column()
declare readablePropertyName: string;
@column()
declare physicalQuantityId: number;
@belongsTo(() => PhysicalQuantity)
declare physicalQuantity: BelongsTo<typeof PhysicalQuantity>;
}
Please sign in or sign up for free to reply