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

Function struct_values_to_location

chirpstack/src/integration/influxdb.rs:379–421  ·  view source on GitHub ↗
(
    tags: &HashMap<String, String>,
    prefix: &str,
    v: &HashMap<String, pbjson_types::Value>,
)

Source from the content-addressed store, hash-verified

377}
378
379fn struct_values_to_location(
380 tags: &HashMap<String, String>,
381 prefix: &str,
382 v: &HashMap<String, pbjson_types::Value>,
383) -> Vec<Measurement> {
384 let mut out: Vec<Measurement> = Vec::new();
385 let mut latitude: Option<f64> = None;
386 let mut longitude: Option<f64> = None;
387
388 if let Some(v) = v.get("latitude")
389 && let Some(pbjson_types::value::Kind::NumberValue(n)) = &v.kind
390 {
391 latitude = Some(*n);
392 }
393
394 if let Some(v) = v.get("longitude")
395 && let Some(pbjson_types::value::Kind::NumberValue(n)) = &v.kind
396 {
397 longitude = Some(*n);
398 }
399
400 if let (Some(lat), Some(lon)) = (latitude, longitude) {
401 out.push(Measurement {
402 name: format!("{}_location", prefix),
403 tags: tags.clone(),
404 values: [
405 ("latitude".to_string(), Value::Float(lat)),
406 ("longitude".to_string(), Value::Float(lon)),
407 (
408 "geohash".to_string(),
409 Value::String(
410 geohash::encode(geohash::Coord { x: lon, y: lat }, 12).unwrap_or_default(),
411 ),
412 ),
413 ]
414 .iter()
415 .cloned()
416 .collect(),
417 });
418 }
419
420 out
421}
422
423fn struct_value_to_measurements(
424 tags: &HashMap<String, String>,

Callers 2

struct_to_measurementsFunction · 0.85

Calls 5

pushMethod · 0.80
iterMethod · 0.80
to_stringMethod · 0.80
encodeFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected