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

Fix BNAPost wrapper #97

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion entity/src/entities/brokenspoke_pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14

use super::sea_orm_active_enums::BrokenspokeState;
use sea_orm::entity::prelude::*;
Expand All @@ -19,6 +19,7 @@ pub struct Model {
pub start_time: TimeDateTimeWithTimeZone,
pub end_time: Option<TimeDateTimeWithTimeZone>,
pub torn_down: Option<bool>,
pub results_posted: Option<bool>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/census.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/city.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/core_services.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/features.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/infrastructure.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14

pub mod prelude;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/opportunity.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14

pub use super::brokenspoke_pipeline::Entity as BrokenspokePipeline;
pub use super::census::Entity as Census;
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/recreation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/sea_orm_active_enums.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/speed_limit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/state_speed_limit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/submission.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14

use super::sea_orm_active_enums::ApprovalStatus;
use sea_orm::entity::prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion entity/src/entities/summary.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14

use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
45 changes: 45 additions & 0 deletions entity/src/wrappers/bna.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ pub struct BNARecreation {
pub score: Option<f64>,
}

impl BNARecreation {
pub fn refresh_score(&mut self) {
let score = (self.community_centers.unwrap_or_default()
+ self.parks.unwrap_or_default()
+ self.recreation_trails.unwrap_or_default())
/ 3.0;
self.score = Some(score);
}
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct BNAOpportunity {
pub employment: Option<f64>,
Expand All @@ -32,6 +42,17 @@ pub struct BNAOpportunity {
pub technical_vocational_college: Option<f64>,
}

impl BNAOpportunity {
pub fn refresh_score(&mut self) {
let score = (self.employment.unwrap_or_default()
+ self.higher_education.unwrap_or_default()
+ self.k12_education.unwrap_or_default()
+ self.technical_vocational_college.unwrap_or_default())
/ 4.0;
self.score = Some(score);
}
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct BNACoreServices {
pub dentists: Option<f64>,
Expand All @@ -43,6 +64,19 @@ pub struct BNACoreServices {
pub social_services: Option<f64>,
}

impl BNACoreServices {
pub fn refresh_score(&mut self) {
let score = (self.dentists.unwrap_or_default()
+ self.doctors.unwrap_or_default()
+ self.grocery.unwrap_or_default()
+ self.hospitals.unwrap_or_default()
+ self.pharmacies.unwrap_or_default()
+ self.social_services.unwrap_or_default())
/ 6.0;
self.score = Some(score);
}
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct BNAFeatures {
pub people: Option<f64>,
Expand All @@ -60,6 +94,17 @@ pub struct BNAPost {
pub summary: BNASummary,
}

impl BNAPost {
pub fn refresh_score(&mut self) {
let score = (self.core_services.score.unwrap_or_default()
// + self.features.score.unwrap_or_default()
+ self.opportunity.score.unwrap_or_default()
+ self.recreation.score.unwrap_or_default())
/ 4.0;
self.summary.score = score;
}
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct BNAPatch {
pub core_services: BNACoreServices,
Expand Down
6 changes: 6 additions & 0 deletions entity/src/wrappers/brokenspoke_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct BrokenspokePipelinePost {
pub start_time: TimeDateTimeWithTimeZone,
pub end_time: Option<TimeDateTimeWithTimeZone>,
pub torn_down: Option<bool>,
pub result_posted: Option<bool>,
}

impl IntoActiveModel<brokenspoke_pipeline::ActiveModel> for BrokenspokePipelinePost {
Expand All @@ -32,6 +33,7 @@ impl IntoActiveModel<brokenspoke_pipeline::ActiveModel> for BrokenspokePipelineP
start_time: ActiveValue::Set(self.start_time),
end_time: ActiveValue::Set(self.end_time),
torn_down: ActiveValue::Set(self.torn_down),
results_posted: ActiveValue::Set(self.result_posted),
}
}
}
Expand All @@ -47,6 +49,7 @@ pub struct BrokenspokePipelinePatch {
pub start_time: Option<Option<TimeDateTimeWithTimeZone>>,
pub end_time: Option<Option<TimeDateTimeWithTimeZone>>,
pub torn_down: Option<Option<bool>>,
pub result_posted: Option<Option<bool>>,
}

impl IntoActiveModel<brokenspoke_pipeline::ActiveModel> for BrokenspokePipelinePatch {
Expand All @@ -70,6 +73,9 @@ impl IntoActiveModel<brokenspoke_pipeline::ActiveModel> for BrokenspokePipelineP
start_time: ActiveValue::NotSet,
end_time: self.end_time.map_or(ActiveValue::NotSet, ActiveValue::Set),
torn_down: self.torn_down.map_or(ActiveValue::NotSet, ActiveValue::Set),
results_posted: self
.result_posted
.map_or(ActiveValue::NotSet, ActiveValue::Set),
}
}
}
8 changes: 7 additions & 1 deletion lambdas/src/bnas/post-bnas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ async fn function_handler(event: Request) -> Result<Response<Body>, Error> {
dotenv().ok();

// Extract and serialize the data.
let wrapper = match parse_request_body::<BNAPost>(&event) {
let mut wrapper = match parse_request_body::<BNAPost>(&event) {
Ok(value) => value,
Err(e) => return Ok(e.into()),
};

// Refresh the scores.
wrapper.core_services.refresh_score();
wrapper.opportunity.refresh_score();
wrapper.recreation.refresh_score();
wrapper.refresh_score();

// Turn the model wrapper into active models.
let summary = summary::ActiveModel {
bna_uuid: ActiveValue::Set(wrapper.summary.bna_uuid),
Expand Down
14 changes: 8 additions & 6 deletions migration/src/m20240202_004130_brokenspoke_analyzer_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl MigrationTrait for Migration {
)
.col(ColumnDef::new(BrokenspokePipeline::EndTime).timestamp_with_time_zone())
.col(ColumnDef::new(BrokenspokePipeline::TornDown).boolean())
.col(ColumnDef::new(BrokenspokePipeline::ResultsPosted).boolean())
.to_owned(),
)
.await
Expand All @@ -73,15 +74,16 @@ impl MigrationTrait for Migration {
#[derive(DeriveIden)]
enum BrokenspokePipeline {
Table,
StateMachineId,
ScheduledTriggerId,
State,
SqsMessage,
NeonBranchId,
EndTime,
FargateTaskARN,
NeonBranchId,
ResultsPosted,
S3Bucket,
ScheduledTriggerId,
SqsMessage,
StartTime,
EndTime,
State,
StateMachineId,
TornDown,
}

Expand Down