From 26936dd0c3767243bbc38781a8d30d73a34a4e6d Mon Sep 17 00:00:00 2001 From: Philip Heltweg Date: Thu, 29 Feb 2024 17:15:44 +0100 Subject: [PATCH] feat: :sparkles: Added basic GTFS domain specific blocks to stdLib (#534) * feat: :sparkles: Added basic GTFS domain specific blocks to stdLib --- example/gtfs-static.jv | 343 ++---------------- .../domain/mobility/GTFSAgencyInterpreter.jv | 37 ++ .../mobility/GTFSCalendarDatesInterpreter.jv | 37 ++ .../mobility/GTFSCalendarInterpreter.jv | 44 +++ .../{ => domain/mobility}/GTFSExtractor.jv | 2 +- .../mobility/GTFSFareAttributesInterpreter.jv | 40 ++ .../mobility/GTFSFareRulesInterpreter.jv | 38 ++ .../mobility/GTFSFrequenciesInterpreter.jv | 37 ++ .../domain/mobility/GTFSRoutesInterpreter.jv | 42 +++ .../domain/mobility/GTFSShapesInterpreter.jv | 38 ++ .../mobility/GTFSStopTimesInterpreter.jv | 42 +++ .../domain/mobility/GTFSStopsInterpreter.jv | 40 ++ .../domain/mobility/GTFSTripsInterpreter.jv | 40 ++ .../stdlib/domain/mobility/GTFSValueTypes.jv | 97 +++++ 14 files changed, 571 insertions(+), 306 deletions(-) create mode 100644 libs/language-server/src/stdlib/domain/mobility/GTFSAgencyInterpreter.jv create mode 100644 libs/language-server/src/stdlib/domain/mobility/GTFSCalendarDatesInterpreter.jv create mode 100644 libs/language-server/src/stdlib/domain/mobility/GTFSCalendarInterpreter.jv rename libs/language-server/src/stdlib/{ => domain/mobility}/GTFSExtractor.jv (86%) create mode 100644 libs/language-server/src/stdlib/domain/mobility/GTFSFareAttributesInterpreter.jv create mode 100644 libs/language-server/src/stdlib/domain/mobility/GTFSFareRulesInterpreter.jv create mode 100644 libs/language-server/src/stdlib/domain/mobility/GTFSFrequenciesInterpreter.jv create mode 100644 libs/language-server/src/stdlib/domain/mobility/GTFSRoutesInterpreter.jv create mode 100644 libs/language-server/src/stdlib/domain/mobility/GTFSShapesInterpreter.jv create mode 100644 libs/language-server/src/stdlib/domain/mobility/GTFSStopTimesInterpreter.jv create mode 100644 libs/language-server/src/stdlib/domain/mobility/GTFSStopsInterpreter.jv create mode 100644 libs/language-server/src/stdlib/domain/mobility/GTFSTripsInterpreter.jv create mode 100644 libs/language-server/src/stdlib/domain/mobility/GTFSValueTypes.jv diff --git a/example/gtfs-static.jv b/example/gtfs-static.jv index 7703ca1f..9e36e3c4 100644 --- a/example/gtfs-static.jv +++ b/example/gtfs-static.jv @@ -12,84 +12,50 @@ pipeline GtfsPipeline { // 2. The origin for multiple pipe sequences is a zip - // file. Each csv file in this zip is further processed + // file. Each file in this zip is further processed // by its own sequence of blocks and pipes. - GTFSSampleFeedExtractor - -> AgencyFilePicker - -> AgencyTextFileInterpreter - -> AgencyCSVInterpreter - -> AgencyTableInterpreter + -> AgencyInterpreter -> AgencyLoader; GTFSSampleFeedExtractor - -> CalendarDatesFilePicker - -> CalendarDatesTextFileInterpreter - -> CalendarDatesCSVInterpreter - -> CalendarDatesTableInterpreter + -> CalendarDatesInterpreter -> CalendarDatesLoader; GTFSSampleFeedExtractor - -> CalendarFilePicker - -> CalendarTextFileInterpreter - -> CalendarCSVInterpreter - -> CalendarTableInterpreter + -> CalendarInterpreter -> CalendarLoader; GTFSSampleFeedExtractor - -> FareAttributesFilePicker - -> FareAttributesTextFileInterpreter - -> FareAttributesCSVInterpreter - -> FareAttributesTableInterpreter + -> FareAttributesInterpreter -> FareAttributesLoader; GTFSSampleFeedExtractor - -> FareRulesFilePicker - -> FareRulesTextFileInterpreter - -> FareRulesCSVInterpreter - -> FareRulesTableInterpreter + -> FareRulesInterpreter -> FareRulesLoader; GTFSSampleFeedExtractor - -> FrequenciesFilePicker - -> FrequenciesTextFileInterpreter - -> FrequenciesCSVInterpreter - -> FrequenciesTableInterpreter + -> FrequenciesInterpreter -> FrequenciesLoader; GTFSSampleFeedExtractor - -> RoutesFilePicker - -> RoutesTextFileInterpreter - -> RoutesCSVInterpreter - -> RoutesTableInterpreter + -> RoutesInterpreter -> RoutesLoader; GTFSSampleFeedExtractor - -> ShapesFilePicker - -> ShapesTextFileInterpreter - -> ShapesCSVInterpreter - -> ShapesTableInterpreter + -> ShapesInterpreter -> ShapesLoader; GTFSSampleFeedExtractor - -> StopTimesFilePicker - -> StopTimesTextFileInterpreter - -> StopTimesCSVInterpreter - -> StopTimesTableInterpreter + -> StopTimesInterpreter -> StopTimesLoader; GTFSSampleFeedExtractor - -> StopsFilePicker - -> StopsTextFileInterpreter - -> StopsCSVInterpreter - -> StopsTableInterpreter + -> StopsInterpreter -> StopsLoader; GTFSSampleFeedExtractor - -> TripsFilePicker - -> TripsTextFileInterpreter - -> TripsCSVInterpreter - -> TripsTableInterpreter + -> TripsInterpreter -> TripsLoader; // 3. As a first step, we download the zip file and interpret it. @@ -97,263 +63,30 @@ pipeline GtfsPipeline { url: "https://developers.google.com/static/transit/gtfs/examples/sample-feed.zip"; } - // 4. Next, we pick several csv files (with the file extension ".txt") - // for further processing . - block AgencyFilePicker oftype FilePicker { - path: "/agency.txt"; - } - - block CalendarDatesFilePicker oftype FilePicker { - path: "/calendar_dates.txt"; - } - - block CalendarFilePicker oftype FilePicker { - path: "/calendar.txt"; - } - - block FareAttributesFilePicker oftype FilePicker { - path: "/fare_attributes.txt"; - } - - block FareRulesFilePicker oftype FilePicker { - path: "/fare_rules.txt"; - } - - block FrequenciesFilePicker oftype FilePicker { - path: "/frequencies.txt"; - } - - block RoutesFilePicker oftype FilePicker { - path: "/routes.txt"; - } - - block ShapesFilePicker oftype FilePicker { - path: "/shapes.txt"; - } - - block StopTimesFilePicker oftype FilePicker { - path: "/stop_times.txt"; - } - - block StopsFilePicker oftype FilePicker { - path: "/stops.txt"; - } - - block TripsFilePicker oftype FilePicker { - path: "/trips.txt"; - } - - // 5. The rest of the pipeline follows the usual pattern. - block AgencyTextFileInterpreter oftype TextFileInterpreter { } - block CalendarDatesTextFileInterpreter oftype TextFileInterpreter { } - block CalendarTextFileInterpreter oftype TextFileInterpreter { } - block FareAttributesTextFileInterpreter oftype TextFileInterpreter { } - block FareRulesTextFileInterpreter oftype TextFileInterpreter { } - block FrequenciesTextFileInterpreter oftype TextFileInterpreter { } - block RoutesTextFileInterpreter oftype TextFileInterpreter { } - block ShapesTextFileInterpreter oftype TextFileInterpreter { } - block StopTimesTextFileInterpreter oftype TextFileInterpreter { } - block StopsTextFileInterpreter oftype TextFileInterpreter { } - block TripsTextFileInterpreter oftype TextFileInterpreter { } - block AgencyCSVInterpreter oftype CSVInterpreter { } - block CalendarDatesCSVInterpreter oftype CSVInterpreter { } - block CalendarCSVInterpreter oftype CSVInterpreter { } - block FareAttributesCSVInterpreter oftype CSVInterpreter { } - block FareRulesCSVInterpreter oftype CSVInterpreter { } - block FrequenciesCSVInterpreter oftype CSVInterpreter { } - block RoutesCSVInterpreter oftype CSVInterpreter { } - block ShapesCSVInterpreter oftype CSVInterpreter { } - block StopTimesCSVInterpreter oftype CSVInterpreter { } - block StopsCSVInterpreter oftype CSVInterpreter { } - block TripsCSVInterpreter oftype CSVInterpreter { } - - block AgencyTableInterpreter oftype TableInterpreter { - header: true; - columns:[ - "agency_id" oftype text, //Conditional columns are considered as required - "agency_name" oftype text, - "agency_url" oftype text, - "agency_timezone" oftype text - ]; - } - - block CalendarDatesTableInterpreter oftype TableInterpreter { - header: true; - columns: [ - "service_id" oftype text, - "date" oftype text, - "exception_type" oftype text - ]; - } - - block CalendarTableInterpreter oftype TableInterpreter { - header: true; - columns: [ - "service_id" oftype text, - "monday" oftype text, - "tuesday" oftype text, - "wednesday" oftype text, - "thursday" oftype text, - "friday" oftype text, - "saturday" oftype text, - "sunday" oftype text, - "start_date" oftype text, - "end_date" oftype text - ]; - } - - block FareAttributesTableInterpreter oftype TableInterpreter { - header: true; - columns: [ - "fare_id" oftype text, - "price" oftype text, - "currency_type" oftype text, - "payment_method" oftype text, - "transfers" oftype text, - "transfer_duration" oftype text - ]; - } - - block FareRulesTableInterpreter oftype TableInterpreter { - header: true; - columns: [ - "fare_id" oftype text, - "route_id" oftype text, - "origin_id" oftype text, - "destination_id" oftype text, - "contains_id" oftype text - ]; - } - - block FrequenciesTableInterpreter oftype TableInterpreter { - header: true; - columns: [ - "trip_id" oftype text, - "start_time" oftype text, - "end_time" oftype text, - "headway_secs" oftype text - ]; - } - - block RoutesTableInterpreter oftype TableInterpreter { - header: true; - columns: [ - "route_id" oftype text, - "agency_id" oftype text, - "route_short_name" oftype text, - "route_long_name" oftype text, - "route_desc" oftype text, - "route_type" oftype text, - "route_url" oftype text, - "route_color" oftype text, - "route_text_color" oftype text - ]; - } - - block ShapesTableInterpreter oftype TableInterpreter { - header: true; - columns: [ - "shape_id" oftype text, - "shape_pt_lat" oftype text, - "shape_pt_lon" oftype text, - "shape_pt_sequence" oftype text, - "shape_dist_traveled" oftype text - ]; - } - - block StopTimesTableInterpreter oftype TableInterpreter { - header: true; - columns: [ - "trip_id" oftype text, - "arrival_time" oftype text, - "departure_time" oftype text, - "stop_id" oftype text, - "stop_sequence" oftype text, - "stop_headsign" oftype text, - "pickup_type" oftype text, - "drop_off_time" oftype text, - "shape_dist_traveled" oftype text - ]; - } - - block StopsTableInterpreter oftype TableInterpreter { - header: true; - columns:[ - "stop_id" oftype text, - "stop_name" oftype text, - "stop_desc" oftype text, - "stop_lat" oftype text, - "stop_lon" oftype text, - "zone_id" oftype text, - "stop_url" oftype text - ]; - } - - block TripsTableInterpreter oftype TableInterpreter { - header: true; - columns: [ - "route_id" oftype text, - "service_id" oftype text, - "trip_id" oftype text, - "trip_headsign" oftype text, - "direction_id" oftype text, - "block_id" oftype text, - "shape_id" oftype text - ]; - } - - block AgencyLoader oftype SQLiteLoader { - table: "agency"; - file: "./gtfs.sqlite"; - } - - block CalendarDatesLoader oftype SQLiteLoader { - table: "calendar_dates"; - file: "./gtfs.sqlite"; - } - - block CalendarLoader oftype SQLiteLoader { - table: "calendar"; - file: "./gtfs.sqlite"; - } - - block FareAttributesLoader oftype SQLiteLoader { - table: "fare_attributes"; - file: "./gtfs.sqlite"; - } - - block FareRulesLoader oftype SQLiteLoader { - table: "fare_rules"; - file: "./gtfs.sqlite"; - } - - block FrequenciesLoader oftype SQLiteLoader { - table: "frequencies"; - file: "./gtfs.sqlite"; - } - - block RoutesLoader oftype SQLiteLoader { - table: "routes"; - file: "./gtfs.sqlite"; - } - - block ShapesLoader oftype SQLiteLoader { - table: "shapes"; - file: "./gtfs.sqlite"; - } - - block StopTimesLoader oftype SQLiteLoader { - table: "stop_times"; - file: "./gtfs.sqlite"; - } - - block StopsLoader oftype SQLiteLoader { - table: "stops"; - file: "./gtfs.sqlite"; - } - - block TripsLoader oftype SQLiteLoader { - table: "trips"; - file: "./gtfs.sqlite"; - } + // 4. Next, interpret the zip files contents according to the different elements + // from the GTFS standard. + block AgencyInterpreter oftype GTFSAgencyInterpreter { } + block CalendarDatesInterpreter oftype GTFSCalendarDatesInterpreter { } + block CalendarInterpreter oftype GTFSCalendarInterpreter { } + block FareAttributesInterpreter oftype GTFSFareAttributesInterpreter { } + block FareRulesInterpreter oftype GTFSFareRulesInterpreter { } + block FrequenciesInterpreter oftype GTFSFrequenciesInterpreter { } + block RoutesInterpreter oftype GTFSRoutesInterpreter { } + block ShapesInterpreter oftype GTFSShapesInterpreter { } + block StopTimesInterpreter oftype GTFSStopTimesInterpreter { } + block StopsInterpreter oftype GTFSStopsInterpreter { } + block TripsInterpreter oftype GTFSTripsInterpreter { } + + // 5. Finally, write the interpreted tables into a SQLite database + block AgencyLoader oftype SQLiteLoader { table: "agency"; file: "./gtfs.sqlite"; } + block CalendarDatesLoader oftype SQLiteLoader { table: "calendar_dates"; file: "./gtfs.sqlite"; } + block CalendarLoader oftype SQLiteLoader { table: "calendar"; file: "./gtfs.sqlite"; } + block FareAttributesLoader oftype SQLiteLoader { table: "fare_attributes"; file: "./gtfs.sqlite"; } + block FareRulesLoader oftype SQLiteLoader { table: "fare_rules"; file: "./gtfs.sqlite"; } + block FrequenciesLoader oftype SQLiteLoader { table: "frequencies"; file: "./gtfs.sqlite"; } + block RoutesLoader oftype SQLiteLoader { table: "routes"; file: "./gtfs.sqlite"; } + block ShapesLoader oftype SQLiteLoader { table: "shapes"; file: "./gtfs.sqlite"; } + block StopTimesLoader oftype SQLiteLoader { table: "stop_times"; file: "./gtfs.sqlite"; } + block StopsLoader oftype SQLiteLoader { table: "stops"; file: "./gtfs.sqlite"; } + block TripsLoader oftype SQLiteLoader { table: "trips"; file: "./gtfs.sqlite"; } } \ No newline at end of file diff --git a/libs/language-server/src/stdlib/domain/mobility/GTFSAgencyInterpreter.jv b/libs/language-server/src/stdlib/domain/mobility/GTFSAgencyInterpreter.jv new file mode 100644 index 00000000..61edadc7 --- /dev/null +++ b/libs/language-server/src/stdlib/domain/mobility/GTFSAgencyInterpreter.jv @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +/** +* A GTFSAgencyInterpreter interprets a agency.txt file from an extracted ZIP file according to the GTFS standard +* See https://gtfs.org/schedule/reference/#agencytxt +*/ +composite blocktype GTFSAgencyInterpreter { + + input inputPort oftype FileSystem; + output outputPort oftype Table; + + inputPort + -> AgencyFilePicker + -> AgencyTextFileInterpreter + -> AgencyCSVInterpreter + -> AgencyTableInterpreter + -> outputPort; + + block AgencyFilePicker oftype FilePicker { + path: "/agency.txt"; + } + + block AgencyTextFileInterpreter oftype TextFileInterpreter { } + block AgencyCSVInterpreter oftype CSVInterpreter { } + + block AgencyTableInterpreter oftype TableInterpreter { + header: true; + columns: [ + "agency_id" oftype text, // Conditional columns are considered required for now + "agency_name" oftype text, + "agency_url" oftype GTFSUrl, + "agency_timezone" oftype text + ]; + } +} diff --git a/libs/language-server/src/stdlib/domain/mobility/GTFSCalendarDatesInterpreter.jv b/libs/language-server/src/stdlib/domain/mobility/GTFSCalendarDatesInterpreter.jv new file mode 100644 index 00000000..b08b0f34 --- /dev/null +++ b/libs/language-server/src/stdlib/domain/mobility/GTFSCalendarDatesInterpreter.jv @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +/** +* A GTFSCalendarDatesInterpreter interprets a calendar_dates.txt file from an extracted ZIP file according to the GTFS standard +* See https://gtfs.org/schedule/reference/#calendar_datestxt +*/ +composite blocktype GTFSCalendarDatesInterpreter { + + input inputPort oftype FileSystem; + output outputPort oftype Table; + + inputPort + -> CalendarDatesFilePicker + -> CalendarDatesTextFileInterpreter + -> CalendarDatesCSVInterpreter + -> CalendarDatesTableInterpreter + -> outputPort; + + block CalendarDatesFilePicker oftype FilePicker { + path: "/calendar_dates.txt"; + } + + block CalendarDatesTextFileInterpreter oftype TextFileInterpreter { } + block CalendarDatesCSVInterpreter oftype CSVInterpreter { } + + block CalendarDatesTableInterpreter oftype TableInterpreter { + header: true; + columns: [ + "service_id" oftype text, + "date" oftype GTFSDate, + "exception_type" oftype GTFSEnumOneOrTwo // 1 - Service has been added for the specified date + // 2 - Service has been removed for the specified date. + ]; + } +} diff --git a/libs/language-server/src/stdlib/domain/mobility/GTFSCalendarInterpreter.jv b/libs/language-server/src/stdlib/domain/mobility/GTFSCalendarInterpreter.jv new file mode 100644 index 00000000..be8b32a7 --- /dev/null +++ b/libs/language-server/src/stdlib/domain/mobility/GTFSCalendarInterpreter.jv @@ -0,0 +1,44 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +/** +* A GTFSCalendarInterpreter interprets a calendar.txt file from an extracted ZIP file according to the GTFS standard +* See https://gtfs.org/schedule/reference/#calendartxt +*/ +composite blocktype GTFSCalendarInterpreter { + + input inputPort oftype FileSystem; + output outputPort oftype Table; + + inputPort + -> CalendarFilePicker + -> CalendarTextFileInterpreter + -> CalendarCSVInterpreter + -> CalendarTableInterpreter + -> outputPort; + + block CalendarFilePicker oftype FilePicker { + path: "/calendar.txt"; + } + + block CalendarTextFileInterpreter oftype TextFileInterpreter { } + block CalendarCSVInterpreter oftype CSVInterpreter { } + + block CalendarTableInterpreter oftype TableInterpreter { + header: true; + columns: [ + "service_id" oftype text, + "monday" oftype GTFSEnumTwo, // 1 - Service is available for all Mondays in the date range. + // 0 - Service is not available for Mondays in the date range. + "tuesday" oftype GTFSEnumTwo, + "wednesday" oftype GTFSEnumTwo, + "thursday" oftype GTFSEnumTwo, + "friday" oftype GTFSEnumTwo, + "saturday" oftype GTFSEnumTwo, + "sunday" oftype GTFSEnumTwo, + "start_date" oftype GTFSDate, + "end_date" oftype GTFSDate + ]; + } +} diff --git a/libs/language-server/src/stdlib/GTFSExtractor.jv b/libs/language-server/src/stdlib/domain/mobility/GTFSExtractor.jv similarity index 86% rename from libs/language-server/src/stdlib/GTFSExtractor.jv rename to libs/language-server/src/stdlib/domain/mobility/GTFSExtractor.jv index f1ba6aba..d5699c36 100644 --- a/libs/language-server/src/stdlib/GTFSExtractor.jv +++ b/libs/language-server/src/stdlib/domain/mobility/GTFSExtractor.jv @@ -18,5 +18,5 @@ composite blocktype GTFSExtractor { block FileExtractor oftype HttpExtractor { url: url; } - block ZipArchiveInterpreter oftype ArchiveInterpreter { archiveType: "zip"; } + block ZipArchiveInterpreter oftype ArchiveInterpreter { archiveType: "zip"; } } diff --git a/libs/language-server/src/stdlib/domain/mobility/GTFSFareAttributesInterpreter.jv b/libs/language-server/src/stdlib/domain/mobility/GTFSFareAttributesInterpreter.jv new file mode 100644 index 00000000..40c2cb25 --- /dev/null +++ b/libs/language-server/src/stdlib/domain/mobility/GTFSFareAttributesInterpreter.jv @@ -0,0 +1,40 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +/** +* A GTFSFareAttributesInterpreter interprets a fare_attributes.txt file from an extracted ZIP file according to the GTFS standard +* See https://gtfs.org/schedule/reference/#fare_attributestxt +*/ +composite blocktype GTFSFareAttributesInterpreter { + + input inputPort oftype FileSystem; + output outputPort oftype Table; + + inputPort + -> FareAttributesFilePicker + -> FareAttributesTextFileInterpreter + -> FareAttributesCSVInterpreter + -> FareAttributesTableInterpreter + -> outputPort; + + block FareAttributesFilePicker oftype FilePicker { + path: "/fare_attributes.txt"; + } + + block FareAttributesTextFileInterpreter oftype TextFileInterpreter { } + block FareAttributesCSVInterpreter oftype CSVInterpreter { } + + block FareAttributesTableInterpreter oftype TableInterpreter { + header: true; + columns: [ + "fare_id" oftype text, + "price" oftype GTFSNonNegativeDecimal, + "currency_type" oftype GTFSCurrency, + "payment_method" oftype GTFSEnumTwo, // 0 - Fare is paid on board. + // 1 - Fare must be paid before boarding. + "transfers" oftype text, // Is required but can be empty (?!) so has to be modelled as text... + "transfer_duration" oftype text + ]; + } +} diff --git a/libs/language-server/src/stdlib/domain/mobility/GTFSFareRulesInterpreter.jv b/libs/language-server/src/stdlib/domain/mobility/GTFSFareRulesInterpreter.jv new file mode 100644 index 00000000..0cd5f995 --- /dev/null +++ b/libs/language-server/src/stdlib/domain/mobility/GTFSFareRulesInterpreter.jv @@ -0,0 +1,38 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +/** +* A GTFSFareRulesInterpreter interprets a fare_rules.txt file from an extracted ZIP file according to the GTFS standard +* See https://gtfs.org/schedule/reference/#fare_rulestxt +*/ +composite blocktype GTFSFareRulesInterpreter { + + input inputPort oftype FileSystem; + output outputPort oftype Table; + + inputPort + -> FareRulesFilePicker + -> FareRulesTextFileInterpreter + -> FareRulesCSVInterpreter + -> FareRulesTableInterpreter + -> outputPort; + + block FareRulesFilePicker oftype FilePicker { + path: "/fare_rules.txt"; + } + + block FareRulesTextFileInterpreter oftype TextFileInterpreter { } + block FareRulesCSVInterpreter oftype CSVInterpreter { } + + block FareRulesTableInterpreter oftype TableInterpreter { + header: true; + columns: [ + "fare_id" oftype text, + "route_id" oftype text, + "origin_id" oftype text, + "destination_id" oftype text, + "contains_id" oftype text + ]; + } +} diff --git a/libs/language-server/src/stdlib/domain/mobility/GTFSFrequenciesInterpreter.jv b/libs/language-server/src/stdlib/domain/mobility/GTFSFrequenciesInterpreter.jv new file mode 100644 index 00000000..5d812090 --- /dev/null +++ b/libs/language-server/src/stdlib/domain/mobility/GTFSFrequenciesInterpreter.jv @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +/** +* A GTFSFrequenciesInterpreter interprets a frequencies.txt file from an extracted ZIP file according to the GTFS standard +* See https://gtfs.org/schedule/reference/#frequenciestxt +*/ +composite blocktype GTFSFrequenciesInterpreter { + + input inputPort oftype FileSystem; + output outputPort oftype Table; + + inputPort + -> FrequenciesFilePicker + -> FrequenciesTextFileInterpreter + -> FrequenciesCSVInterpreter + -> FrequenciesTableInterpreter + -> outputPort; + + block FrequenciesFilePicker oftype FilePicker { + path: "/frequencies.txt"; + } + + block FrequenciesTextFileInterpreter oftype TextFileInterpreter { } + block FrequenciesCSVInterpreter oftype CSVInterpreter { } + + block FrequenciesTableInterpreter oftype TableInterpreter { + header: true; + columns: [ + "trip_id" oftype text, + "start_time" oftype GTFSTime, + "end_time" oftype GTFSTime, + "headway_secs" oftype GTFSNonNegativeInteger + ]; + } +} diff --git a/libs/language-server/src/stdlib/domain/mobility/GTFSRoutesInterpreter.jv b/libs/language-server/src/stdlib/domain/mobility/GTFSRoutesInterpreter.jv new file mode 100644 index 00000000..45a8e9ca --- /dev/null +++ b/libs/language-server/src/stdlib/domain/mobility/GTFSRoutesInterpreter.jv @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +/** +* A GTFSRoutesInterpreter interprets a routes.txt file from an extracted ZIP file according to the GTFS standard +* See https://gtfs.org/schedule/reference/#routestxt +*/ +composite blocktype GTFSRoutesInterpreter { + + input inputPort oftype FileSystem; + output outputPort oftype Table; + + inputPort + -> RoutesFilePicker + -> RoutesTextFileInterpreter + -> RoutesCSVInterpreter + -> RoutesTableInterpreter + -> outputPort; + + block RoutesFilePicker oftype FilePicker { + path: "/routes.txt"; + } + + block RoutesTextFileInterpreter oftype TextFileInterpreter { } + block RoutesCSVInterpreter oftype CSVInterpreter { } + + block RoutesTableInterpreter oftype TableInterpreter { + header: true; + columns: [ + "route_id" oftype text, + "agency_id" oftype text, + "route_short_name" oftype text, + "route_long_name" oftype text, + "route_desc" oftype text, + "route_type" oftype integer, // Technically is an enum from 0 - 12 + "route_url" oftype text, + "route_color" oftype text, + "route_text_color" oftype text + ]; + } +} diff --git a/libs/language-server/src/stdlib/domain/mobility/GTFSShapesInterpreter.jv b/libs/language-server/src/stdlib/domain/mobility/GTFSShapesInterpreter.jv new file mode 100644 index 00000000..bf830d44 --- /dev/null +++ b/libs/language-server/src/stdlib/domain/mobility/GTFSShapesInterpreter.jv @@ -0,0 +1,38 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +/** +* A GTFSShapesInterpreter interprets a shapes.txt file from an extracted ZIP file according to the GTFS standard +* See https://gtfs.org/schedule/reference/#shapestxt +*/ +composite blocktype GTFSShapesInterpreter { + + input inputPort oftype FileSystem; + output outputPort oftype Table; + + inputPort + -> ShapesFilePicker + -> ShapesTextFileInterpreter + -> ShapesCSVInterpreter + -> ShapesTableInterpreter + -> outputPort; + + block ShapesFilePicker oftype FilePicker { + path: "/shapes.txt"; + } + + block ShapesTextFileInterpreter oftype TextFileInterpreter { } + block ShapesCSVInterpreter oftype CSVInterpreter { } + + block ShapesTableInterpreter oftype TableInterpreter { + header: true; + columns: [ + "shape_id" oftype text, + "shape_pt_lat" oftype GTFSLatitude, + "shape_pt_lon" oftype GTFSLongitude, + "shape_pt_sequence" oftype GTFSNonNegativeInteger, + "shape_dist_traveled" oftype text + ]; + } +} diff --git a/libs/language-server/src/stdlib/domain/mobility/GTFSStopTimesInterpreter.jv b/libs/language-server/src/stdlib/domain/mobility/GTFSStopTimesInterpreter.jv new file mode 100644 index 00000000..23862c2b --- /dev/null +++ b/libs/language-server/src/stdlib/domain/mobility/GTFSStopTimesInterpreter.jv @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +/** +* A GTFSStopTimesInterpreter interprets a stop_times.txt file from an extracted ZIP file according to the GTFS standard +* See https://gtfs.org/schedule/reference/#stop_timestxt +*/ +composite blocktype GTFSStopTimesInterpreter { + + input inputPort oftype FileSystem; + output outputPort oftype Table; + + inputPort + -> StopTimesFilePicker + -> StopTimesTextFileInterpreter + -> StopTimesCSVInterpreter + -> StopTimesTableInterpreter + -> outputPort; + + block StopTimesFilePicker oftype FilePicker { + path: "/stop_times.txt"; + } + + block StopTimesTextFileInterpreter oftype TextFileInterpreter { } + block StopTimesCSVInterpreter oftype CSVInterpreter { } + + block StopTimesTableInterpreter oftype TableInterpreter { + header: true; + columns: [ + "trip_id" oftype text, + "arrival_time" oftype GTFSTime, + "departure_time" oftype GTFSTime, + "stop_id" oftype text, + "stop_sequence" oftype GTFSNonNegativeInteger, + "stop_headsign" oftype text, + "pickup_type" oftype text, + "drop_off_time" oftype text, + "shape_dist_traveled" oftype text + ]; + } +} diff --git a/libs/language-server/src/stdlib/domain/mobility/GTFSStopsInterpreter.jv b/libs/language-server/src/stdlib/domain/mobility/GTFSStopsInterpreter.jv new file mode 100644 index 00000000..3d634491 --- /dev/null +++ b/libs/language-server/src/stdlib/domain/mobility/GTFSStopsInterpreter.jv @@ -0,0 +1,40 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +/** +* A GTFSStopsInterpreter interprets a stops.txt file from an extracted ZIP file according to the GTFS standard +* See https://gtfs.org/schedule/reference/#stopstxt +*/ +composite blocktype GTFSStopsInterpreter { + + input inputPort oftype FileSystem; + output outputPort oftype Table; + + inputPort + -> StopsFilePicker + -> StopsTextFileInterpreter + -> StopsCSVInterpreter + -> StopsTableInterpreter + -> outputPort; + + block StopsFilePicker oftype FilePicker { + path: "/stops.txt"; + } + + block StopsTextFileInterpreter oftype TextFileInterpreter { } + block StopsCSVInterpreter oftype CSVInterpreter { } + + block StopsTableInterpreter oftype TableInterpreter { + header: true; + columns: [ + "stop_id" oftype text, + "stop_name" oftype text, + "stop_desc" oftype text, + "stop_lat" oftype GTFSLatitude, + "stop_lon" oftype GTFSLongitude, + "zone_id" oftype text, + "stop_url" oftype text + ]; + } +} diff --git a/libs/language-server/src/stdlib/domain/mobility/GTFSTripsInterpreter.jv b/libs/language-server/src/stdlib/domain/mobility/GTFSTripsInterpreter.jv new file mode 100644 index 00000000..163e5dcf --- /dev/null +++ b/libs/language-server/src/stdlib/domain/mobility/GTFSTripsInterpreter.jv @@ -0,0 +1,40 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +/** +* A GTFSTripsInterpreter interprets a trips.txt file from an extracted ZIP file according to the GTFS standard +* See https://gtfs.org/schedule/reference/#tripstxt +*/ +composite blocktype GTFSTripsInterpreter { + + input inputPort oftype FileSystem; + output outputPort oftype Table; + + inputPort + -> TripsFilePicker + -> TripsTextFileInterpreter + -> TripsCSVInterpreter + -> TripsTableInterpreter + -> outputPort; + + block TripsFilePicker oftype FilePicker { + path: "/trips.txt"; + } + + block TripsTextFileInterpreter oftype TextFileInterpreter { } + block TripsCSVInterpreter oftype CSVInterpreter { } + + block TripsTableInterpreter oftype TableInterpreter { + header: true; + columns: [ + "route_id" oftype text, + "service_id" oftype text, + "trip_id" oftype text, + "trip_headsign" oftype text, + "direction_id" oftype text, + "block_id" oftype text, + "shape_id" oftype text + ]; + } +} diff --git a/libs/language-server/src/stdlib/domain/mobility/GTFSValueTypes.jv b/libs/language-server/src/stdlib/domain/mobility/GTFSValueTypes.jv new file mode 100644 index 00000000..3fd76f4d --- /dev/null +++ b/libs/language-server/src/stdlib/domain/mobility/GTFSValueTypes.jv @@ -0,0 +1,97 @@ +// SPDX-FileCopyrightText: 2023 Friedrich-Alexander-Universitat Erlangen-Nurnberg +// +// SPDX-License-Identifier: AGPL-3.0-only + +/* + * All field type docs in this file are from: https://gtfs.org/schedule/reference/#field-types + */ + +/* + * Color - A color encoded as a six-digit hexadecimal number. Refer to https://htmlcolorcodes.com to generate a valid value (the leading "#" must not be included). + * Example: FFFFFF for white, 000000 for black or 0039A6 for the A,C,E lines in NYMTA. + */ +constraint GTFSColorConstraint on text: value matches /^[A-F]{6}$/; +valuetype GTFSColor oftype text { + constraints: [GTFSColorConstraint]; +} + +/* + * Date - Service day in the YYYYMMDD format. Since time within a service day may be above 24:00:00, a service day may contain information for the subsequent day(s). + * Example: 20180913 for September 13th, 2018. + */ +constraint DateYYYYMMDD on text: value matches /^[0-9]{4}[0-9]{2}[0-9]{2}$/; +valuetype GTFSDate oftype text { + constraints: [DateYYYYMMDD]; +} + +/* + * Currency code - An ISO 4217 alphabetical currency code. For the list of current currency, refer to https://en.wikipedia.org/wiki/ISO_4217#Active_codes. + * Example: CAD for Canadian dollars, EUR for euros or JPY for Japanese yen. + */ +constraint CurrencyConstraint on text: value matches /^[A-Z]{3}$/; +valuetype GTFSCurrency oftype text { + constraints: [CurrencyConstraint]; +} + +/* + * Time - Time in the HH:MM:SS format (H:MM:SS is also accepted). The time is measured from "noon minus 12h" of the service day (effectively midnight except for days on which daylight savings time changes occur). For times occurring after midnight on the service day, enter the time as a value greater than 24:00:00 in HH:MM:SS. + * Example: 14:30:00 for 2:30PM or 25:35:00 for 1:35AM on the next day. + */ +constraint TimeHHMMSS on text: value matches /^[0-9]{1,2}:{1}[0-9]{2}:{1}[0-9]{2}$/; +valuetype GTFSTime oftype text { + constraints: [TimeHHMMSS]; +} + +// Placeholders +constraint EnumTwo on integer: value in [0, 1]; +constraint EnumOneOrTwo on integer: value in [1, 2]; +constraint EnumThree on integer: value in [0, 1, 2]; + +valuetype GTFSEnumTwo oftype integer { + constraints: [EnumTwo]; +} + +valuetype GTFSEnumOneOrTwo oftype integer { + constraints: [EnumOneOrTwo]; +} + +valuetype GTFSEnumThree oftype integer { + constraints: [EnumThree]; +} + +// Generic value types + +/* + * Latitude - WGS84 latitude in decimal degrees. The value must be greater than or equal to -90.0 and less than or equal to 90.0. + * Example: 41.890169 for the Colosseum in Rome. + */ +constraint Latitude on decimal: value >= -90 and value <= 90; +valuetype GTFSLatitude oftype decimal { + constraints: [Latitude]; +} + +/* + * Longitude - WGS84 longitude in decimal degrees. The value must be greater than or equal to -180.0 and less than or equal to 180.0. + * Example: 12.492269 for the Colosseum in Rome. + */ +constraint Longitude on decimal: value >= -180 and value <= 180; +valuetype GTFSLongitude oftype decimal { + constraints: [Longitude]; +} + +constraint NonNegativeNumber on decimal: value >= 0; +valuetype GTFSNonNegativeDecimal oftype decimal { + constraints: [NonNegativeNumber]; +} + +valuetype GTFSNonNegativeInteger oftype integer { + constraints: [NonNegativeNumber]; +} + +/* + * URL - A fully qualified URL that includes http:// or https://, and any special characters in the URL must be correctly escaped. See the following http://www.w3.org/Addressing/URL/4_URI_Recommentations.html for a description of how to create fully qualified URL values. + */ +constraint URLIncludingSchema on text: value matches /^(http)s?(:\/\/)/; +valuetype GTFSUrl oftype text { + constraints: [URLIncludingSchema]; +}