mangadex_api_schema_rust/v5/statistics/
manga.rs

1//! Manga statistics from a response body.
2
3use std::collections::HashMap;
4
5use mangadex_api_types::ResultType;
6use serde::Deserialize;
7use uuid::Uuid;
8
9use super::Comments;
10
11#[derive(Clone, Debug, Deserialize)]
12#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
13#[serde(rename_all = "camelCase")]
14#[non_exhaustive]
15#[cfg_attr(feature = "specta", derive(specta::Type))]
16pub struct MangaStatisticsObject {
17    #[serde(default)]
18    pub result: ResultType,
19    /// JSON object of `MangaId-StatisticsObject`.
20    pub statistics: HashMap<Uuid, MangaStatistics>,
21}
22
23#[derive(Clone, Debug, Deserialize, Copy)]
24#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
25#[cfg_attr(feature = "specta", derive(specta::Type))]
26#[non_exhaustive]
27pub struct MangaStatistics {
28    pub rating: MangaRating,
29    /// Number of users following the Manga.
30    // The API documentation has placed this within the `rating` object as of MangaDex API 5.4.9 but
31    // the actual response has this field at this level.
32    pub follows: u32,
33    pub comments: Option<Comments>,
34    #[serde(default)]
35    pub unavailable_chapter_count: u32,
36}
37
38#[derive(Clone, Debug, Deserialize, Copy)]
39#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
40#[cfg_attr(feature = "specta", derive(specta::Type))]
41#[non_exhaustive]
42pub struct MangaRating {
43    /// Average rating of distributed votes.
44    ///
45    /// Ratings values with no votes are not included in the calculation.
46    ///
47    /// Will be `None` if no ratings calculations have been done.
48    #[serde(default)]
49    pub average: Option<f32>,
50    #[serde(default)]
51    pub bayesian: Option<f32>,
52    /// Ordered distribution of ratings from 1 to 10.
53    ///
54    /// Array indices correspond to the rating value.
55    ///
56    /// Each element corresponds to the number of users that have given that rating.
57    #[serde(default)]
58    #[cfg_attr(feature = "specta", specta(type = HashMap<String, u32>))]
59    pub distribution: RatingsDistribution,
60}
61
62/// Distribution of ratings from 1 to 10.
63///
64/// Because Rust identifies may not begin with a number, the fields are prefixed with an arbitrary
65/// "r" to denote "rating".
66#[derive(Clone, Debug, Deserialize, Default, Copy)]
67#[cfg_attr(feature = "serialize", derive(serde::Serialize))]
68#[non_exhaustive]
69pub struct RatingsDistribution {
70    #[serde(rename = "1")]
71    pub r1: u32,
72    #[serde(rename = "2")]
73    pub r2: u32,
74    #[serde(rename = "3")]
75    pub r3: u32,
76    #[serde(rename = "4")]
77    pub r4: u32,
78    #[serde(rename = "5")]
79    pub r5: u32,
80    #[serde(rename = "6")]
81    pub r6: u32,
82    #[serde(rename = "7")]
83    pub r7: u32,
84    #[serde(rename = "8")]
85    pub r8: u32,
86    #[serde(rename = "9")]
87    pub r9: u32,
88    #[serde(rename = "10")]
89    pub r10: u32,
90}