-
Notifications
You must be signed in to change notification settings - Fork 1
/
qt.rs
97 lines (84 loc) · 3.55 KB
/
qt.rs
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#![cfg(feature = "qt")]
use super::super::stats::*;
use qml::*;
pub fn output(gathered: &AllResultStat) {
let mut engine = QmlEngine::new();
save_data(gathered, &mut engine);
}
fn save_data(gathered: &AllResultStat, engine: &mut QmlEngine) {
let total = gathered.common_stats.get("TOTAL").unwrap();
let days = total.days;
// Functions that replaces code phrases in a given string
fn replace(c: &str, num: u32, i: usize, engine: &mut QmlEngine) {
let rep: &str = &num.to_string();
engine.set_and_store_property(&format!("{}{}", c, i), rep)
}
for (i, item) in days.iter().enumerate().map(|(i, e)| (i + 1, e)) {
replace("c", item.commits, i, engine);
replace("a", item.inserts, i, engine);
replace("d", item.dels, i, engine);
}
let times = total.daytimes;
for (i, item) in times.iter().enumerate().map(|(i, e)| (i + 1, e)) {
replace("cdt", item.commits, i, engine);
}
const MONTHES: [&'static str; 12] = ["January",
"February",
"March",
"April",
"May",
"June",
"Jule",
"August",
"September",
"October",
"November",
"December"];
let mut qalm = QListModel::new(&["date", "user", "commits", "adds", "dels"]);
for t in &gathered.top_monthly {
let vec: Vec<QVariant> = vec![format!("{}, {}", t.year, MONTHES[t.month as usize]).into(),
(&t.sign.0 as &str).into(),
(t.stat.commits as i32).into(),
(t.stat.inserts as i32).into(),
(t.stat.dels as i32).into()];
qalm.insert_row(vec.into_iter());
}
let qvar = qalm.get_qvar();
engine.set_property("contrs", &qvar);
let mut languages: Vec<String> = Vec::new();
let mut categories: Vec<String> = Vec::new();
// Fill with all languages
for &LanguageStatSnapshot(year, month, ref map) in &gathered.lang_stats {
for lang in map.keys() {
if !languages.contains(lang) {
languages.push(lang.clone());
}
}
let mut formed = format!("{}, {}", year, MONTHES[month as usize]);
if categories.contains(&formed) {
let mut start = 1;
while categories.contains(&(formed.clone() + &format!(" ({})", start))) {
start += 1;
}
formed = formed + &format!(" ({})", start);
}
categories.push(formed);
}
let categories: Vec<QVariant> = categories.into_iter().map(|s| s.into()).collect();
let mut bars: Vec<QVariant> = Vec::new();
for lang in languages.into_iter() {
let mut lang_data: Vec<QVariant> = Vec::new();
for &LanguageStatSnapshot(_, _, ref map) in &gathered.lang_stats {
lang_data.push(if let Some(n) = map.get(&lang) {
*n as i32
} else {
0
}
.into());
}
bars.push(qvarlist![lang, lang_data].into());
}
engine.set_and_store_property("values", qvarlist![categories, bars]);
engine.load_data(include_str!("chart.qml"));
engine.exec();
}