🩹 fix small issues in main
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
```{r backend, child="./main.Rmd"}
|
||||||
|
source("./main.Rmd")
|
||||||
|
exists("getRouteSummary")
|
||||||
|
```
|
||||||
|
|
||||||
# Web Interface
|
# Web Interface
|
||||||
```{r shiny}
|
```{r shiny}
|
||||||
# Flight Trajectory Analysis - Shiny GUI Application
|
# Flight Trajectory Analysis - Shiny GUI Application
|
||||||
|
|||||||
26
src/main.Rmd
26
src/main.Rmd
@@ -104,7 +104,7 @@ getTrajFromRoute <- function(route_df){
|
|||||||
xCol = "x", yCol = "y", timeCol = "time"
|
xCol = "x", yCol = "y", timeCol = "time"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
getRouteSummary<-function(route_df){
|
getRouteSummary<-function(route_df, icao){
|
||||||
meters <- getRouteDistance(route_df)
|
meters <- getRouteDistance(route_df)
|
||||||
x_meters <- meters$x
|
x_meters <- meters$x
|
||||||
y_meters <- meters$y
|
y_meters <- meters$y
|
||||||
@@ -128,6 +128,7 @@ getRouteSummary<-function(route_df){
|
|||||||
straightness <- TrajStraightness(trj)
|
straightness <- TrajStraightness(trj)
|
||||||
|
|
||||||
# 5. Mean travel velocity (meters/second)
|
# 5. Mean travel velocity (meters/second)
|
||||||
|
mean_velocity <- path_length / duration
|
||||||
|
|
||||||
# 6. Fractal dimension (using divider method)
|
# 6. Fractal dimension (using divider method)
|
||||||
# Note: requires sufficient points for accurate estimation
|
# Note: requires sufficient points for accurate estimation
|
||||||
@@ -144,17 +145,17 @@ getRouteSummary<-function(route_df){
|
|||||||
})
|
})
|
||||||
|
|
||||||
return(data.frame(
|
return(data.frame(
|
||||||
icao24 = icao24,
|
icao24 = icao,
|
||||||
diffusion_distance_m = diffusion_distance, # meters
|
diffusion_distance_km = diffusion_distance / 1000, # meters to kilometers
|
||||||
path_length_m = path_length, # meters
|
path_length_km = path_length / 1000, # meters to kilometers
|
||||||
straightness = straightness,
|
straightness = straightness,
|
||||||
duration_s = duration, # seconds
|
duration_mins = duration / 60, # seconds to minutes
|
||||||
mean_velocity_kmh = mean_velocity * 3.6,
|
mean_velocity_kmh = mean_velocity * 3.6,
|
||||||
fractal_dimension = fractal_dim
|
fractal_dimension = fractal_dim
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
print(getRouteSummary(route_df))
|
print(getRouteSummary(route_df, icao))
|
||||||
trj <- getTrajFromRoute(route_df)
|
trj <- getTrajFromRoute(route_df)
|
||||||
plot(trj, main = paste("Trajectory of", icao))
|
plot(trj, main = paste("Trajectory of", icao))
|
||||||
|
|
||||||
@@ -165,14 +166,16 @@ plot(trj, main = paste("Trajectory of", icao))
|
|||||||
# Statistical Analysis of Multiple Trajectories
|
# Statistical Analysis of Multiple Trajectories
|
||||||
```{r multi-trajectory-analysis}
|
```{r multi-trajectory-analysis}
|
||||||
# Function to calculate trajectory characteristics for a single flight
|
# 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({
|
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 dimension
|
||||||
fractal <- tryCatch({
|
fractal <- tryCatch({
|
||||||
|
trj <- getTrajFromRoute(route_df)
|
||||||
|
path_length <- TrajLength(trj)
|
||||||
min_step <- path_length / 100
|
min_step <- path_length / 100
|
||||||
max_step <- path_length / 2
|
max_step <- path_length / 2
|
||||||
if (min_step > 0 && max_step > min_step) {
|
if (min_step > 0 && max_step > min_step) {
|
||||||
@@ -183,10 +186,10 @@ calculate_trajectory_params <- function(icao24, departure_time, creds) {
|
|||||||
}
|
}
|
||||||
}, error = function(e) NA)
|
}, error = function(e) NA)
|
||||||
|
|
||||||
return(getRouteSummary(route_df))
|
return(getRouteSummary(route_df, icao))
|
||||||
|
|
||||||
}, error = function(e) {
|
}, error = function(e) {
|
||||||
message("Error processing ", icao24, ": ", e$message)
|
message("Error processing ", icao, ": ", e$message)
|
||||||
return(NULL)
|
return(NULL)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -233,7 +236,7 @@ if (length(all_trajectories) > 0) {
|
|||||||
if (exists("trajectory_stats_df") && nrow(trajectory_stats_df) >= 2) {
|
if (exists("trajectory_stats_df") && nrow(trajectory_stats_df) >= 2) {
|
||||||
|
|
||||||
# Parameters to analyze
|
# 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")
|
"mean_velocity_kmh", "fractal_dimension")
|
||||||
param_labels <- c("Diffusion Distance (km)", "Straightness Index",
|
param_labels <- c("Diffusion Distance (km)", "Straightness Index",
|
||||||
"Duration (min)", "Mean Velocity (km/h)", "Fractal Dimension")
|
"Duration (min)", "Mean Velocity (km/h)", "Fractal Dimension")
|
||||||
@@ -286,7 +289,6 @@ if (exists("trajectory_stats_df") && nrow(trajectory_stats_df) >= 2) {
|
|||||||
ylab = label,
|
ylab = label,
|
||||||
col = "lightblue",
|
col = "lightblue",
|
||||||
border = "darkblue")
|
border = "darkblue")
|
||||||
|
|
||||||
# Add mean point
|
# Add mean point
|
||||||
points(1, mean(data), pch = 18, col = "red", cex = 1.5)
|
points(1, mean(data), pch = 18, col = "red", cex = 1.5)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user