wip: fix: trajectory stats for single aircraft
This commit is contained in:
24
src/app.Rmd
24
src/app.Rmd
@@ -39,7 +39,7 @@ ui <- fluidPage(
|
|||||||
hr(),
|
hr(),
|
||||||
|
|
||||||
h4("Batch Analysis"),
|
h4("Batch Analysis"),
|
||||||
numericInput("batch_size", "Number of flights to analyze:", value = 10, min = 2, max = 50),
|
numericInput("batch_size", "Days of flights to analyze:", value = 5, min = 1, max = 30),
|
||||||
actionButton("batch_analyze", "Run Batch Analysis", class = "btn-warning"),
|
actionButton("batch_analyze", "Run Batch Analysis", class = "btn-warning"),
|
||||||
|
|
||||||
hr(),
|
hr(),
|
||||||
@@ -144,6 +144,7 @@ server <- function(input, output, session) {
|
|||||||
data.frame(
|
data.frame(
|
||||||
Index = i,
|
Index = i,
|
||||||
ICAO24 = dep[["ICAO24"]] %||% NA,
|
ICAO24 = dep[["ICAO24"]] %||% NA,
|
||||||
|
#FIXME Callsign, Origin, Destination
|
||||||
Callsign = dep[["callsign"]] %||% NA,
|
Callsign = dep[["callsign"]] %||% NA,
|
||||||
Origin = dep[["estDepartureAirport"]] %||% NA,
|
Origin = dep[["estDepartureAirport"]] %||% NA,
|
||||||
Destination = dep[["estArrivalAirport"]] %||% NA,
|
Destination = dep[["estArrivalAirport"]] %||% NA,
|
||||||
@@ -248,28 +249,9 @@ server <- function(input, output, session) {
|
|||||||
status("Running batch analysis...")
|
status("Running batch analysis...")
|
||||||
|
|
||||||
tryCatch({
|
tryCatch({
|
||||||
all_trajectories <- list()
|
|
||||||
n_departures <- min(length(rv$departures), input$batch_size)
|
|
||||||
|
|
||||||
withProgress(message = 'Analyzing flights', value = 0, {
|
withProgress(message = 'Analyzing flights', value = 0, {
|
||||||
for (i in 1:n_departures) {
|
all_trajectories <- getAircraftTrajectories(rv$current_icao, time = Sys.time(), creds, days = input$batch_size)
|
||||||
dep <- rv$departures[[i]]
|
|
||||||
icao24 <- dep[["ICAO24"]]
|
|
||||||
dep_time <- dep[["departure_time"]]
|
|
||||||
|
|
||||||
incProgress(1/n_departures, detail = paste("Processing", icao24))
|
|
||||||
|
|
||||||
if (is.null(dep_time)) next
|
|
||||||
|
|
||||||
# Use calculate_trajectory_params from main.Rmd
|
|
||||||
params <- calculate_trajectory_params(icao24, dep_time, rv$creds)
|
|
||||||
|
|
||||||
if (!is.null(params)) {
|
|
||||||
all_trajectories[[length(all_trajectories) + 1]] <- params
|
|
||||||
}
|
|
||||||
|
|
||||||
Sys.sleep(0.3)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (length(all_trajectories) > 0) {
|
if (length(all_trajectories) > 0) {
|
||||||
|
|||||||
25
src/main.Rmd
25
src/main.Rmd
@@ -52,6 +52,8 @@ getAircraftTrack <- function(icao, time, creds) {
|
|||||||
}
|
}
|
||||||
return(NULL)
|
return(NULL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Trajectory Conversion Functions
|
## Trajectory Conversion Functions
|
||||||
@@ -86,7 +88,6 @@ getTrajFromRoute <- function(route_df) {
|
|||||||
# Calculate trajectory characteristics
|
# Calculate trajectory characteristics
|
||||||
# Input: either route_df (data.frame with lat/lon) or trj (trajr object)
|
# Input: either route_df (data.frame with lat/lon) or trj (trajr object)
|
||||||
# format: "row" for batch analysis (one row per flight), "table" for single flight display
|
# format: "row" for batch analysis (one row per flight), "table" for single flight display
|
||||||
# FIXME for batch analysis: use the same aircraft
|
|
||||||
calculateTrajectoryStats <- function(input, icao = NULL, format = "row") {
|
calculateTrajectoryStats <- function(input, icao = NULL, format = "row") {
|
||||||
# Determine if input is route_df or trj
|
# Determine if input is route_df or trj
|
||||||
if (inherits(input, "Trajectory")) {
|
if (inherits(input, "Trajectory")) {
|
||||||
@@ -165,6 +166,21 @@ calculate_trajectory_params <- function(icao, departure_time, creds) {
|
|||||||
return(NULL)
|
return(NULL)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getAircraftTrajectories <- function(icao, time, creds, days = 5){
|
||||||
|
tracks <- list()
|
||||||
|
for (i in 0: (days-1)) {
|
||||||
|
flights <- getFlights(icao,time - days(i),creds)
|
||||||
|
for (f in flights){
|
||||||
|
track <- calculate_trajectory_params(icao, f[["departure_time"]], creds)
|
||||||
|
if (!is.null(track)){
|
||||||
|
tracks[[length(tracks)+1]] <- track
|
||||||
|
}
|
||||||
|
Sys.sleep(0.5) # API courtesy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(tracks)
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Statistical Helper Functions
|
## Statistical Helper Functions
|
||||||
@@ -313,7 +329,10 @@ generateInterpretation <- function(trajectory_stats_df) {
|
|||||||
# Set eval=TRUE to run this demo
|
# Set eval=TRUE to run this demo
|
||||||
|
|
||||||
# Get credentials
|
# Get credentials
|
||||||
creds <- getCredentials()
|
creds <- getCredentials(
|
||||||
|
client_id = Sys.getenv('OPENSKY_CLIENT_ID'),
|
||||||
|
client_secret = Sys.getenv('OPENSKY_CLIENT_SECRET')
|
||||||
|
)
|
||||||
|
|
||||||
# Get departures from Frankfurt airport
|
# Get departures from Frankfurt airport
|
||||||
time_now <- Sys.time()
|
time_now <- Sys.time()
|
||||||
@@ -343,7 +362,7 @@ if (length(departures) > 0) {
|
|||||||
xlab = "Time (Unix)", ylab = "Height (Meter)")
|
xlab = "Time (Unix)", ylab = "Height (Meter)")
|
||||||
|
|
||||||
# Get summary
|
# Get summary
|
||||||
print(getRouteSummary(route_df, icao))
|
print(calculateTrajectoryStats(route_df, icao))
|
||||||
|
|
||||||
# Plot trajectory
|
# Plot trajectory
|
||||||
trj <- getTrajFromRoute(route_df)
|
trj <- getTrajFromRoute(route_df)
|
||||||
|
|||||||
Reference in New Issue
Block a user