Function determine_solo_flex

Source
pub fn determine_solo_flex(
    rank_info: &Vec<HashMap<String, Value>>,
    default_rank: &HashMap<String, Value>,
) -> (HashMap<String, Value>, HashMap<String, Value>)
Expand description

⚙️ Function: Determines Solo/Duo and Flex ranks from rank information.

This function analyzes a list of rank information and determines the Solo/Duo and Flex ranks based on the provided data. It checks the queueType field in the rank data to distinguish between Solo/Duo and Flex ranks. If no rank data is available for a specific queue, it returns a default rank.

§Parameters:

  • rank_info: A vector containing rank information in the form of a list of HashMap<String, serde_json::Value>. Each HashMap represents a rank type with various rank data, including queueType.
  • default_rank: A default rank (HashMap<String, serde_json::Value>) to return if the corresponding rank information is missing.

§Returns:

  • (HashMap<String, serde_json::Value>, HashMap<String, serde_json::Value>): A tuple containing two HashMap values, where the first element is the Solo/Duo rank and the second is the Flex rank.

§⚠️ Notes:

  • The function expects the queueType field to differentiate between “RANKED_SOLO_5x5” and “RANKED_FLEX_SR”.
  • If rank information is missing for either Solo/Duo or Flex, the function returns the default_rank for that rank type.
  • It assumes that the first element in the rank_info corresponds to Flex if queueType is “RANKED_FLEX_SR”, otherwise it assumes the first element is Solo/Duo.

§Example:

let rank_info = vec![
    hashmap! { "queueType".to_string() => serde_json::Value::String("RANKED_FLEX_SR".to_string()) },
    hashmap! { "queueType".to_string() => serde_json::Value::String("RANKED_SOLO_5x5".to_string()) }
];
let default_rank = hashmap! { "tier".to_string() => serde_json::Value::String("UNRANKED".to_string()) };

let (solo_rank, flex_rank) = determine_solo_flex(&rank_info, &default_rank);

assert_eq!(solo_rank.get("queueType").unwrap(), "RANKED_SOLO_5x5");
assert_eq!(flex_rank.get("queueType").unwrap(), "RANKED_FLEX_SR");

In this example, the function will correctly identify the Solo/Duo and Flex ranks based on the queueType values provided in rank_info.