-
Notifications
You must be signed in to change notification settings - Fork 1
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
feature/of-504-user-metrics-in-subgraph #78
feature/of-504-user-metrics-in-subgraph #78
Conversation
3a05333
to
74737b0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for not looking at this for a while, wanted to make sure give it some good use before reviewing.
Proposed a couple of small changes to the shema. But I think this is basically ready to go.
The main blocker looks like the test suite not supporting aggregations. @nup9151f are there any ways around this so we can still test the rest of the subgraph?
schema.graphql
Outdated
tokenAmount: BigInt! | ||
|
||
badgeId: String | ||
badgeCount: Int! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
badgeCount
should be badgeTokenCount
Reason being in the schema badge
refers to NFT contract and badgeToken
refers to the individual NFT
schema.graphql
Outdated
transactionHash: String! | ||
|
||
badgeId: String | ||
badgeCount: Int! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here badgeCount
should be badgeTokenCount
schema.graphql
Outdated
type RewardAppTokenTypeStat @aggregation(intervals: ["hour", "day"], source: "RewardTokenData") { | ||
id: Int8! | ||
timestamp: Timestamp! | ||
appId: String! | ||
count: Int8! @aggregate(fn: "count") | ||
totalCount: Int8! @aggregate(fn: "count", cumulative: true) | ||
} | ||
|
||
type RewardAppTokenTypeUserStat @aggregation(intervals: ["hour", "day"], source: "RewardTokenData") { | ||
id: Int8! | ||
timestamp: Timestamp! | ||
appId: String! | ||
userId: String! | ||
count: Int8! @aggregate(fn: "count") | ||
totalCount: Int8! @aggregate(fn: "count", cumulative: true) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After coming back to this I think we should remove stat types that contain TokenType
as I am not totally convinced it's all that useful to an end user. So remove RewardAppTokenTypeStat
and RewardAppTokenTypeUserStat
It shows us the amount of rewards issued that contained a token for a given app. This can be constructed from querying all the tokens used by that app, with the RewardAppTokenStat
.
I would rather keep it out for now and add in later if highly requested, but more than happy to be convinced otherwise.
schema.graphql
Outdated
type RewardAppBadgeTypeStat @aggregation(intervals: ["hour", "day"], source: "RewardBadgeData") { | ||
id: Int8! | ||
timestamp: Timestamp! | ||
appId: String! | ||
count: Int8! @aggregate(fn: "count") | ||
totalCount: Int8! @aggregate(fn: "count", cumulative: true) | ||
badgeAmount: BigInt! @aggregate(fn: "sum", arg: "badgeCount") | ||
totalBadgeAmount: BigInt! @aggregate(fn: "sum", arg: "badgeCount", cumulative: true) | ||
} | ||
|
||
type RewardAppBadgeTypeUserStat @aggregation(intervals: ["hour", "day"], source: "RewardBadgeData") { | ||
id: Int8! | ||
timestamp: Timestamp! | ||
appId: String! | ||
userId: String! | ||
count: Int8! @aggregate(fn: "count") | ||
totalCount: Int8! @aggregate(fn: "count", cumulative: true) | ||
badgeAmount: BigInt! @aggregate(fn: "sum", arg: "badgeCount") | ||
totalBadgeAmount: BigInt! @aggregate(fn: "sum", arg: "badgeCount", cumulative: true) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here as TokenType
I think we should remove RewardAppBadgeTypeStat
and RewardAppBadgeTypeUserStat
.
We can get this results by summing the results of RewardAppBadgeStat
or RewardAppBadgeUserStat
schema.graphql
Outdated
badgeAmount: BigInt! @aggregate(fn: "sum", arg: "badgeCount") | ||
totalBadgeAmount: BigInt! @aggregate(fn: "sum", arg: "badgeCount", cumulative: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
badgeAmount
should be badgeTokenAmount
totalBadgeAmount
should be totalBadgeTokenAmount
schema.graphql
Outdated
badgeAmount: BigInt! @aggregate(fn: "sum", arg: "badgeCount") | ||
totalBadgeAmount: BigInt! @aggregate(fn: "sum", arg: "badgeCount", cumulative: true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
badgeAmount
should be badgeTokenAmount
totalBadgeAmount
should be totalBadgeTokenAmount
Hey @george-openformat: |
Gotcha, thanks for explaining that. |
…f-504-user-metrics-in-subgraph-2
…n-subgraph-2 Feature/of 504 user metrics in subgraph 2
Hey @george-openformat: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Awesome |
Description
This PR adds aggregation stats to be able to create these graphs:
Changes
Entities:
UserReward
- Created to solve the Unique users rewarded problem. The idea of this entity is to keep track of what users have received a reward on which app. Because we can only query an entity id from the db in our handlers, thisUserReward
saves the relationship${user_id}-${app_id}
in its ID the first time (and only the first time) a user receives a reward in the app.AppRewardId
- Created to saveRewardId
for each app. EntityReward
and timeseriesRewardData
already have this data, we need this new entity because we can not create a Graphql resolver to add adistinct
orgroup by
to the queries.Timeseries:
UserRewardData
- Created to count the amount of new unique users per app. When we save aUserReward
we also save a newUserRewardData
, the result is we only create a new stat when a new user is rewarded in an app.RewardData
- To create aggregations over all Rewards regardless of type (token, badge).RewardTokenData
- To create aggregation over only Token rewards.RewardBadgeData
- To create aggregation over only Badges rewards.Note: In all timeseries entities, the relations in the form
app: App
where changed toappId: String
. The previous form was throwing occasional errors:ERROR: functions in index expression must be marked IMMUTABLE
Current stats:
UserRewardAppStat
, source:UserRewardData
- New users by app.RewardAppStat
- Count and total rewards per app.RewardAppRewardIdStat
RewardAppRewardTypeStat
RewardAppRewardIdRewardTypeStat
RewardAppUserStat
RewardAppUserRewardTypeStat
RewardAppUserRewardIdStat
RewardAppUserRewardIdRewardTypeStat
RewardAppTokenTypeStat
, source:RewardTokenData
- Stats for all tokens (and only tokens) on each app.RewardAppTokenTypeUserStat
, source:RewardTokenData
- Stats for all tokens (and only tokens) on each app and user.RewardAppTokenStat
, source:RewardTokenData
- Stats for specific tokens and appsRewardAppTokenUserStat
, source:RewardTokenData
RewardAppBadgeTypeStat
, source:RewardBadgeData
- Stats for all badges (and only badges) on each app.RewardAppBadgeTypeUserStat
, source:RewardBadgeData
RewardAppBadgeStat
, source:RewardBadgeData
- Stats for specific badges and appsRewardAppBadgeUserStat
, source:RewardBadgeData
Tests
Tests are failing because
matchstick
library does not have support yet for Aggregations.