1#![allow(dead_code, unused_imports)]
2mod ergast;
3mod historical;
4mod livetiming;
5mod season;
6mod weekend;
7
8pub use season::Season;
9pub use weekend::Weekend;
10
11use chrono::prelude::*;
12use std::collections::HashMap;
13use std::fmt;
14use std::sync::MutexGuard;
15use std::sync::PoisonError;
16use thiserror::Error;
17
18const EARLIEST_SEASON: i32 = 1950;
19
20#[derive(Error, Debug)]
21pub enum F1Error {
22 #[error("API JSON deserialization problem")]
23 JsonDeserialization,
24 #[error("API not reachable")]
25 ApiNotReachable,
26 #[error("Cache Error")]
27 Cache,
28}
29
30#[derive(PartialEq, Debug, Clone)]
31pub enum SessionType {
32 Practice1,
33 Practice2,
34 Practice3,
35 Qualifying,
36 Sprint,
37 Race,
38}
39
40impl Default for SessionType {
41 fn default() -> Self {
42 Self::Race
43 }
44}
45
46impl fmt::Display for SessionType {
47 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48 write!(f, "{:?}", self)
49 }
50}
51
52#[derive(Debug, Default, Clone)]
53pub struct Constructor {
54 id: String,
55 name: String,
56}
57
58#[derive(Clone, Debug, Default)]
59pub struct Driver {
60 id: String,
61 first_name: String,
62 last_name: String,
63 pub screen_name: String,
64}
65
66#[derive(Clone, Debug)]
67pub struct Standing {
68 pub driver: Driver,
69 constructor: Constructor,
70 pub position: i32,
71 pub lap_time: chrono::NaiveTime,
72}
73
74impl Default for Standing {
75 fn default() -> Self {
76 Self {
77 driver: Default::default(),
78 constructor: Default::default(),
79 position: Default::default(),
80 lap_time: NaiveTime::from_hms(0, 0, 0),
81 }
82 }
83}
84
85#[derive(Clone, Debug, Default)]
86pub struct Session {
87 pub r#type: SessionType,
88 finished: bool,
89 pub standings: Vec<Standing>,
90}
91
92#[derive(Clone, Debug, Default)]
93pub struct Circuit {
94 id: String,
95 pub name: String,
96 pub latitude: f32,
97 pub longitude: f32,
98 pub locality: String,
99 pub country: String,
100}
101
102pub fn get_available_seasons() -> Vec<i32> {
103 (EARLIEST_SEASON..Utc::now().year() + 1).rev().collect()
104}
105
106#[cfg(test)]
107mod tests {
108 use super::*;
109 use crate::*;
110
111 #[test]
112 fn test_type_to_string() {
113 let quali = SessionType::Qualifying;
114 assert_eq!(quali.to_string(), "Qualifying".to_string());
115
116 let race = SessionType::Race;
117 assert_eq!(race.to_string(), "Race".to_string());
118 }
119}