fun

delijn-stop_ids.hs

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