Skip to main content

sunday_slate/scoring/
service.rs

1use crate::entries::Lineup;
2use nfl_data::Snapshot;
3use std::collections::HashSet;
4
5use crate::entries::FantasyTeamEntry;
6use nfl_data::slates::SlateId;
7
8/// Does not check official eligibility; callers must select eligible slates.
9pub fn lineup_total(lineup: &Lineup, snapshot: &Snapshot, slate_id: SlateId) -> f64 {
10    let players: f64 = lineup
11        .player_ids()
12        .iter()
13        .filter_map(|id| snapshot.player(&slate_id, id))
14        .filter_map(|player| player.scored_stats.as_ref())
15        .map(|scored| scored.score.total)
16        .sum();
17    let defense = snapshot
18        .defense(&slate_id, &lineup.def)
19        .and_then(|player| player.scored_stats.as_ref())
20        .map_or(0.0, |scored| scored.score.total);
21    players + defense
22}
23
24pub fn score_entries(
25    entries: &[FantasyTeamEntry],
26    snapshot: &Snapshot,
27    official_slates: &HashSet<SlateId>,
28) -> Vec<(SlateId, f64)> {
29    entries
30        .iter()
31        .filter(|entry| official_slates.contains(&entry.slate_id))
32        .map(|entry| {
33            (
34                entry.slate_id,
35                lineup_total(&entry.lineup, snapshot, entry.slate_id),
36            )
37        })
38        .collect()
39}