pub fn select_all_workers_state(conn: &PgConnection) -> Result<Vec<NodeState>, MeshSimError> {
    use schema::workers;
    use schema::worker_positions;
    use schema::worker_velocities;
    use schema::worker_destinations;

    let source: Vec<(i32, String, f64, f64, f64, f64, Option<f64>, Option<f64>)> = workers::table
        .inner_join(worker_positions::table)
        .inner_join(worker_velocities::table)
        .inner_join(worker_destinations::table)
        .select((
            workers::id,
            workers::worker_name,
            worker_positions::x,
            worker_positions::y,
            worker_velocities::x,
            worker_velocities::y,
            worker_destinations::x.nullable(),
            worker_destinations::y.nullable(),
        ))
        .get_results(conn)
        .map_err(|e| {
            let error_msg =
                String::from("Failed to read worker positions, destinations and velocities");
            MeshSimError {
                kind: MeshSimErrorKind::SQLExecutionFailure(error_msg),
                cause: Some(Box::new(e)),
            }
        })?;

    let result = source
        .into_iter()
        .map(|(id, name, p_x, p_y, v_x, v_y, d_x, d_y)| {
            let dest = if d_x.is_some() && d_y.is_some() {
                let d = Position {
                    x: d_x.unwrap(),
                    y: d_y.unwrap(),
                };
                Some(d)
            } else {
                None
            };

            NodeState {
                id,
                name,
                pos: Position{x: p_x, y: p_y},
                vel: Velocity{x: v_x, y: v_y},
                dest,
            }
        })
        .collect();

    Ok(result)
}
/// Get the positions of all workers
Get the positions of all workers
Get the positions of all workers
pub fn select_all_workers_state(conn: &PgConnection) -> Result<Vec<NodeState>, MeshSimError> {
    use schema::workers;
    use schema::worker_positions;
    use schema::worker_velocities;
    use schema::worker_destinations;
    let source: Vec<(i32, String, f64, f64, f64, f64, Option<f64>, Option<f64>)> = workers::table
        .inner_join(worker_positions::table)
        .inner_join(worker_velocities::table)
        .inner_join(worker_destinations::table)
        .select((
            workers::id,
            workers::worker_name,
            worker_positions::x,
            worker_positions::y,
            worker_velocities::x,
            worker_velocities::y,
            worker_destinations::x.nullable(),
            worker_destinations::y.nullable(),
        ))
        .get_results(conn)
        .map_err(|e| {
            let error_msg =
                String::from("Failed to read worker positions, destinations and velocities");
            MeshSimError {
                kind: MeshSimErrorKind::SQLExecutionFailure(error_msg),
                cause: Some(Box::new(e)),
            }
        })?;
    let result = source
        .into_iter()
        .map(|(id, name, p_x, p_y, v_x, v_y, d_x, d_y)| {
            let dest = if d_x.is_some() && d_y.is_some() {
                let d = Position {
                    x: d_x.unwrap(),
                    y: d_y.unwrap(),
                };
                Some(d)
            } else {
                None
            };
            NodeState {
                id,
                name,
                pos: Position{x: p_x, y: p_y},
                vel: Velocity{x: v_x, y: v_y},
                dest,
            }
        })
        .collect();
    Ok(result)
}
pub fn select_all_workers_state ( conn : & PgConnection ) -> Result < Vec < NodeState > , MeshSimError > { use schema :: workers ; use schema :: worker_positions ; use schema :: worker_velocities ; use schema :: worker_destinations ; let source : Vec < ( i32 , String , f64 , f64 , f64 , f64 , Option < f64 > , Option < f64 > ) > = workers :: table . inner_join ( worker_positions :: table ) . inner_join ( worker_velocities :: table ) . inner_join ( worker_destinations :: table ) . select ( ( workers :: id , workers :: worker_name , worker_positions :: x , worker_positions :: y , worker_velocities :: x , worker_velocities :: y , worker_destinations :: x . nullable ( ) , worker_destinations :: y . nullable ( ) , ) ) . get_results ( conn ) . map_err ( | e | { let error_msg = String :: from ( " " ) ; MeshSimError { kind : MeshSimErrorKind :: SQLExecutionFailure ( error_msg ) , cause : Some ( Box :: new ( e ) ) , } } ) ? ; let result = source . into_iter ( ) . map ( | ( id , name , p_x , p_y , v_x , v_y , d_x , d_y ) | { let dest = if d_x . is_some ( ) && d_y . is_some ( ) { let d = Position { x : d_x . unwrap ( ) , y : d_y . unwrap ( ) , } ; Some ( d ) } else { None } ; NodeState { id , name , pos : Position { x : p_x , y : p_y } , vel : Velocity { x : v_x , y : v_y } , dest , } } ) . collect ( ) ; Ok ( result ) }
Get the positions of all workers
Get the positions of all workers
conn
&PgConnection