1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use time::{Duration, Timespec};
use std::collections::BTreeMap;
use std::convert::From;
use error::{Error, ProtoError};
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Stats {
pub artists: u32,
pub albums: u32,
pub songs: u32,
pub uptime: Duration,
pub playtime: Duration,
pub db_playtime: Duration,
pub db_update: Timespec,
}
impl Stats {
pub fn from_map(map: BTreeMap<String, String>) -> Result<Stats, Error> {
Ok(Stats {
artists: get_field!(map, "artists"),
albums: get_field!(map, "albums"),
songs: get_field!(map, "songs"),
uptime: Duration::seconds(get_field!(map, "uptime")),
playtime: Duration::seconds(get_field!(map, "playtime")),
db_playtime: Duration::seconds(get_field!(map, "db_playtime")),
db_update: Timespec::new(get_field!(map, "db_update"), 0),
})
}
}