@@ -77,6 +77,7 @@ use crate::client::get_app_version;
77
77
use crate :: core:: mq_client;
78
78
use crate :: core:: pathfinding:: PathfindingInputError ;
79
79
use crate :: core:: pathfinding:: PathfindingNotFound ;
80
+ use crate :: core:: simulation:: SimulationResponse ;
80
81
use crate :: core:: version:: CoreVersionRequest ;
81
82
use crate :: core:: AsCoreRequest ;
82
83
use crate :: core:: CoreClient ;
@@ -93,6 +94,7 @@ use crate::map::MapLayers;
93
94
use crate :: models;
94
95
use crate :: models:: auth:: PgAuthDriver ;
95
96
use crate :: valkey_utils:: ValkeyConfig ;
97
+ use crate :: views:: path:: pathfinding:: PathfindingFailure ;
96
98
use crate :: ValkeyClient ;
97
99
98
100
crate :: routes! {
@@ -172,7 +174,7 @@ pub struct InfraIdQueryParam {
172
174
173
175
#[ derive( Debug , PartialEq , Serialize , Deserialize , ToSchema ) ]
174
176
#[ serde( tag = "status" , rename_all = "snake_case" ) ]
175
- pub enum SimulationSummaryResult {
177
+ enum SimulationSummaryResult {
176
178
/// Minimal information on a simulation's result
177
179
Success {
178
180
/// Length of a path in mm
@@ -201,6 +203,45 @@ pub enum SimulationSummaryResult {
201
203
PathfindingInputError ( PathfindingInputError ) ,
202
204
}
203
205
206
+ fn simulation_response ( sim : SimulationResponse ) -> SimulationSummaryResult {
207
+ match sim {
208
+ SimulationResponse :: Success {
209
+ final_output,
210
+ provisional,
211
+ base,
212
+ ..
213
+ } => {
214
+ let report = final_output. report_train ;
215
+ SimulationSummaryResult :: Success {
216
+ length : * report. positions . last ( ) . unwrap ( ) ,
217
+ time : * report. times . last ( ) . unwrap ( ) ,
218
+ energy_consumption : report. energy_consumption ,
219
+ path_item_times_final : report. path_item_times . clone ( ) ,
220
+ path_item_times_provisional : provisional. path_item_times . clone ( ) ,
221
+ path_item_times_base : base. path_item_times . clone ( ) ,
222
+ }
223
+ }
224
+ SimulationResponse :: PathfindingFailed { pathfinding_failed } => match pathfinding_failed {
225
+ PathfindingFailure :: InternalError { core_error } => {
226
+ SimulationSummaryResult :: PathfindingFailure { core_error }
227
+ }
228
+
229
+ PathfindingFailure :: PathfindingInputError ( input_error) => {
230
+ SimulationSummaryResult :: PathfindingInputError ( input_error)
231
+ }
232
+
233
+ PathfindingFailure :: PathfindingNotFound ( not_found) => {
234
+ SimulationSummaryResult :: PathfindingNotFound ( not_found)
235
+ }
236
+ } ,
237
+ SimulationResponse :: SimulationFailed { core_error } => {
238
+ SimulationSummaryResult :: SimulationFailed {
239
+ error_type : core_error. get_type ( ) . into ( ) ,
240
+ }
241
+ }
242
+ }
243
+ }
244
+
204
245
/// Represents the bundle of information about the issuer of a request
205
246
/// that can be extracted form recognized headers.
206
247
#[ derive( Debug , Clone ) ]
0 commit comments