MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / get

Function get

chirpstack/src/storage/metrics.rs:178–308  ·  view source on GitHub ↗
(
    name: &str,
    kind: Kind,
    a: Aggregation,
    start: DateTime<Local>,
    end: DateTime<Local>,
)

Source from the content-addressed store, hash-verified

176}
177
178pub async fn get(
179 name: &str,
180 kind: Kind,
181 a: Aggregation,
182 start: DateTime<Local>,
183 end: DateTime<Local>,
184) -> Result<Vec<Record>> {
185 let mut keys: Vec<String> = Vec::new();
186 let mut timestamps: Vec<NaiveDateTime> = Vec::new();
187
188 match a {
189 Aggregation::MINUTE => {
190 let mut ts = NaiveDate::from_ymd_opt(start.year(), start.month(), start.day())
191 .ok_or_else(|| anyhow!("Invalid date"))?
192 .and_hms_opt(start.hour(), start.minute(), 0)
193 .ok_or_else(|| anyhow!("Invalid time"))?;
194 let end = NaiveDate::from_ymd_opt(end.year(), end.month(), end.day())
195 .ok_or_else(|| anyhow!("Invalid date"))?
196 .and_hms_opt(end.hour(), end.minute(), 0)
197 .ok_or_else(|| anyhow!("Invalid time"))?;
198
199 while ts.le(&end) {
200 timestamps.push(ts);
201 keys.push(get_key(name, a, ts));
202 ts += ChronoDuration::minutes(1);
203 }
204 }
205 Aggregation::HOUR => {
206 let mut ts = NaiveDate::from_ymd_opt(start.year(), start.month(), start.day())
207 .ok_or_else(|| anyhow!("Invalid date"))?
208 .and_hms_opt(start.hour(), 0, 0)
209 .ok_or_else(|| anyhow!("Invalid time"))?;
210 let end = NaiveDate::from_ymd_opt(end.year(), end.month(), end.day())
211 .ok_or_else(|| anyhow!("Invalid date"))?
212 .and_hms_opt(end.hour(), 0, 0)
213 .ok_or_else(|| anyhow!("Invalid time"))?;
214
215 while ts.le(&end) {
216 timestamps.push(ts);
217 keys.push(get_key(name, a, ts));
218 ts += ChronoDuration::hours(1);
219 }
220 }
221 Aggregation::DAY => {
222 let mut ts = NaiveDate::from_ymd_opt(start.year(), start.month(), start.day())
223 .ok_or_else(|| anyhow!("Invalid date"))?
224 .and_hms_opt(0, 0, 0)
225 .ok_or_else(|| anyhow!("Invalid time"))?;
226 let end = NaiveDate::from_ymd_opt(end.year(), end.month(), end.day())
227 .ok_or_else(|| anyhow!("Invalid date"))?
228 .and_hms_opt(0, 0, 0)
229 .ok_or_else(|| anyhow!("Invalid time"))?;
230
231 while ts.le(&end) {
232 timestamps.push(ts);
233 keys.push(get_key(name, a, ts));
234 ts += ChronoDuration::days(1);
235 }

Callers 7

test_hourFunction · 0.70
test_dayFunction · 0.70
test_day_dst_transitionFunction · 0.70
test_monthFunction · 0.70
test_counterFunction · 0.70
test_absoluteFunction · 0.70
test_gaugeFunction · 0.70

Calls 6

get_async_redis_connFunction · 0.85
pushMethod · 0.80
iterMethod · 0.80
to_stringMethod · 0.80
unwrapMethod · 0.80
get_keyFunction · 0.70

Tested by 7

test_hourFunction · 0.56
test_dayFunction · 0.56
test_day_dst_transitionFunction · 0.56
test_monthFunction · 0.56
test_counterFunction · 0.56
test_absoluteFunction · 0.56
test_gaugeFunction · 0.56