@@ -53,6 +53,12 @@ pub(crate) struct KillDeathStatsQuery {
5353 #[ serde( default = "default_min_kills_deaths" ) ]
5454 #[ param( default = default_min_kills_deaths, minimum = 1 ) ]
5555 min_deaths_per_raster : Option < u32 > ,
56+ /// Filter kills based on their game time.
57+ #[ param( maximum = 7000 ) ]
58+ min_game_time_s : Option < u32 > ,
59+ /// Filter kills based on their game time.
60+ #[ param( maximum = 7000 ) ]
61+ max_game_time_s : Option < u32 > ,
5662}
5763
5864#[ derive( Debug , Clone , Row , Serialize , Deserialize , ToSchema ) ]
@@ -110,6 +116,18 @@ fn build_query(query: &KillDeathStatsQuery) -> String {
110116 } else {
111117 format ! ( " AND {}" , info_filters. join( " AND " ) )
112118 } ;
119+ let mut death_filters = vec ! [ ] ;
120+ if let Some ( min_game_time_s) = query. min_game_time_s {
121+ death_filters. push ( format ! ( "dd.game_time_s >= {min_game_time_s}" ) ) ;
122+ }
123+ if let Some ( max_game_time_s) = query. max_game_time_s {
124+ death_filters. push ( format ! ( "dd.game_time_s <= {max_game_time_s}" ) ) ;
125+ }
126+ let death_filters = if death_filters. is_empty ( ) {
127+ String :: new ( )
128+ } else {
129+ format ! ( " AND {}" , death_filters. join( " AND " ) )
130+ } ;
113131 format ! (
114132 "
115133 WITH t_matches AS (SELECT match_id FROM match_info WHERE start_time > now() - interval 2 MONTH {info_filters}),
@@ -118,14 +136,14 @@ fn build_query(query: &KillDeathStatsQuery) -> String {
118136 'death' as type
119137 FROM match_player
120138 ARRAY JOIN death_details as dd
121- WHERE match_id IN t_matches
139+ WHERE match_id IN t_matches {death_filters}
122140 UNION ALL
123141 SELECT toInt32(round(tupleElement(dd.killer_pos, 1), -2)) as position_x,
124142 toInt32(round(tupleElement(dd.killer_pos, 2), -2)) as position_y,
125143 'kill' as type
126144 FROM match_player
127145 ARRAY JOIN death_details as dd
128- WHERE match_id IN t_matches)
146+ WHERE match_id IN t_matches {death_filters} )
129147 SELECT position_x, position_y, count(type = 'death') as deaths, count(type = 'kill') as kills
130148 FROM t_events
131149 GROUP BY position_x, position_y
0 commit comments