Skip to content

Commit

Permalink
Landtype Boosting (#789)
Browse files Browse the repository at this point in the history
* add landtype to hex boosting

- initialize hexes without a landtype assignment
- load landtype disktree
- update tests to match HIP-103 chart with all 3 data sets

* use struct HexAssignments

HexAssignemnts wrap and labels Assignments. The order Assignments are
considered is not always clear unless you have HIP-103 up next to the
code. So we try to funnel all uses of the fields together into one
place, and callers deal with Assignments as a collection.

* reify HexBoostData for CoverageDaemon

This is an attempt to simplify the trait soup hex boosting was starting
to become. Until there is a concrete need for more traits, I believe
this flow is easier to follow, and easier to mock at the level desired
in tests.

* remove unused trait

* add mobile-verifier command to verify disktree

This command makes sure all values in a disktree file can be turned into
Assignment.

* rename WorldCover -> Landtype to match HIP

* add from_paths constructor to Geofence

Now a geofence can be constructed directly without needing to go through
a file if you have a HexTreeSet.

* match printing order with HIP order

The tables in HIP-103 list the assignments (AAA, ABC, etc,.) in the
order (footfall, landtype, urbanized). Having the Debug repr of
Assignments print in the same order makes it easier to cross reference
with the tables.

* Unit test for HexAssignments

This test will break if the logic for deriving scores changes. If the
break is on purpose, the test should be updated.

* match comments

* update proto dep after rebase

* Update number of fields in hex update query

* remove unused test code

* implement From for the proto type, avoid base type

This forces us to go through the proto enum, but provides a stronger
contract for going between types. very nice

* update proto back to master

---------

Co-authored-by: Brian Balser <[email protected]>
  • Loading branch information
michaeldjeffrey and bbalser authored Apr 24, 2024
1 parent 992d80c commit f4a60da
Show file tree
Hide file tree
Showing 17 changed files with 800 additions and 464 deletions.
39 changes: 15 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mobile_verifier/migrations/32_landtype.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE hexes ADD COLUMN landtype oracle_assignment;
117 changes: 64 additions & 53 deletions mobile_verifier/src/boosting_oracles/assignment.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
use helium_proto::services::poc_mobile::oracle_boosting_hex_assignment;
use helium_proto::services::poc_mobile::oracle_boosting_hex_assignment::Assignment as ProtoAssignment;
use rust_decimal::Decimal;
use rust_decimal_macros::dec;
use std::fmt;

#[derive(Debug, Clone, PartialEq, Eq, sqlx::FromRow)]
pub struct HexAssignments {
pub footfall: Assignment,
pub landtype: Assignment,
pub urbanized: Assignment,
}

#[derive(Copy, Clone, PartialEq, Eq, Debug, sqlx::Type)]
#[sqlx(type_name = "oracle_assignment")]
#[sqlx(rename_all = "lowercase")]
Expand All @@ -12,7 +19,7 @@ pub enum Assignment {
C,
}

impl From<Assignment> for oracle_boosting_hex_assignment::Assignment {
impl From<Assignment> for ProtoAssignment {
fn from(assignment: Assignment) -> Self {
match assignment {
Assignment::A => Self::A,
Expand All @@ -24,7 +31,17 @@ impl From<Assignment> for oracle_boosting_hex_assignment::Assignment {

impl From<Assignment> for i32 {
fn from(assignment: Assignment) -> i32 {
oracle_boosting_hex_assignment::Assignment::from(assignment) as i32
ProtoAssignment::from(assignment) as i32
}
}

impl From<ProtoAssignment> for Assignment {
fn from(value: ProtoAssignment) -> Self {
match value {
ProtoAssignment::A => Assignment::A,
ProtoAssignment::B => Assignment::B,
ProtoAssignment::C => Assignment::C,
}
}
}

Expand All @@ -40,59 +57,53 @@ impl fmt::Display for Assignment {
}
}

pub fn footfall_and_urbanization_multiplier(
footfall: Assignment,
urbanization: Assignment,
) -> Decimal {
use Assignment::*;
impl HexAssignments {
pub fn boosting_multiplier(&self) -> Decimal {
let HexAssignments {
footfall,
urbanized,
landtype,
} = self;

match (footfall, urbanization) {
(A, A) => dec!(1.0),
(A, B) => dec!(1.0),
(B, A) => dec!(0.75),
(B, B) => dec!(0.50),
(C, A) => dec!(0.40),
(C, B) => dec!(0.10),
(A, C) => dec!(0.00),
(B, C) => dec!(0.00),
(C, C) => dec!(0.00),
use Assignment::*;
match (footfall, landtype, urbanized) {
// yellow - POI ≥ 1 Urbanized
(A, A, A) => dec!(1.00),
(A, B, A) => dec!(1.00),
(A, C, A) => dec!(1.00),
// orange - POI ≥ 1 Not Urbanized
(A, A, B) => dec!(1.00),
(A, B, B) => dec!(1.00),
(A, C, B) => dec!(1.00),
// light green - Point of Interest Urbanized
(B, A, A) => dec!(0.70),
(B, B, A) => dec!(0.70),
(B, C, A) => dec!(0.70),
// dark green - Point of Interest Not Urbanized
(B, A, B) => dec!(0.50),
(B, B, B) => dec!(0.50),
(B, C, B) => dec!(0.50),
// light blue - No POI Urbanized
(C, A, A) => dec!(0.40),
(C, B, A) => dec!(0.30),
(C, C, A) => dec!(0.05),
// dark blue - No POI Not Urbanized
(C, A, B) => dec!(0.20),
(C, B, B) => dec!(0.15),
(C, C, B) => dec!(0.03),
// gray - Outside of USA
(_, _, C) => dec!(0.00),
}
}
}

#[allow(dead_code)]
pub fn boosting_oracles_multiplier(
footfall: Assignment,
landtype: Assignment,
urbanization: Assignment,
) -> Decimal {
use Assignment::*;

match (footfall, landtype, urbanization) {
// POI ≥ 1 Urbanized
(A, A, A) => dec!(1.00),
(A, B, A) => dec!(1.00),
(A, C, A) => dec!(1.00),
// POI ≥ 1 Not Urbanized
(A, A, B) => dec!(1.00),
(A, B, B) => dec!(1.00),
(A, C, B) => dec!(1.00),
// Point of Interest Urbanized
(B, A, A) => dec!(0.70),
(B, B, A) => dec!(0.70),
(B, C, A) => dec!(0.70),
// Point of Interest Not Urbanized
(B, A, B) => dec!(0.50),
(B, B, B) => dec!(0.50),
(B, C, B) => dec!(0.50),
// No POI Urbanized
(C, A, A) => dec!(0.40),
(C, B, A) => dec!(0.30),
(C, C, A) => dec!(0.05),
// No POI Not Urbanized
(C, A, B) => dec!(0.20),
(C, B, B) => dec!(0.15),
(C, C, B) => dec!(0.03),
// Outside of USA
(_, _, C) => dec!(0.00),
#[cfg(test)]
impl HexAssignments {
pub fn test_best() -> Self {
Self {
footfall: Assignment::A,
urbanized: Assignment::A,
landtype: Assignment::A,
}
}
}
Loading

0 comments on commit f4a60da

Please sign in to comment.