Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create hex_assignments crate #817

Merged
merged 6 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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