fun

Add small script for De Lijn extraction

I wanted to use this in conjunction with Trammekes, but that kind of failed and I eventually used Pandas, but I'll just put this in my tracker for archiving purposes.

Author
Maarten Vangeneugden
Date
April 17, 2025, 4:08 p.m.
Hash
f39d954c732e3b29ce470d1661f720f03b2b23e0
Parent
c3be70d1e0392e5a06b6262955324c765b011f4c
Modified file
delijn-stop_ids.hs

delijn-stop_ids.hs

33 additions and 0 deletions.

View changes Hide changes
+
1
-- being visited by the buses of De Lijn. It's necessary to do it this way
+
2
-- because the stops.txt file also includes stops that are not visited anymore.
+
3
+
4
import Data.Set as S
+
5
import qualified Data.Vector as V
+
6
import Data.Gtfs.StopTimes
+
7
import Data.Gtfs.Stops
+
8
import Data.Text
+
9
import qualified Data.ByteString.Lazy as BL
+
10
import Data.Either (fromRight)
+
11
import Data.Csv (decodeByName)
+
12
+
13
+
14
extractStopTimes :: String -> IO (V.Vector StopTime)
+
15
extractStopTimes filepath = do
+
16
  x <- BL.readFile filepath
+
17
  let decodeE = decodeByName x
+
18
  --let stoptimes = snd $ fromRight (V.empty, V.empty) decodeE
+
19
  return (snd $ fromRight (V.empty, V.empty) decodeE)
+
20
  
+
21
+
22
+
23
stot :: StopID -> Text
+
24
stot (StopID a) = a
+
25
+
26
allStopIDs :: V.Vector StopTime -> S.Set Text -> S.Set Text
+
27
allStopIDs stopTimes set = case stopTimes V.!? 0 of
+
28
  Just x -> case stoptime_stop_id x of
+
29
    Just y ->  allStopIDs (V.tail stopTimes) $ S.insert (stot y) set
+
30
    Nothing -> allStopIDs (V.tail stopTimes) set
+
31
  Nothing -> set
+
32
                        
+
33