Skip to main content

aj_models/
problems.rs

1//! Structs for problems
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6/// Problem's config
7#[derive(Deserialize, Serialize, Clone, Debug)]
8pub struct ProblemConfig {
9    /// Problem's owner's user id (optional)
10    pub owner_id: Option<i64>,
11    /// Problem's type
12    pub r#type: ProblemType,
13    /// Merge subgroups
14    pub merge_subgroups: bool,
15    /// Problems's contest id
16    pub contest_id: i64,
17    /// Problem's index in contest
18    pub problem_index: i64,
19    /// Problem's name (ru)
20    pub name_ru: String,
21    /// Problem's name (en)
22    pub name_en: String,
23    /// Testing time limit in milliseconds
24    pub time_limit_ms: i32,
25    /// Testing memory limit in megabytes
26    pub memory_limit_mb: i32,
27    /// Path to the checker relative to problem's path
28    pub checker_path: String,
29    /// Path to the directory, which contains directories with tests inputs and outputs, relative to problem's path
30    pub tests_path: String,
31    /// Testing subgroups
32    pub subgroups: Vec<Subgroup>,
33}
34
35/// Problem config visible for all users
36#[derive(Deserialize, Serialize, Clone, Debug)]
37#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
38pub struct PublicProblemConfig {
39    /// Problem's id
40    pub id: i64,
41    /// Problem's owner id (optional)
42    pub owner_id: Option<i64>,
43    /// Problem's type
44    pub r#type: ProblemType,
45    /// Merge subgroups
46    pub merge_subgroups: bool,
47    /// Problems's contest id
48    pub contest_id: i64,
49    /// Problem's index in contest
50    pub problem_index: i64,
51    /// Problem's name (ru)
52    pub name_ru: String,
53    /// Problem's name (en)
54    pub name_en: String,
55    /// Testing time limit in milliseconds
56    pub time_limit_ms: i32,
57    /// Testing memory limit in megabytes
58    pub memory_limit_mb: i32,
59    /// Problem's subgroups
60    pub subgroups: Vec<Subgroup>,
61}
62
63/// Problem's type
64#[derive(Deserialize, Serialize, Debug, Clone)]
65#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
66#[cfg_attr(
67    feature = "sqlx",
68    sqlx(type_name = "problem_type", rename_all = "snake_case")
69)]
70#[serde(rename_all = "snake_case")]
71pub enum ProblemType {
72    /// Default problem
73    Default,
74    /// Interactive problem
75    Interactive,
76    /// Run-twice problem
77    RunTwice,
78    /// Run-twice problem, where both runs are interactive
79    RunTwiceInteractive,
80    /// Run-twice problem, where the first run is interactive, and the second run is a default one
81    RunTwiceFirstInteractive,
82    /// Run-twice problem, where the first run is a default one, and the second run is interactive
83    RunTwiceSecondInteractive,
84}
85
86/// Testing subgroup
87#[derive(Deserialize, Serialize, Debug, Clone)]
88#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
89pub struct Subgroup {
90    /// Subgroup's type
91    pub r#type: SubgroupType,
92    /// Array of tests' indexes of the subgroup
93    pub tests: Vec<i32>,
94    /// Maximum score which can be obtained from the subgroup
95    pub score: Option<i32>,
96    /// Maximum score which can be obtained from the each of subgroup's tests
97    pub score_per_test: Option<i32>,
98    /// Indexes of the subgroups, all of them must have `Ok` verdict to test on this subgroup.
99    /// Also, they must be less than index of this subgroup
100    pub depends_on: Vec<usize>,
101}
102
103/// Subgroup's type
104#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
105#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
106#[cfg_attr(
107    feature = "sqlx",
108    sqlx(type_name = "subgroup_type", rename_all = "snake_case")
109)]
110#[serde(rename_all = "snake_case")]
111pub enum SubgroupType {
112    /// Don't count score for this subgroup
113    Sample,
114    /// Count score for this subgroup
115    Main,
116}
117
118/// Request for creating/updating a question for a problem
119#[derive(Clone, Debug, Serialize, Deserialize)]
120pub struct ProblemQuestionRequest {
121    /// Question's title
122    pub title: String,
123    /// Question's text
124    pub text: String,
125    /// Created at
126    pub created_at: DateTime<Utc>,
127}
128
129/// Request for creating a question for a problem
130#[derive(Deserialize, Serialize, Clone, Debug)]
131#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
132pub struct ProblemQuestion {
133    /// Post id
134    pub id: i64,
135    /// Owner's id
136    pub owner_id: i64,
137    /// Problem's id
138    pub problem_id: i64,
139    /// Question's title
140    pub title: String,
141    /// Question's text
142    pub text: String,
143    /// Answer for a question
144    pub answer: String,
145    /// Created at
146    pub created_at: DateTime<Utc>,
147}