|
1 |
| -use std::fmt; |
2 |
| - |
3 |
| -use diesel::sql_types::{Array, Integer, Json, Text}; |
4 |
| -use diesel::{sql_query, PgConnection, RunQueryDsl}; |
5 |
| -use serde::{Deserialize, Serialize}; |
6 |
| -use strum::IntoEnumIterator; |
7 |
| -use strum_macros::EnumIter; |
8 |
| - |
9 | 1 | use super::graph::Graph;
|
10 |
| -use super::InfraError; |
11 |
| -use crate::objects::{Direction, DirectionalTrackRange, ObjectType, Route}; |
12 |
| -use crate::{infra_cache::InfraCache, objects::ObjectRef}; |
| 2 | +use crate::infra_cache::InfraCache; |
| 3 | +use crate::schema::{ |
| 4 | + Direction, DirectionalTrackRange, InfraError, ObjectRef, ObjectType, PathEndpointField, |
| 5 | +}; |
13 | 6 | use diesel::result::Error as DieselError;
|
| 7 | +use diesel::sql_types::{Array, Integer, Json, Text}; |
| 8 | +use diesel::{sql_query, PgConnection, RunQueryDsl}; |
14 | 9 | use serde_json::to_value;
|
15 |
| - |
16 |
| -/// Represent the entry or exit point of a path |
17 |
| -#[derive(Serialize, Deserialize, Debug, Clone, Copy, EnumIter, PartialEq, Eq)] |
18 |
| -#[serde(deny_unknown_fields)] |
19 |
| -pub enum PathEndpointField { |
20 |
| - #[serde(rename = "entry_point")] |
21 |
| - EntryPoint, |
22 |
| - #[serde(rename = "exit_point")] |
23 |
| - ExitPoint, |
24 |
| -} |
25 |
| - |
26 |
| -impl PathEndpointField { |
27 |
| - /// Given a path, retrieve track id and position offset of the path endpoint location |
28 |
| - pub fn get_path_location(&self, path: &[DirectionalTrackRange]) -> (String, f64) { |
29 |
| - let track_range = match self { |
30 |
| - PathEndpointField::EntryPoint => path.first().unwrap(), |
31 |
| - PathEndpointField::ExitPoint => path.last().unwrap(), |
32 |
| - }; |
33 |
| - |
34 |
| - let pos = match (self, &track_range.direction) { |
35 |
| - (PathEndpointField::EntryPoint, Direction::StartToStop) => track_range.begin, |
36 |
| - (PathEndpointField::EntryPoint, Direction::StopToStart) => track_range.end, |
37 |
| - (PathEndpointField::ExitPoint, Direction::StartToStop) => track_range.end, |
38 |
| - (PathEndpointField::ExitPoint, Direction::StopToStart) => track_range.begin, |
39 |
| - }; |
40 |
| - |
41 |
| - (track_range.track.obj_id.clone(), pos) |
42 |
| - } |
43 |
| - |
44 |
| - pub fn get_route_endpoint<'a>(&self, route: &'a Route) -> &'a ObjectRef { |
45 |
| - match self { |
46 |
| - PathEndpointField::EntryPoint => &route.entry_point, |
47 |
| - PathEndpointField::ExitPoint => &route.exit_point, |
48 |
| - } |
49 |
| - } |
50 |
| -} |
51 |
| - |
52 |
| -impl fmt::Display for PathEndpointField { |
53 |
| - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
54 |
| - write!(f, "{}", serde_json::to_string(self).unwrap()) |
55 |
| - } |
56 |
| -} |
| 10 | +use strum::IntoEnumIterator; |
57 | 11 |
|
58 | 12 | /// Given an ObjectRef, retrieve the id and position of its track section
|
59 | 13 | /// If the object type is not a detector or a buffer stop, return `None`
|
@@ -111,7 +65,7 @@ pub fn insert_errors(
|
111 | 65 | let mut errors = vec![];
|
112 | 66 |
|
113 | 67 | for error in infra_errors {
|
114 |
| - route_ids.push(error.obj_id.clone()); |
| 68 | + route_ids.push(error.get_id().clone()); |
115 | 69 | errors.push(to_value(error).unwrap());
|
116 | 70 | }
|
117 | 71 |
|
@@ -302,11 +256,11 @@ pub fn generate_errors(infra_cache: &InfraCache, graph: &Graph) -> Vec<InfraErro
|
302 | 256 |
|
303 | 257 | #[cfg(test)]
|
304 | 258 | mod tests {
|
305 |
| - use crate::{ |
306 |
| - infra_cache::tests::{create_detector_cache, create_route_cache, create_small_infra_cache}, |
307 |
| - models::errors::{graph::Graph, routes::PathEndpointField}, |
308 |
| - objects::{Direction, ObjectRef, ObjectType}, |
| 259 | + use crate::errors::graph::Graph; |
| 260 | + use crate::infra_cache::tests::{ |
| 261 | + create_detector_cache, create_route_cache, create_small_infra_cache, |
309 | 262 | };
|
| 263 | + use crate::schema::{Direction, ObjectRef, ObjectType, PathEndpointField}; |
310 | 264 |
|
311 | 265 | use super::generate_errors;
|
312 | 266 | use super::InfraError;
|
|
0 commit comments