Skip to main content

aj_models/
problems.rs

1use crate::{
2    testing::{Language, SubgroupResult},
3    verdicts::Verdict,
4};
5use chrono::{DateTime, Utc};
6use serde::{Deserialize, Serialize};
7
8#[derive(Deserialize, Serialize, Clone, Debug)]
9pub struct ProblemConfig {
10    pub owner_id: Option<i64>,
11    pub name_ru: String,
12    pub name_en: String,
13    pub r#type: ProblemType,
14    pub testing_type: ProblemTestingType,
15    pub contest_id: i64,
16    pub index: i64,
17    pub time_limit_ms: i32,
18    pub memory_limit_mb: i32,
19    pub checker_path: String,
20    pub checker_lang: Language,
21    pub tests_path: String,
22    pub subgroups: Vec<Subgroup>,
23}
24
25#[derive(Deserialize, Serialize, Clone, Debug)]
26#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
27pub struct PublicProblemConfig {
28    pub id: i64,
29    pub owner_id: Option<i64>,
30    pub owner_login: Option<String>,
31    pub name_ru: String,
32    pub name_en: String,
33    pub r#type: ProblemType,
34    pub testing_type: ProblemTestingType,
35    pub contest_id: i64,
36    pub index: i64,
37    pub time_limit_ms: i32,
38    pub memory_limit_mb: i32,
39    pub subgroups: Vec<Subgroup>,
40    pub created_at: DateTime<Utc>,
41}
42
43#[derive(Deserialize, Serialize, Debug, Clone)]
44#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
45#[cfg_attr(
46    feature = "sqlx",
47    sqlx(type_name = "problem_type", rename_all = "snake_case")
48)]
49#[serde(rename_all = "snake_case")]
50pub enum ProblemType {
51    Default,
52    Interactive,
53    RunTwice,
54    InteractiveRunTwice,
55    RunTwiceFirstInteractive,
56    RunTwiceSecondInteractive,
57}
58
59#[derive(Deserialize, Serialize, Debug, Clone)]
60#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
61#[cfg_attr(
62    feature = "sqlx",
63    sqlx(type_name = "problem_testing_type", rename_all = "snake_case")
64)]
65#[serde(rename_all = "snake_case")]
66pub enum ProblemTestingType {
67    Ioi,
68    IoiMergeSubgroups,
69}
70
71#[derive(Deserialize, Serialize, Debug, Clone)]
72#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
73pub struct Subgroup {
74    pub r#type: SubgroupType,
75    pub tests: Vec<i32>,
76    pub score: Option<f64>,
77    pub score_per_test: Option<f64>,
78    pub depends_on: Vec<usize>,
79}
80
81impl Subgroup {
82    #[must_use]
83    pub fn should_skip(&self, subgroups_results: &[SubgroupResult]) -> bool {
84        self.depends_on
85            .iter()
86            .all(|i| subgroups_results[*i].verdict == Verdict::Ok)
87    }
88}
89
90#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
91#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
92#[cfg_attr(
93    feature = "sqlx",
94    sqlx(type_name = "subgroup_type", rename_all = "snake_case")
95)]
96#[serde(rename_all = "snake_case")]
97pub enum SubgroupType {
98    Sample,
99    Main,
100}
101
102#[derive(Clone, Debug, Serialize, Deserialize)]
103pub struct ProblemQuestionRequest {
104    pub title: String,
105    pub text: String,
106}
107
108#[derive(Deserialize, Serialize, Clone, Debug)]
109#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
110pub struct ProblemQuestion {
111    pub id: i64,
112    pub owner_id: i64,
113    pub owner_login: String,
114    pub problem_id: i64,
115    pub title: String,
116    pub text: String,
117    pub answer: String,
118    pub created_at: DateTime<Utc>,
119}