Skip to content

Commit

Permalink
Merge pull request #945 from mapswipe/dev
Browse files Browse the repository at this point in the history
Release - Fix community statsboard issue
  • Loading branch information
thenav56 authored Jul 3, 2024
2 parents 308f8b4 + e9c49f6 commit f9c3438
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 96 deletions.
10 changes: 9 additions & 1 deletion community-dashboard/app/Base/configs/apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ const link: ApolloLinkFromClient = ApolloLink.from([

const apolloOptions: ApolloClientOptions<NormalizedCacheObject> = {
link,
cache: new InMemoryCache(),
cache: new InMemoryCache({
typePolicies: {
// NOTE: Singleton types that have no identifying field can use an empty
// array for their keyFields.
FilteredStats: {
keyFields: [],
},
},
}),
assumeImmutableResults: true,
defaultOptions: {
query: {
Expand Down
2 changes: 2 additions & 0 deletions community-dashboard/app/views/Dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import {
const COMMUNITY_STATS = gql`
query CommunityStats {
communityStatsLatest {
id
totalContributors
totalUserGroups
totalSwipes
}
communityStats {
id
totalContributors
totalUserGroups
totalSwipes
Expand Down
5 changes: 5 additions & 0 deletions community-dashboard/app/views/UserDashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ import styles from './styles.css';
const USER_STATS = gql`
query UserStats($pk: ID!, $limit: Int!, $offset: Int!) {
user(pk: $pk) {
id
userId
username
userInUserGroups(pagination: {limit: $limit, offset: $offset}) {
count
items {
id
userGroupId
userGroupName
membersCount
}
}
}
userStats(userId: $pk) {
id
stats {
totalSwipes
totalSwipeTime
Expand All @@ -54,7 +57,9 @@ const USER_STATS = gql`
const FILTERED_USER_STATS = gql`
query FilteredUserStats($pk: ID!, $fromDate: DateTime!, $toDate: DateTime!) {
userStats(userId: $pk) {
id
filteredStats(dateRange: { fromDate: $fromDate, toDate: $toDate}) {
id
areaSwipedByProjectType {
totalArea
projectType
Expand Down
2 changes: 2 additions & 0 deletions django/apps/existing_database/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def get_community_stats() -> CommunityStatsType:
total_user_groups=models.Count("user_group", distinct=True),
)
return CommunityStatsType(
id="all",
total_contributors=user_agg_data["total_users"] or 0,
total_user_groups=user_group_agg_data["total_user_groups"] or 0,
total_swipes=user_agg_data["swipes_sum"] or 0,
Expand All @@ -64,6 +65,7 @@ def get_community_stats_latest() -> CommunityStatsType:
total_user_groups=models.Count("user_group", distinct=True),
)
return CommunityStatsType(
id="last-30-days",
total_contributors=user_agg_data["total_users"] or 0,
total_user_groups=user_group_agg_data["total_user_groups"] or 0,
total_swipes=user_agg_data["swipes_sum"] or 0,
Expand Down
11 changes: 11 additions & 0 deletions django/apps/existing_database/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class DateRangeInput:

@strawberry.type
class CommunityStatsType:
id: strawberry.ID
total_swipes: int
total_contributors: int
total_user_groups: int
Expand Down Expand Up @@ -264,23 +265,33 @@ def __post_init__(self, date_range, user_id):
filters = {
"user_id": user_id,
}
self._user_id = user_id
if date_range:
filters.update(
timestamp_date__gte=date_range.from_date,
timestamp_date__lte=date_range.to_date,
)
self._qs = AggregatedUserStatData.objects.filter(**filters)

@strawberry.field
async def id(self) -> strawberry.ID:
return self._user_id


@strawberry.type
class UserStats:
user_id: InitVar[str]

def __post_init__(self, user_id):
self.id = user_id
self._user_id = user_id
self.qs = AggregatedUserStatData.objects.filter(user_id=user_id)
self.ug_qs = AggregatedUserGroupStatData.objects.filter(user_id=user_id)

@strawberry.field
async def id(self) -> strawberry.ID:
return self._user_id

@strawberry.field
async def stats(self) -> UserStatType:
agg_data = await self.qs.aaggregate(
Expand Down
3 changes: 2 additions & 1 deletion django/mapswipe/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def _scope_with_sentry(self, execute_func, *args, **kwargs) -> ExecutionResult:
operation_name = kwargs.get("operation_name")
with sentry_sdk.configure_scope() as scope:
scope.set_tag("kind", operation_name)
scope.transaction.name = operation_name
if scope.transaction:
scope.transaction.name = operation_name
return execute_func(*args, **kwargs)

def execute_sync(self, *args, **kwargs) -> ExecutionResult:
Expand Down
Loading

0 comments on commit f9c3438

Please sign in to comment.