entropyE
Convex Communityโ€ข14mo agoโ€ข
5 replies
entropy

Calculating average rating across a large dataset

Hello! I'm currently looking to build a feature that shows the average rating of a show based on entry logged by users. This is my first time approaching something like this Convex. I was wondering if there were any recommended solutions? I was looking into the Aggregate convex component to potential solve my problem. The only issue I've have with that approach is that a user can log an entry without rating it, but the sameValue does not accept undefined.

export const animeStatsByEntry = new TableAggregate<{
  Namespace: Id<'anime'>
  Key: null
  DataModel: DataModel
  TableName: 'anime_entries'
}>(components.aggregateByAnime, {
  namespace: doc => doc.animeId,
  sortKey: _ => null,
  // TODO: This needs to ignore undefined values instead of setting them to 0
  sumValue: doc => doc.rating ?? 0
})
Was this page helpful?