Type: Package
Title: Standard Schedules Information Parser
Version: 0.1.1
Author: Sebastien Thonnard
Maintainer: Sebastien Thonnard <sebastien.thonnard@icloud.com>
Description: Parse Standard Schedules Information file (types 2 and 3) into a Data Frame. Can also expand schedules into flights.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.1.2
Imports: tidyr, dplyr, stringr, airportr, magrittr
NeedsCompilation: no
Packaged: 2022-01-11 18:02:38 UTC; sebastienthonnard
Repository: CRAN
Date/Publication: 2022-01-11 18:30:02 UTC

Pipe operator

Description

See magrittr::%>% for details.

Usage

lhs %>% rhs

Value

For numeric arguments, a numeric vector. For factors, an unordered factor. See magrittr::%>% for details.


get_airport_icao

Description

Get airport ICAO with package airportr.

Usage

get_airport_icao(iata)

Arguments

iata

Airport IATA code.

Value

A character vector containing the airport ICAO or '-' when airportr::airport_detail returned an error.


get_day_of_week

Description

Get day of week (1 = Monday).

Usage

get_day_of_week(pdate = Sys.Date())

Arguments

pdate

An object of class "POSIXct" from which day of week will be extracted.

Value

A double representing the day of week.


get_ssim_collist

Description

Get the list of columns that can be parsed from SSIM.

Usage

get_ssim_collist(getall = TRUE)

Arguments

getall

Get all columns (TRUE/FALSE).

Value

Vector containing the SSIM columns.

Examples

# Get all columns
get_ssim_collist()
# Get some of the most 'useful' columns
get_ssim_collist(FALSE)

get_ssim_sample

Description

Get a test SSIM file for validation and testing.

Usage

get_ssim_sample(
  datefrom = as.Date("2020-11-01"),
  dateto = as.Date("2020-12-01"),
  season = "W20",
  creadate = Sys.Date()
)

Arguments

datefrom

First date of the sample.

dateto

Last date of the sample.

season

IATA season (W20 = Winter 2020).

creadate

Creation date. Default today.

Value

A character vector containing the SSIM sample.

Examples

# Get sample
sample_ssim_str <- ssimparser::get_ssim_sample(datefrom = as.Date("2020-11-01"),
dateto = as.Date("2020-12-01"),
season="W20")

# Parse the sample into a data frame
ssim_sample_df <- ssimparser::load_ssim(ssim_file = sample_ssim_str)
head(ssim_sample_df, 10)

get_utc_time

Description

Get UTC date and time from SSIM local date time and offset.

Usage

get_utc_time(pdate = "27NOV20", ptime = "0000", poffset = "+0000")

Arguments

pdate

Local date formatted as %d%b%y" (eg 27NOV20).

ptime

Local time formatted %H%M (eg 1345 for 13:45).

poffset

UTC offset (+0130 for +01:30).

Value

A "POSIXct" or the description of a conversion problem as a character vector.


load_ssim

Description

Load SSIM file into a Data Frame.

Usage

load_ssim(
  ssim_file = get_ssim_sample(),
  nested_df = FALSE,
  collist = get_ssim_collist(getall = FALSE),
  clean_col_names = TRUE,
  unpivot_days_of_op = FALSE,
  expand_sched = FALSE
)

Arguments

ssim_file

Path to the SSIM file or character vector containing the content to load.

nested_df

Nest SSIM type 3 into type 2 (TRUE/FALSE). Default to FALSE.

collist

List of columns that need to be present in the final Data Frame. get_ssim_collist() to get the full list.

clean_col_names

Clean column names in the final Data Frame by removing type2/type3 prefixes (TRUE/FALSE). Default TRUE.

unpivot_days_of_op

Unpivot the schedules by creating a schedule by day of operation (TRUE/FALSE). Default FALSE.

expand_sched

Expand schedules into flights.

Value

Data Frame (nested or not) containing the schedules (or flights when schedules were expanded).

Examples

# Get a sample as a character vector
sample_ssim_string <- ssimparser::get_ssim_sample(datefrom = as.Date("2020-11-01"),
dateto = as.Date("2020-12-01"),
season = "W20",
creadate = as.Date("2020-12-02"))

# Write sample to temp dir
sample_ssim_file <- tempfile()
write(sample_ssim_string, sample_ssim_file, append = FALSE)

# Load sample, expand schedules to flights and display the traffic
# by month and departure airport ICAO
ssimparser::load_ssim(ssim_file = sample_ssim_file,
expand_sched = TRUE) %>%
dplyr::group_by(format(flight.flight_date,"%Y-%m"), adep_icao) %>%
dplyr::summarise(n=dplyr::n())

# Get the unique list of airports ICAO
ssimparser::load_ssim(ssim_file = sample_ssim_file, expand_sched = TRUE,
collist = c("type3.adep_icao", "type3.ades_icao")) %>% unique()

# Nest the type 3 into type 2
ssim_nested <- ssimparser::load_ssim(ssim_file = sample_ssim_file,
expand_sched = FALSE, nested = TRUE)
head(ssim_nested)

# Remove the sample SSIM file
unlink(sample_ssim_file)

load_ssim_flights

Description

Load multiple SSIM file, expand to flights, and return the result as a Data Frame.
In case of period overlap for a specific flight date, information from the latest file will be used,
so beware of the file order in parameter ssim_files.

Usage

load_ssim_flights(
  ssim_files = c("AFR_20201115.txt", "AFR_20201116.txt"),
  collist = get_ssim_collist(getall = FALSE),
  clean_col_names = TRUE
)

Arguments

ssim_files

List of SSIM files to load, in the correct order (from the first to load to the last file to load).

collist

List of columns that need to be present in the final Data Frame. get_ssim_collist() to get the full list.

clean_col_names

Clean column names in the final Data Frame by removing type2/type3 prefixes (TRUE/FALSE). Default TRUE.

Value

Data Frame containing the flights.

Examples

# Get 3 samples as a character vector
samples <- data.frame(sampleid = c(1:3)) %>%
 dplyr::rowwise() %>%
 dplyr::mutate(
 filename = tempfile(),
 samplestring = ssimparser::get_ssim_sample(datefrom = as.Date("2020-11-01") + (sampleid * 3),
 dateto = as.Date("2020-12-01") + (sampleid * 3),
 season = "W20",
 creadate = as.Date("2020-11-01") + sampleid)
 )
# Write the samples to tempdir
for (i in 1:3)
{
 write(samples[i,]$samplestring, samples[i,]$filename, append = FALSE)
}

# Load the 3 samples and display the total traffic per day
ssimparser::load_ssim_flights(ssim_files = samples$filename) %>%
dplyr::group_by(flight_date = as.Date(flight.flight_date)) %>%
dplyr::summarise(total_flights = dplyr::n()) %>%
dplyr::arrange(desc(flight_date))

# Unlink temp files
for (i in 1:3)
{
  unlink(samples[i,]$filename)
}

ssimparser: A Tool for Parsing Standard Schedules Information (Chapter 7).

Description

Parse SSIM file (types 2 and 3) into a Data Frame.

Bugs report:
https://github.com/sthonnard/ssimparser

ssimparser functions

get_ssim_collist()
Get the list of columns that can be parsed from SSIM.

load_ssim(ssim_file)
Parse SSIM file into a Data Frame.

load_ssim_flights(ssim_files)
Parse multiple SSIM files, expand to flights, and return the result into a Data Frame.

get_ssim_sample()
Get a sample SSIM file as a character vector.