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
use {
crate::*,
std::{
fmt::Display,
hash::Hash,
},
};
pub struct LineGroup<'b, T>
where
T: Display + Hash + Eq + 'b,
{
pub value: T,
pub lines: Vec<&'b LogLine>,
pub trend: Trend,
pub bytes: u64,
pub key_sum: u64,
}
impl<'b, T> LineGroup<'b, T>
where
T: Display + Hash + Eq + 'b,
{
pub fn new(
value: T,
lines: Vec<&'b LogLine>,
trend_computer: &TrendComputer,
) -> Self {
debug_assert!(!lines.is_empty());
let trend = trend_computer.compute_trend(&lines);
let bytes = lines.iter().map(|ll| ll.bytes_sent).sum();
let key_sum = match trend_computer.key {
Key::Hits => lines.len() as u64,
Key::Bytes => bytes,
};
Self {
value,
lines,
trend,
bytes,
key_sum,
}
}
pub fn any(&self) -> &LogLine {
&self.lines[0]
}
pub fn hits(&self) -> usize {
self.lines.len()
}
pub fn histo_line(&self) -> String {
histo_line(
&self.trend.sum_per_day,
self.trend.max_day_count(),
false,
)
}
}