This repository has been archived by the owner on Jan 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gtfs.clj
64 lines (56 loc) · 2.02 KB
/
gtfs.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(ns hiposfer.kamal.specs.gtfs
(:require [clojure.spec.alpha :as s]
[hiposfer.geojson.specs :as geojson]))
;; TODO: here are only the obligatory fields
;; agencies
(s/def ::agency_id some?)
(s/def ::agency_url string?)
(s/def ::agency_name string?)
(s/def ::agency_timezone string?)
(s/def ::agency (s/keys :req-un [::agency_name ::agency_timezone]
:opt-un [::agency_id]))
;; routes
(s/def ::route_id some?)
(s/def ::route_short_name string?)
(s/def ::route_long_name string?)
(s/def ::route_type int?)
(s/def ::route (s/keys :req-un [::route_id ::route_short_name ::route_type]
:opt-un [::agency_id]))
;; stops
(s/def ::stop_lon ::geojson/lon)
(s/def ::stop_lat ::geojson/lat)
(s/def ::stop_id some?)
(s/def ::stop_name string?)
(s/def ::stop (s/keys :req-un [::stop_lon ::stop_lat ::stop_id ::stop_name]))
;; trips
(s/def ::service_id some?)
(s/def ::trip_id some?)
(s/def ::trip (s/keys :req-un [::route_id ::service_id ::trip_id]))
;; stop_times
;; HH:MM:SS
(def re-time "regex expression for gtfs time declarations"
#"(\d{2}):(\d{2}):(\d{2})")
(defn time? [text] (re-matches re-time text))
(s/def ::trip_id some?)
(s/def ::arrival_time (s/and string? time?))
(s/def ::departure_time (s/and string? time?))
(s/def ::stop_sequence some?)
(s/def ::stop_time (s/keys :req-un [::trip_id ::arrival_time ::departure_time
::stop_id ::stop_sequence]))
;; calendar
;; AAAAMMDD
(defn date? [text] (re-matches #"\d{8}" text))
(s/def ::day #{"0" "1"})
(s/def ::monday ::day)
(s/def ::tuesday ::day)
(s/def ::wednesday ::day)
(s/def ::thursday ::day)
(s/def ::friday ::day)
(s/def ::saturday ::day)
(s/def ::sunday ::day)
(s/def ::start_date (s/and string? date?))
(s/def ::end_date (s/and string? date?))
(s/def ::calendar (s/keys :req-un [::service_id ::monday ::tuesday
::wednesday ::thursday ::friday
::saturday ::sunday ::start_date
::end_date]))