-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from vklachkov/occupancy
Конструкторские бюро и ко
- Loading branch information
Showing
28 changed files
with
381 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::{ | ||
api::{error::Result, BackendState}, | ||
domain::*, | ||
}; | ||
use axum::{extract::State, Json}; | ||
use std::{collections::HashMap, sync::Arc}; | ||
|
||
pub async fn juries() -> Json<HashMap<&'static str, Bureau>> { | ||
Json(Bureau::all().into_iter().map(|b| (b.jury(), b)).collect()) | ||
} | ||
|
||
pub async fn stats( | ||
State(state): State<Arc<BackendState>>, | ||
) -> Result<Json<HashMap<Bureau, BureauStats>>> { | ||
let participants = state | ||
.datasource | ||
.participants | ||
.get_all(None, Sort::Id, Order::Asc, false) | ||
.await?; | ||
|
||
let mut bureaus = Bureau::all() | ||
.into_iter() | ||
.map(|b| (b, BureauStats::default())) | ||
.collect::<HashMap<_, _>>(); | ||
|
||
for p in participants { | ||
if let Some(bureau) = p.jury.as_ref().and_then(|j| Bureau::from_jury(&j.name)) { | ||
bureaus.get_mut(&bureau).unwrap().participants += 1; | ||
} | ||
} | ||
|
||
Ok(Json(bureaus)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use serde::Serialize; | ||
|
||
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize)] | ||
#[rustfmt::skip] | ||
pub enum Bureau { | ||
#[serde(rename = "1D")] OneD, | ||
#[serde(rename = "Салют")] Salut, | ||
#[serde(rename = "Звёздное")] Zvezdnoe, | ||
#[serde(rename = "Родное")] Rodnoe, | ||
#[serde(rename = "Око")] Oko, | ||
} | ||
|
||
impl Bureau { | ||
pub fn all() -> [Bureau; 5] { | ||
use Bureau::*; | ||
[OneD, Salut, Zvezdnoe, Rodnoe, Oko] | ||
} | ||
|
||
pub fn from_jury(name: &str) -> Option<Self> { | ||
match name { | ||
"Матюхин Андрей" => Some(Self::OneD), | ||
"Кириевский Дмитрий" => Some(Self::Salut), | ||
"Каменева Вероника" => Some(Self::Zvezdnoe), | ||
"Овчинников Илья" => Some(Self::Rodnoe), | ||
"Калинкин Александр" => Some(Self::Oko), | ||
_ => None, | ||
} | ||
} | ||
|
||
pub fn jury(self) -> &'static str { | ||
match self { | ||
Self::OneD => "Матюхин Андрей", | ||
Self::Salut => "Кириевский Дмитрий", | ||
Self::Zvezdnoe => "Каменева Вероника", | ||
Self::Rodnoe => "Овчинников Илья", | ||
Self::Oko => "Калинкин Александр", | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, Serialize)] | ||
pub struct BureauStats { | ||
pub participants: usize, | ||
pub max_participants: usize, | ||
} | ||
|
||
impl Default for BureauStats { | ||
fn default() -> Self { | ||
Self { | ||
participants: 0, | ||
max_participants: super::MAX_PARTICIPANTS_PER_BUREAU, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
mod adult; | ||
mod bureau; | ||
mod operations; | ||
mod participant; | ||
|
||
pub use adult::{Adult, AdultId, AdultRole}; | ||
pub use bureau::{Bureau, BureauStats}; | ||
pub use operations::{Order, Sort}; | ||
pub use participant::{ | ||
JuryParticipant, Participant, ParticipantAnswers, ParticipantCode, ParticipantId, | ||
ParticipantInfo, ParticipantRate, | ||
}; | ||
|
||
pub const MAX_PARTICIPANTS_PER_BUREAU: usize = 24; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,6 @@ | |
} | ||
|
||
&__select { | ||
min-width: 14em; | ||
min-width: 20em; | ||
} | ||
} |
Oops, something went wrong.