mirror of
https://github.com/chirpstack/chirpstack.git
synced 2025-02-07 11:10:15 +00:00
Change aggregation enum to uppercase.
This is such that the aggregation level in the Redis keys are uppercase.
This commit is contained in:
parent
d974423aab
commit
100e9f1b6d
@ -598,7 +598,7 @@ impl DeviceService for Device {
|
|||||||
|
|
||||||
let device_metrics = metrics::get(
|
let device_metrics = metrics::get(
|
||||||
&format!("device:{}", dev_eui),
|
&format!("device:{}", dev_eui),
|
||||||
metrics::Aggregation::Day,
|
metrics::Aggregation::DAY,
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
)
|
)
|
||||||
|
@ -298,7 +298,7 @@ impl GatewayService for Gateway {
|
|||||||
|
|
||||||
let gw_metrics = metrics::get(
|
let gw_metrics = metrics::get(
|
||||||
&format!("gw:{}", gateway_id),
|
&format!("gw:{}", gateway_id),
|
||||||
metrics::Aggregation::Day,
|
metrics::Aggregation::DAY,
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
)
|
)
|
||||||
|
@ -13,9 +13,9 @@ use crate::storage::{get_redis_conn, redis_key};
|
|||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Deserialize, Serialize, Copy, Clone, Debug, Eq, PartialEq)]
|
||||||
pub enum Aggregation {
|
pub enum Aggregation {
|
||||||
Hour,
|
HOUR,
|
||||||
Day,
|
DAY,
|
||||||
Month,
|
MONTH,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Aggregation {
|
impl fmt::Display for Aggregation {
|
||||||
@ -32,14 +32,14 @@ pub struct Record {
|
|||||||
|
|
||||||
fn get_ttl(a: Aggregation) -> Duration {
|
fn get_ttl(a: Aggregation) -> Duration {
|
||||||
match a {
|
match a {
|
||||||
Aggregation::Hour => Duration::from_secs(60 * 60 * 24 * 2), // two days
|
Aggregation::HOUR => Duration::from_secs(60 * 60 * 24 * 2), // two days
|
||||||
Aggregation::Day => Duration::from_secs(60 * 60 * 24 * 31 * 2), // two months
|
Aggregation::DAY => Duration::from_secs(60 * 60 * 24 * 31 * 2), // two months
|
||||||
Aggregation::Month => Duration::from_secs(60 * 60 * 24 * 365 * 2), // two years
|
Aggregation::MONTH => Duration::from_secs(60 * 60 * 24 * 365 * 2), // two years
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_aggregations() -> Vec<Aggregation> {
|
fn get_aggregations() -> Vec<Aggregation> {
|
||||||
vec![Aggregation::Hour, Aggregation::Day, Aggregation::Month]
|
vec![Aggregation::HOUR, Aggregation::DAY, Aggregation::MONTH]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_key(name: &str, a: Aggregation, dt: DateTime<Local>) -> String {
|
fn get_key(name: &str, a: Aggregation, dt: DateTime<Local>) -> String {
|
||||||
@ -70,13 +70,13 @@ async fn save_for_interval(a: Aggregation, name: &str, record: &Record) -> Resul
|
|||||||
let ttl = get_ttl(a);
|
let ttl = get_ttl(a);
|
||||||
|
|
||||||
let ts: DateTime<Local> = match a {
|
let ts: DateTime<Local> = match a {
|
||||||
Aggregation::Hour => Local
|
Aggregation::HOUR => Local
|
||||||
.ymd(record.time.year(), record.time.month(), record.time.day())
|
.ymd(record.time.year(), record.time.month(), record.time.day())
|
||||||
.and_hms(record.time.hour(), 0, 0),
|
.and_hms(record.time.hour(), 0, 0),
|
||||||
Aggregation::Day => Local
|
Aggregation::DAY => Local
|
||||||
.ymd(record.time.year(), record.time.month(), record.time.day())
|
.ymd(record.time.year(), record.time.month(), record.time.day())
|
||||||
.and_hms(0, 0, 0),
|
.and_hms(0, 0, 0),
|
||||||
Aggregation::Month => Local
|
Aggregation::MONTH => Local
|
||||||
.ymd(record.time.year(), record.time.month(), 1)
|
.ymd(record.time.year(), record.time.month(), 1)
|
||||||
.and_hms(0, 0, 0),
|
.and_hms(0, 0, 0),
|
||||||
};
|
};
|
||||||
@ -119,7 +119,7 @@ pub async fn get(
|
|||||||
let mut timestamps: Vec<DateTime<Local>> = Vec::new();
|
let mut timestamps: Vec<DateTime<Local>> = Vec::new();
|
||||||
|
|
||||||
match a {
|
match a {
|
||||||
Aggregation::Hour => {
|
Aggregation::HOUR => {
|
||||||
let mut ts =
|
let mut ts =
|
||||||
Local
|
Local
|
||||||
.ymd(start.year(), start.month(), start.day())
|
.ymd(start.year(), start.month(), start.day())
|
||||||
@ -134,7 +134,7 @@ pub async fn get(
|
|||||||
ts = ts + ChronoDuration::hours(1);
|
ts = ts + ChronoDuration::hours(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Aggregation::Day => {
|
Aggregation::DAY => {
|
||||||
let mut ts = Local
|
let mut ts = Local
|
||||||
.ymd(start.year(), start.month(), start.day())
|
.ymd(start.year(), start.month(), start.day())
|
||||||
.and_hms(0, 0, 0);
|
.and_hms(0, 0, 0);
|
||||||
@ -149,7 +149,7 @@ pub async fn get(
|
|||||||
ts = (ts + ChronoDuration::days(1)).date().and_hms(0, 0, 0);
|
ts = (ts + ChronoDuration::days(1)).date().and_hms(0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Aggregation::Month => {
|
Aggregation::MONTH => {
|
||||||
let mut ts = Local.ymd(start.year(), start.month(), 1).and_hms(0, 0, 0);
|
let mut ts = Local.ymd(start.year(), start.month(), 1).and_hms(0, 0, 0);
|
||||||
let end = Local.ymd(end.year(), end.month(), 1).and_hms(0, 0, 0);
|
let end = Local.ymd(end.year(), end.month(), 1).and_hms(0, 0, 0);
|
||||||
|
|
||||||
@ -228,14 +228,14 @@ pub mod test {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
for r in &records {
|
for r in &records {
|
||||||
save_for_interval(Aggregation::Hour, "test", r)
|
save_for_interval(Aggregation::HOUR, "test", r)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let resp = get(
|
let resp = get(
|
||||||
"test",
|
"test",
|
||||||
Aggregation::Hour,
|
Aggregation::HOUR,
|
||||||
Local.ymd(2018, 1, 1).and_hms(1, 0, 0),
|
Local.ymd(2018, 1, 1).and_hms(1, 0, 0),
|
||||||
Local.ymd(2018, 1, 1).and_hms(2, 0, 0),
|
Local.ymd(2018, 1, 1).and_hms(2, 0, 0),
|
||||||
)
|
)
|
||||||
@ -291,14 +291,14 @@ pub mod test {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
for r in &records {
|
for r in &records {
|
||||||
save_for_interval(Aggregation::Day, "test", r)
|
save_for_interval(Aggregation::DAY, "test", r)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let resp = get(
|
let resp = get(
|
||||||
"test",
|
"test",
|
||||||
Aggregation::Day,
|
Aggregation::DAY,
|
||||||
Local.ymd(2018, 1, 1).and_hms(1, 0, 0),
|
Local.ymd(2018, 1, 1).and_hms(1, 0, 0),
|
||||||
Local.ymd(2018, 1, 2).and_hms(1, 0, 0),
|
Local.ymd(2018, 1, 2).and_hms(1, 0, 0),
|
||||||
)
|
)
|
||||||
@ -354,14 +354,14 @@ pub mod test {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
for r in &records {
|
for r in &records {
|
||||||
save_for_interval(Aggregation::Month, "test", r)
|
save_for_interval(Aggregation::MONTH, "test", r)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let resp = get(
|
let resp = get(
|
||||||
"test",
|
"test",
|
||||||
Aggregation::Month,
|
Aggregation::MONTH,
|
||||||
Local.ymd(2018, 1, 1).and_hms(0, 0, 0),
|
Local.ymd(2018, 1, 1).and_hms(0, 0, 0),
|
||||||
Local.ymd(2018, 2, 1).and_hms(0, 0, 0),
|
Local.ymd(2018, 2, 1).and_hms(0, 0, 0),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user