@@ -21,6 +21,7 @@ use std::{
2121 sync:: { Arc , Mutex } ,
2222} ;
2323
24+ use crate :: cli:: types:: filters:: { FantasyTeamFilter , InjuryStatusFilter , RosterStatusFilter } ;
2425use crate :: { LeagueId , PlayerId , Position , Season , Week } ;
2526
2627/// Path: ~/.cache/league_settings-{season}-{league_id}.json
@@ -79,6 +80,9 @@ pub struct PlayerDataCacheKey {
7980 pub player_names : Option < Vec < String > > ,
8081 pub positions : Option < Vec < Position > > ,
8182 pub projected : bool ,
83+ pub injury_status : Option < InjuryStatusFilter > ,
84+ pub roster_status : Option < RosterStatusFilter > ,
85+ pub fantasy_team_filter : Option < FantasyTeamFilter > ,
8286}
8387
8488impl CacheKey for PlayerDataCacheKey {
@@ -104,12 +108,38 @@ impl CacheKey for PlayerDataCacheKey {
104108 } )
105109 . unwrap_or_else ( || "all_pos" . to_string ( ) ) ;
106110
111+ let injury_hash = self
112+ . injury_status
113+ . as_ref ( )
114+ . map ( |status| format ! ( "inj_{}" , status. to_string( ) . to_lowercase( ) ) )
115+ . unwrap_or_else ( || "all_inj" . to_string ( ) ) ;
116+
117+ let roster_hash = self
118+ . roster_status
119+ . as_ref ( )
120+ . map ( |status| format ! ( "ros_{}" , status. to_string( ) . to_lowercase( ) ) )
121+ . unwrap_or_else ( || "all_ros" . to_string ( ) ) ;
122+
123+ let team_hash = self
124+ . fantasy_team_filter
125+ . as_ref ( )
126+ . map ( |filter| match filter {
127+ FantasyTeamFilter :: Id ( id) => format ! ( "team_id_{}" , id) ,
128+ FantasyTeamFilter :: Name ( name) => {
129+ format ! ( "team_name_{}" , name. to_lowercase( ) . replace( ' ' , "_" ) )
130+ }
131+ } )
132+ . unwrap_or_else ( || "all_teams" . to_string ( ) ) ;
133+
107134 format ! (
108- "player_data_s{}_w{}_{}_{}_{}" ,
135+ "player_data_s{}_w{}_{}_{}_{}_{}_{}_{} " ,
109136 self . season. as_u16( ) ,
110137 self . week. as_u16( ) ,
111138 names_hash,
112139 positions_hash,
140+ injury_hash,
141+ roster_hash,
142+ team_hash,
113143 if self . projected { "proj" } else { "actual" }
114144 )
115145 }
@@ -448,6 +478,9 @@ mod tests {
448478 player_names : Some ( vec ! [ "Josh Allen" . to_string( ) ] ) ,
449479 positions : None ,
450480 projected : false ,
481+ injury_status : None ,
482+ roster_status : None ,
483+ fantasy_team_filter : None ,
451484 } ;
452485
453486 let file_key = key. to_file_key ( ) ;
0 commit comments