Skip to content

Commit cec9ea0

Browse files
update to use proto with hex as a CellIndex and grid_distance
1 parent 279f304 commit cec9ea0

File tree

11 files changed

+173
-179
lines changed

11 files changed

+173
-179
lines changed

Cargo.lock

+38-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ helium-lib = { git = "https://github.com/helium/helium-wallet-rs.git", branch =
7070
hextree = { git = "https://github.com/jaykickliter/HexTree", branch = "main", features = [
7171
"disktree",
7272
] }
73-
helium-proto = { git = "https://github.com/helium/proto", branch = "macpie/radio_location_estimates", features = [
73+
helium-proto = { git = "https://github.com/helium/proto", branch = "mj/radio_location_esimates_with_hexes", features = [
7474
"services",
7575
] }
76-
beacon = { git = "https://github.com/helium/proto", branch = "macpie/radio_location_estimates" }
76+
beacon = { git = "https://github.com/helium/proto", branch = "mj/radio_location_esimates_with_hexes" }
7777
solana-client = "1.18"
7878
solana-sdk = "1.18"
7979
solana-program = "1.18"

file_store/src/error.rs

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ pub enum Error {
4141
//Not recommended for internal use!
4242
#[error("external error")]
4343
ExternalError(#[from] Box<dyn std::error::Error + Send + Sync>),
44+
#[error("error parsing decimal")]
45+
IntoDecimal(#[from] rust_decimal::Error),
4446
}
4547

4648
#[derive(Error, Debug)]

file_store/src/radio_location_estimates.rs

+32-26
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use crate::{
33
Error, Result,
44
};
55
use chrono::{DateTime, Utc};
6+
use h3o::CellIndex;
67
use helium_crypto::PublicKeyBinary;
78
use helium_proto::services::poc_mobile::{
8-
self as proto, RadioLocationEstimateV1, RadioLocationEstimatesReqV1, RleEventV1,
9+
self as proto, RadioLocationCorrelationV1, RadioLocationEstimateV1, RadioLocationEstimatesReqV1,
910
};
1011
use rust_decimal::Decimal;
1112
use serde::{Deserialize, Serialize};
@@ -108,73 +109,77 @@ impl TryFrom<RadioLocationEstimatesReqV1> for RadioLocationEstimatesReq {
108109

109110
#[derive(Clone, Deserialize, Serialize, Debug, PartialEq)]
110111
pub struct RadioLocationEstimate {
111-
pub radius: Decimal,
112-
pub lat: Decimal,
113-
pub lon: Decimal,
112+
pub hex: CellIndex,
113+
pub grid_distance: u32,
114114
pub confidence: Decimal,
115-
pub events: Vec<RadioLocationEstimateEvent>,
115+
pub radio_location_correlations: Vec<RadioLocationCorrelation>,
116116
}
117117

118118
impl From<RadioLocationEstimate> for RadioLocationEstimateV1 {
119119
fn from(rle: RadioLocationEstimate) -> Self {
120120
RadioLocationEstimateV1 {
121-
radius: Some(to_proto_decimal(rle.radius)),
122-
lat: Some(to_proto_decimal(rle.lat)),
123-
lon: Some(to_proto_decimal(rle.lon)),
121+
hex: rle.hex.into(),
122+
grid_distance: rle.grid_distance,
124123
confidence: Some(to_proto_decimal(rle.confidence)),
125-
events: rle.events.into_iter().map(|e| e.into()).collect(),
124+
radio_location_correlations: rle
125+
.radio_location_correlations
126+
.into_iter()
127+
.map(|e| e.into())
128+
.collect(),
126129
}
127130
}
128131
}
129132

130133
impl TryFrom<RadioLocationEstimateV1> for RadioLocationEstimate {
131134
type Error = Error;
132135
fn try_from(estimate: RadioLocationEstimateV1) -> Result<Self> {
136+
let hex = CellIndex::try_from(estimate.hex)
137+
.map_err(crate::error::DecodeError::InvalidCellIndexError)?;
138+
133139
Ok(Self {
134-
radius: to_rust_decimal(estimate.radius.unwrap()),
135-
lat: to_rust_decimal(estimate.lat.unwrap()),
136-
lon: to_rust_decimal(estimate.lon.unwrap()),
137-
confidence: to_rust_decimal(estimate.confidence.unwrap()),
138-
events: estimate
139-
.events
140+
hex,
141+
grid_distance: estimate.grid_distance,
142+
confidence: to_rust_decimal(estimate.confidence)?,
143+
radio_location_correlations: estimate
144+
.radio_location_correlations
140145
.into_iter()
141-
.map(|e| e.try_into().unwrap())
146+
.flat_map(|rlc| rlc.try_into())
142147
.collect(),
143148
})
144149
}
145150
}
146151

147152
#[derive(Clone, Deserialize, Serialize, Debug, PartialEq)]
148-
pub struct RadioLocationEstimateEvent {
153+
pub struct RadioLocationCorrelation {
149154
pub id: String,
150155
pub timestamp: DateTime<Utc>,
151156
}
152157

153-
impl MsgTimestamp<Result<DateTime<Utc>>> for RleEventV1 {
158+
impl MsgTimestamp<Result<DateTime<Utc>>> for RadioLocationCorrelationV1 {
154159
fn timestamp(&self) -> Result<DateTime<Utc>> {
155160
self.timestamp.to_timestamp()
156161
}
157162
}
158163

159-
impl MsgTimestamp<u64> for RadioLocationEstimateEvent {
164+
impl MsgTimestamp<u64> for RadioLocationCorrelation {
160165
fn timestamp(&self) -> u64 {
161166
self.timestamp.encode_timestamp()
162167
}
163168
}
164169

165-
impl From<RadioLocationEstimateEvent> for RleEventV1 {
166-
fn from(event: RadioLocationEstimateEvent) -> Self {
170+
impl From<RadioLocationCorrelation> for RadioLocationCorrelationV1 {
171+
fn from(event: RadioLocationCorrelation) -> Self {
167172
let timestamp = event.timestamp();
168-
RleEventV1 {
173+
RadioLocationCorrelationV1 {
169174
id: event.id,
170175
timestamp,
171176
}
172177
}
173178
}
174179

175-
impl TryFrom<RleEventV1> for RadioLocationEstimateEvent {
180+
impl TryFrom<RadioLocationCorrelationV1> for RadioLocationCorrelation {
176181
type Error = Error;
177-
fn try_from(event: RleEventV1) -> Result<Self> {
182+
fn try_from(event: RadioLocationCorrelationV1) -> Result<Self> {
178183
let timestamp = event.timestamp()?;
179184
Ok(Self {
180185
id: event.id,
@@ -183,9 +188,10 @@ impl TryFrom<RleEventV1> for RadioLocationEstimateEvent {
183188
}
184189
}
185190

186-
fn to_rust_decimal(x: helium_proto::Decimal) -> rust_decimal::Decimal {
191+
fn to_rust_decimal(x: Option<helium_proto::Decimal>) -> Result<rust_decimal::Decimal> {
192+
let x = x.ok_or(Error::NotFound("Decimal".to_string()))?;
187193
let str = x.value.as_str();
188-
rust_decimal::Decimal::from_str_exact(str).unwrap()
194+
Ok(rust_decimal::Decimal::from_str_exact(str)?)
189195
}
190196

191197
fn to_proto_decimal(x: rust_decimal::Decimal) -> helium_proto::Decimal {

ingest/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ custom-tracing = { path = "../custom_tracing", features = ["grpc"] }
1717
file-store = { path = "../file_store" }
1818
futures = { workspace = true }
1919
futures-util = { workspace = true }
20+
h3o = { workspace = true }
2021
helium-crypto = { workspace = true }
2122
helium-proto = { workspace = true }
2223
http = { workspace = true }

0 commit comments

Comments
 (0)