-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathconflict_detection.rs
81 lines (70 loc) · 2.28 KB
/
conflict_detection.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use chrono::DateTime;
use chrono::Utc;
use serde::Deserialize;
use serde::Serialize;
use std::collections::HashMap;
use utoipa::ToSchema;
use crate::core::{AsCoreRequest, Json};
use super::simulation::RoutingRequirement;
use super::simulation::SpacingRequirement;
editoast_common::schemas! {
ConflictDetectionResponse,
Conflict,
ConflictRequirement,
}
#[derive(Debug, Serialize)]
pub struct ConflictDetectionRequest {
/// List of requirements for each train
pub trains_requirements: HashMap<i64, TrainRequirements>,
pub infra_id: i64,
}
#[derive(Debug, Serialize)]
pub struct TrainRequirements {
pub start_time: DateTime<Utc>,
pub spacing_requirements: Vec<SpacingRequirement>,
pub routing_requirements: Vec<RoutingRequirement>,
}
#[derive(Debug, Deserialize, ToSchema)]
pub struct ConflictDetectionResponse {
/// List of conflicts detected
#[schema(inline)]
pub conflicts: Vec<Conflict>,
}
#[derive(Debug, Clone, Deserialize, Serialize, ToSchema)]
pub struct Conflict {
/// List of train ids involved in the conflict
pub train_ids: Vec<i64>,
/// Datetime of the start of the conflict
pub start_time: DateTime<Utc>,
/// Datetime of the end of the conflict
pub end_time: DateTime<Utc>,
/// Type of the conflict
#[schema(inline)]
pub conflict_type: ConflictType,
/// List of requirements causing the conflict
pub requirements: Vec<ConflictRequirement>,
}
/// Unmet requirement causing a conflict.
///
/// The start and end time describe the conflicting time span (not the full
/// requirement's time span).
#[derive(Debug, Clone, Deserialize, Serialize, ToSchema)]
pub struct ConflictRequirement {
pub zone: String,
pub start_time: DateTime<Utc>,
pub end_time: DateTime<Utc>,
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
pub enum ConflictType {
/// Conflict caused by two trains being too close to each other
Spacing,
/// Conflict caused by two trains requiring incompatible routes at the same time
Routing,
}
impl AsCoreRequest<Json<ConflictDetectionResponse>> for ConflictDetectionRequest {
const METHOD: reqwest::Method = reqwest::Method::POST;
const URL_PATH: &'static str = "/v2/conflict_detection";
fn infra_id(&self) -> Option<i64> {
Some(self.infra_id)
}
}