Skip to content

Commit

Permalink
Create hex_assignments crate (#817)
Browse files Browse the repository at this point in the history
* Create hex_assignments

* Fix fmt

* Add HexBoostDataAssignments trait

* Remove HexAssignments::test_best

* Remove new_mock use optional parameter in new

* Format Cargo.toml
  • Loading branch information
kurotych authored May 30, 2024
1 parent 6f56703 commit b3585cd
Show file tree
Hide file tree
Showing 17 changed files with 480 additions and 461 deletions.
16 changes: 16 additions & 0 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ members = [
"reward_scheduler",
"solana",
"task_manager",
"hex_assignments"
]
resolver = "2"

Expand Down
18 changes: 18 additions & 0 deletions hex_assignments/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "hex-assignments"
version = "0.1.0"
description = "Hex Assignments"
edition.workspace = true
authors.workspace = true
license.workspace = true

[dependencies]
anyhow = { workspace = true }
hextree = { workspace = true }
sqlx = { version = "*", features = ["runtime-tokio-rustls"] }
rust_decimal = { workspace = true }
rust_decimal_macros = { workspace = true }
helium-proto = { workspace = true }
async-trait = { workspace = true }
chrono = { workspace = true }
derive_builder = { workspace = true }
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,3 @@ impl HexAssignmentsBuilder {
})
}
}

#[cfg(test)]
impl HexAssignments {
pub fn test_best() -> Self {
Self {
footfall: Assignment::A,
urbanized: Assignment::A,
landtype: Assignment::A,
}
}
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,25 @@
use std::path::Path;

use chrono::{DateTime, Utc};
use hextree::disktree::DiskTreeMap;

use super::{Assignment, DataSet, DataSetType, HexAssignment};
use super::{Assignment, HexAssignment};

pub struct Footfall {
footfall: Option<DiskTreeMap>,
timestamp: Option<DateTime<Utc>>,
pub footfall: Option<DiskTreeMap>,
pub timestamp: Option<DateTime<Utc>>,
}

impl Footfall {
pub fn new() -> Self {
pub fn new(footfall: Option<DiskTreeMap>) -> Self {
Self {
footfall: None,
timestamp: None,
}
}

pub fn new_mock(footfall: DiskTreeMap) -> Self {
Self {
footfall: Some(footfall),
footfall,
timestamp: None,
}
}
}

impl Default for Footfall {
fn default() -> Self {
Self::new()
}
}

#[async_trait::async_trait]
impl DataSet for Footfall {
const TYPE: DataSetType = DataSetType::Footfall;

fn timestamp(&self) -> Option<DateTime<Utc>> {
self.timestamp
}

fn update(&mut self, path: &Path, time_to_use: DateTime<Utc>) -> anyhow::Result<()> {
self.footfall = Some(DiskTreeMap::open(path)?);
self.timestamp = Some(time_to_use);
Ok(())
}

fn is_ready(&self) -> bool {
self.footfall.is_some()
Self::new(None)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,25 @@
use std::path::Path;

use chrono::{DateTime, Utc};
use hextree::disktree::DiskTreeMap;

use super::{Assignment, DataSet, DataSetType, HexAssignment};
use super::{Assignment, HexAssignment};

pub struct Landtype {
landtype: Option<DiskTreeMap>,
timestamp: Option<DateTime<Utc>>,
pub landtype: Option<DiskTreeMap>,
pub timestamp: Option<DateTime<Utc>>,
}

impl Landtype {
pub fn new() -> Self {
pub fn new(landtype: Option<DiskTreeMap>) -> Self {
Self {
landtype: None,
timestamp: None,
}
}

pub fn new_mock(landtype: DiskTreeMap) -> Self {
Self {
landtype: Some(landtype),
landtype,
timestamp: None,
}
}
}

impl Default for Landtype {
fn default() -> Self {
Self::new()
}
}

#[async_trait::async_trait]
impl DataSet for Landtype {
const TYPE: DataSetType = DataSetType::Landtype;

fn timestamp(&self) -> Option<DateTime<Utc>> {
self.timestamp
}

fn update(&mut self, path: &Path, time_to_use: DateTime<Utc>) -> anyhow::Result<()> {
self.landtype = Some(DiskTreeMap::open(path)?);
self.timestamp = Some(time_to_use);
Ok(())
}

fn is_ready(&self) -> bool {
self.landtype.is_some()
Self::new(None)
}
}

Expand Down
Loading

0 comments on commit b3585cd

Please sign in to comment.