akinator/
models.rs

1use pyo3::prelude::*;
2use akinator_rs::models::Guess as GuessModel;
3
4
5/// a model class representing an akinator's guess
6/// not meant for the user to construct, but is returned in various properties and methods in the `Akinator` class
7#[pyclass]
8#[derive(Debug, Clone)]
9pub struct Guess(
10    pub GuessModel,
11);
12
13#[pymethods]
14impl Guess {
15    fn __repr__(&self) -> String {
16        format!(
17            "<Guess id=\"{}\" name=\"{}\" ranking={}>",
18            self.id(),
19            self.name(),
20            self.ranking(),
21        )
22    }
23
24    /// :class:`str`: the unique ID of the specific guess's entity
25    #[getter]
26    const fn id(&self) -> &String {
27        &self.0.id
28    }
29
30    /// :class:`str`: the common name of the specific guess's entity
31    #[getter]
32    const fn name(&self) -> &String {
33        &self.0.name
34    }
35
36    /// :class:`str`: award id
37    #[getter]
38    const fn award_id(&self) -> &String {
39        &self.0.award_id
40    }
41
42    /// :class:`int`: flag photo
43    #[getter]
44    const fn flag_photo(&self) -> usize {
45        self.0.flag_photo
46    }
47
48    /// :class:`float`: the accuracy / confidence of the akinator that this guess is correct
49    #[getter]
50    fn confidence(&self) -> PyResult<f32> {
51        let conf = self.0.confidence
52            .parse::<f32>()?;
53
54        Ok(conf)
55    }
56
57    /// :class:`str`: a brief description of the specific guess's entity
58    #[getter]
59    const fn description(&self) -> &String {
60        &self.0.description
61    }
62
63    /// :class:`str`: the rank of the specific guess's entity
64    #[getter]
65    const fn ranking(&self) -> &String {
66        &self.0.ranking
67    }
68
69    /// :class:`str`: a relative path to a picture of the guess's entity
70    #[getter]
71    const fn picture_path(&self) -> &String {
72        &self.0.picture_path
73    }
74
75    /// :class:`str`: an absolute url to the picture of the guess's entity
76    #[getter]
77    const fn absolute_picture_path(&self) -> &String {
78        &self.0.absolute_picture_path
79    }
80}