-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re-implement evaluator using weighted kda from config
- Loading branch information
1 parent
d4cb21c
commit f64c89e
Showing
5 changed files
with
80 additions
and
105 deletions.
There are no files selected for viewing
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use serde::Deserialize; | ||
use std::collections::HashMap; | ||
use the_collector_db::model::{Match, SummonerMatch}; | ||
use weight::{WeightedKda, Weights}; | ||
|
||
pub mod weight; | ||
|
||
#[derive(Debug, PartialEq, Eq, Hash, Deserialize)] | ||
#[serde(rename_all = "snake_case")] | ||
enum Role { | ||
Top, | ||
Jungle, | ||
Mid, | ||
Bot, | ||
Support, | ||
Other, | ||
} | ||
|
||
impl From<&str> for Role { | ||
fn from(value: &str) -> Self { | ||
// Match to values from Riot API | ||
match value.to_lowercase().as_str() { | ||
"top" => Role::Top, | ||
"jungle" => Role::Jungle, | ||
"middle" => Role::Mid, | ||
"bottom" => Role::Bot, | ||
"utility" => Role::Support, | ||
_ => Role::Other, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Deserialize, Default)] | ||
pub struct MatchStatsEvaluator { | ||
kda_weights: HashMap<Role, Weights>, | ||
kda_limit: WeightedKda, | ||
} | ||
|
||
impl MatchStatsEvaluator { | ||
pub fn is_int(&self, match_stats: &SummonerMatch, _match_data: &Match) -> bool { | ||
// Don't send a message for insignificant scoreline | ||
if match_stats.deaths <= 4 && match_stats.kills >= 1 { | ||
return false; | ||
} | ||
|
||
// If their weighted KDA is less than <= 0, evaluate as an int | ||
let role = match_stats | ||
.position | ||
.as_ref() | ||
.map(String::as_str) | ||
.unwrap_or("other") | ||
.into(); | ||
self.kda_weights[&role].calculate_weighted_kda(match_stats) <= self.kda_limit | ||
} | ||
} |
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,21 @@ | ||
use serde::Deserialize; | ||
use the_collector_db::model::SummonerMatch; | ||
|
||
#[derive(Debug, PartialEq, PartialOrd, Deserialize, Default)] | ||
pub struct WeightedKda(pub f32); | ||
|
||
#[derive(Debug, PartialEq, PartialOrd, Deserialize)] | ||
pub struct Weights { | ||
kill_weight: f32, | ||
death_weight: f32, | ||
assist_weight: f32, | ||
} | ||
|
||
impl Weights { | ||
pub fn calculate_weighted_kda(&self, stats: &SummonerMatch) -> WeightedKda { | ||
let inner = (self.kill_weight * stats.kills as f32) | ||
+ (self.death_weight * stats.deaths as f32) | ||
+ (self.assist_weight * stats.assists as f32); | ||
WeightedKda(inner) | ||
} | ||
} |
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