-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add competition ranking to leaderboard (#439)
Add competition ranking (1224) to the Leaderboard API.
- Loading branch information
1 parent
023984a
commit df4bd46
Showing
14 changed files
with
178 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use super::fetch::FetchResponse; | ||
use super::Order; | ||
use crate::leaderboard::LeaderboardRequest; | ||
use crate::utils::prep_leaderboard_request_with_timeout; | ||
use crate::{Leaderboard, MomentoResult}; | ||
|
||
/// A request to get ranked elements, sorted by competition ranking, by providing a list of element IDs. | ||
pub struct GetCompetitionRankRequest { | ||
ids: Vec<u32>, | ||
order: Order, | ||
} | ||
|
||
impl GetCompetitionRankRequest { | ||
/// Constructs a new `GetCompetitionRankRequest`. | ||
/// | ||
/// Defaults to DESCENDING order, meaning that rank 0 | ||
/// is the element with the highest score. | ||
pub fn new(ids: impl IntoIterator<Item = u32>) -> Self { | ||
Self { | ||
ids: ids.into_iter().collect(), | ||
order: Order::Descending, | ||
} | ||
} | ||
|
||
/// Sets the order ranking. | ||
/// | ||
/// Defaults to DESCENDING order. | ||
pub fn order(mut self, order: Order) -> Self { | ||
self.order = order; | ||
self | ||
} | ||
} | ||
|
||
impl LeaderboardRequest for GetCompetitionRankRequest { | ||
type Response = FetchResponse; | ||
|
||
async fn send(self, leaderboard: &Leaderboard) -> MomentoResult<Self::Response> { | ||
let cache_name = leaderboard.cache_name(); | ||
let request = prep_leaderboard_request_with_timeout( | ||
cache_name, | ||
leaderboard.client_timeout(), | ||
momento_protos::leaderboard::GetCompetitionRankRequest { | ||
leaderboard: leaderboard.leaderboard_name().to_string(), | ||
ids: self.ids, | ||
order: Some(self.order.into_proto() as i32), | ||
}, | ||
)?; | ||
|
||
let response = leaderboard | ||
.next_data_client() | ||
.get_competition_rank(request) | ||
.await? | ||
.into_inner(); | ||
|
||
Ok(FetchResponse::new( | ||
response.elements.iter().map(|v| v.into()).collect(), | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters