-
Notifications
You must be signed in to change notification settings - Fork 3
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
Implement Win Loss #808
base: main
Are you sure you want to change the base?
Implement Win Loss #808
Conversation
5218fb3
to
2cf0484
Compare
we should release after this pr is merged |
working win loss tie
2cf0484
to
a5f440a
Compare
const scrimmagingRecordAll = useScrimmagingRecord({ | ||
episodeId, | ||
teamId: team.id, | ||
scrimmageType: CompeteMatchScrimmagingRecordRetrieveScrimmageTypeEnum.All, | ||
}); | ||
const scrimmagingRecordUnranked = useScrimmagingRecord({ | ||
episodeId, | ||
teamId: team.id, | ||
scrimmageType: | ||
CompeteMatchScrimmagingRecordRetrieveScrimmageTypeEnum.Unranked, | ||
}); | ||
const scrimmagingRecordRanked = useScrimmagingRecord({ | ||
episodeId, | ||
teamId: team.id, | ||
scrimmageType: | ||
CompeteMatchScrimmagingRecordRetrieveScrimmageTypeEnum.Ranked, | ||
}); |
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.
These are bits of repeated code that could be pushed into the WinLossTie component by having that component take the scrimmage type.
{!hideAllScrimmages && ( | ||
<WinLossTie | ||
scrimmageType={ | ||
CompeteMatchScrimmagingRecordRetrieveScrimmageTypeEnum.All | ||
} | ||
loading={scrimmagingRecordAll.isFetching} | ||
wins={scrimmagingRecordAll.data?.wins ?? 0} | ||
losses={scrimmagingRecordAll.data?.losses ?? 0} | ||
ties={scrimmagingRecordAll.data?.ties ?? 0} | ||
/> | ||
)} | ||
{!hideUnranked && ( | ||
<WinLossTie | ||
scrimmageType={ | ||
CompeteMatchScrimmagingRecordRetrieveScrimmageTypeEnum.Unranked | ||
} | ||
loading={scrimmagingRecordUnranked.isFetching} | ||
wins={scrimmagingRecordUnranked.data?.wins ?? 0} | ||
losses={scrimmagingRecordUnranked.data?.losses ?? 0} | ||
ties={scrimmagingRecordUnranked.data?.ties ?? 0} | ||
/> | ||
)} | ||
{!hideRanked && ( | ||
<WinLossTie | ||
scrimmageType={ | ||
CompeteMatchScrimmagingRecordRetrieveScrimmageTypeEnum.Ranked | ||
} | ||
loading={scrimmagingRecordRanked.isFetching} | ||
wins={scrimmagingRecordRanked.data?.wins ?? 0} |
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.
We can reduce the repetitiveness of this code by moving the useScrimmagingRecord call into the WinLossTie component
const userTeamRatingData: Record<string, ChartData[]> | undefined = | ||
useMemo(() => { | ||
if (!userTeamRatingHistory.isSuccess) return undefined; | ||
const ratingRecord: Record<string, ChartData[]> = {}; | ||
return userTeamRatingHistory.data.reduce((record, teamData) => { | ||
if (teamData.team_rating !== undefined) { | ||
record[teamData.team_rating.team.name] = | ||
teamData.team_rating.rating_history.map((match) => [ | ||
match.timestamp.getTime(), | ||
match.rating, | ||
]); | ||
} | ||
return record; | ||
}, ratingRecord); | ||
}, [userTeamRatingHistory]); | ||
|
||
const topTeamRatingData: Record<string, ChartData[]> | undefined = | ||
useMemo(() => { | ||
if (!topRatingHistory.isSuccess) return undefined; | ||
const ratingRecord: Record<string, ChartData[]> = {}; | ||
return topRatingHistory.data.reduce((record, teamData) => { | ||
if (teamData.team_rating !== undefined) { | ||
record[teamData.team_rating.team.name] = | ||
teamData.team_rating.rating_history.map((match) => [ | ||
match.timestamp.getTime(), | ||
match.rating, | ||
]); | ||
} | ||
return record; | ||
}, ratingRecord); | ||
}, [topRatingHistory]); |
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.
Lets see if we can improve the repetitiveness of this code. We can probably drop the stuff inside the useMemo into a function that takes a rating history
queryKey: buildKey(scrimmagingRecordFactory.queryKey, { | ||
episodeId, | ||
teamId: teamDataCached.id, | ||
scrimmageType: | ||
CompeteMatchScrimmagingRecordRetrieveScrimmageTypeEnum.Ranked, | ||
}), | ||
}); | ||
|
||
void queryClient.ensureQueryData({ | ||
queryKey: buildKey(scrimmagingRecordFactory.queryKey, { | ||
episodeId, | ||
teamId: teamDataCached.id, | ||
scrimmageType: | ||
CompeteMatchScrimmagingRecordRetrieveScrimmageTypeEnum.Unranked, | ||
}), | ||
}); | ||
|
||
void queryClient.ensureQueryData({ | ||
queryKey: buildKey(scrimmagingRecordFactory.queryKey, { | ||
episodeId, | ||
teamId: teamDataCached.id, | ||
scrimmageType: | ||
CompeteMatchScrimmagingRecordRetrieveScrimmageTypeEnum.All, | ||
}), | ||
}); | ||
} | ||
|
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.
maybe we can reduce the repetitiveness here too? the main thing that's different is the scrimmage type
@@ -1,3 +1,3 @@ | |||
REACT_APP_THIS_URL=http://localhost:3000 | |||
REACT_APP_BACKEND_URL=http://api.staging.battlecode.org/ | |||
REACT_APP_BACKEND_URL=http://localhost:8000 |
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.
i accidentally changed this to staging in a recent pr, it's good that we're changing it back to localhost here
queryset = self.get_queryset().filter(tournament_round__isnull=True) | ||
|
||
scrimmage_type = self.request.query_params.get("scrimmage_type") | ||
if scrimmage_type is not None: | ||
if scrimmage_type == "ranked": | ||
queryset = queryset.filter(is_ranked=True) | ||
elif scrimmage_type == "unranked": | ||
queryset = queryset.filter(is_ranked=False) | ||
|
||
team_id = parse_int(self.request.query_params.get("team_id")) | ||
if team_id is None and request.user.pk is not None: | ||
team_id = ( | ||
Team.objects.filter(members__pk=request.user.pk) | ||
.filter(episode_id=episode_id) | ||
.first() | ||
.id | ||
) | ||
if team_id is None: | ||
return Response(status=status.HTTP_400_BAD_REQUEST) | ||
if team_id is not None: | ||
queryset = queryset.filter(participants__team=team_id) | ||
else: | ||
return Response(status=status.HTTP_400_BAD_REQUEST) | ||
has_invisible = self.get_queryset().filter( | ||
participants__team__status=TeamStatus.INVISIBLE | ||
) | ||
queryset = queryset.exclude(pk__in=Subquery(has_invisible.values("pk"))) | ||
|
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.
see if we can improve this whole function's performance using the code here
#558
Implements the querying of a team's win-loss-tie record and adds the tile to the home screen, account page, and scrimmaging page! Resolves #781 🚀
Tile: