From eb497462681e861bfbc6471e20f156c9a3bcb1be Mon Sep 17 00:00:00 2001 From: lukasadrion Date: Tue, 20 Jan 2026 16:13:41 +0100 Subject: [PATCH] :adhesive_bandage: fix small issues in main --- src/app.Rmd | 5 +++++ src/main.Rmd | 28 +++++++++++++++------------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/app.Rmd b/src/app.Rmd index ac3400d..1c365bd 100644 --- a/src/app.Rmd +++ b/src/app.Rmd @@ -1,3 +1,8 @@ +```{r backend, child="./main.Rmd"} + source("./main.Rmd") + exists("getRouteSummary") +``` + # Web Interface ```{r shiny} # Flight Trajectory Analysis - Shiny GUI Application diff --git a/src/main.Rmd b/src/main.Rmd index 8b6c86d..d872021 100644 --- a/src/main.Rmd +++ b/src/main.Rmd @@ -104,7 +104,7 @@ getTrajFromRoute <- function(route_df){ xCol = "x", yCol = "y", timeCol = "time" ) } -getRouteSummary<-function(route_df){ +getRouteSummary<-function(route_df, icao){ meters <- getRouteDistance(route_df) x_meters <- meters$x y_meters <- meters$y @@ -128,6 +128,7 @@ getRouteSummary<-function(route_df){ straightness <- TrajStraightness(trj) # 5. Mean travel velocity (meters/second) + mean_velocity <- path_length / duration # 6. Fractal dimension (using divider method) # Note: requires sufficient points for accurate estimation @@ -144,17 +145,17 @@ getRouteSummary<-function(route_df){ }) return(data.frame( - icao24 = icao24, - diffusion_distance_m = diffusion_distance, # meters - path_length_m = path_length, # meters + icao24 = icao, + diffusion_distance_km = diffusion_distance / 1000, # meters to kilometers + path_length_km = path_length / 1000, # meters to kilometers straightness = straightness, - duration_s = duration, # seconds + duration_mins = duration / 60, # seconds to minutes mean_velocity_kmh = mean_velocity * 3.6, fractal_dimension = fractal_dim )) } -print(getRouteSummary(route_df)) +print(getRouteSummary(route_df, icao)) trj <- getTrajFromRoute(route_df) plot(trj, main = paste("Trajectory of", icao)) @@ -165,14 +166,16 @@ plot(trj, main = paste("Trajectory of", icao)) # Statistical Analysis of Multiple Trajectories ```{r multi-trajectory-analysis} # Function to calculate trajectory characteristics for a single flight -calculate_trajectory_params <- function(icao24, departure_time, creds) { +calculate_trajectory_params <- function(icao, departure_time, creds) { tryCatch({ - route_df <- getAircraftTrack(icao24,departure_time, creds) + route_df <- getAircraftTrack(icao, departure_time, creds) - if (is.null(route_df) ||nrow(route_df) < 3) return(NULL) + if (is.null(route_df) || nrow(route_df) < 3) return(NULL) # Fractal dimension fractal <- tryCatch({ + trj <- getTrajFromRoute(route_df) + path_length <- TrajLength(trj) min_step <- path_length / 100 max_step <- path_length / 2 if (min_step > 0 && max_step > min_step) { @@ -183,10 +186,10 @@ calculate_trajectory_params <- function(icao24, departure_time, creds) { } }, error = function(e) NA) - return(getRouteSummary(route_df)) + return(getRouteSummary(route_df, icao)) }, error = function(e) { - message("Error processing ", icao24, ": ", e$message) + message("Error processing ", icao, ": ", e$message) return(NULL) }) } @@ -233,7 +236,7 @@ if (length(all_trajectories) > 0) { if (exists("trajectory_stats_df") && nrow(trajectory_stats_df) >= 2) { # Parameters to analyze - params_to_analyze <- c("diffusion_distance_km", "straightness", "duration_min", + params_to_analyze <- c("diffusion_distance_km", "straightness", "duration_mins", "mean_velocity_kmh", "fractal_dimension") param_labels <- c("Diffusion Distance (km)", "Straightness Index", "Duration (min)", "Mean Velocity (km/h)", "Fractal Dimension") @@ -286,7 +289,6 @@ if (exists("trajectory_stats_df") && nrow(trajectory_stats_df) >= 2) { ylab = label, col = "lightblue", border = "darkblue") - # Add mean point points(1, mean(data), pch = 18, col = "red", cex = 1.5) }