• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Courseography / courseography / 8539aa93-84f2-44b3-b9e6-d50e570cbd5c

30 May 2026 03:12PM UTC coverage: 58.634% (+0.4%) from 58.281%
8539aa93-84f2-44b3-b9e6-d50e570cbd5c

Pull #1718

circleci

AngelsandDevsLOL
update changelog to include Time module
Pull Request #1718: Refactor Building and Time functions into Models

503 of 964 branches covered (52.18%)

Branch coverage included in aggregate %.

38 of 40 new or added lines in 2 files covered. (95.0%)

28 existing lines in 1 file now uncovered.

2373 of 3941 relevant lines covered (60.21%)

164.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/app/Models/Building.hs
1
module Models.Building
2
    (buildingsCSV,
3
    parseBuildings,
4
    getBuildingsFromCSV,
5
    getBuilding) where
6

7
import Config (runDb)
8
import Control.Monad.IO.Class (liftIO)
9
import Data.CSV (csvFile)
10
import qualified Data.Text as T
11
import Database.Persist.Sqlite (Filter, SqlPersistM, deleteWhere, entityVal, insertMany_,
12
                                selectFirst, (==.))
13
import Database.Tables (Building (Building), EntityField (BuildingCode))
14
import Filesystem.Path.CurrentOS as Path (append, decodeString, encodeString)
15
import System.Directory (getCurrentDirectory)
16
import Text.ParserCombinators.Parsec (parseFromFile)
17
import Util.Helpers (safeHead)
18

19
buildingsCSV :: IO Prelude.FilePath
20
buildingsCSV = do
1✔
21
    curDir <- getCurrentDirectory
3✔
22
    return $ Path.encodeString $ Path.append (Path.decodeString curDir) $ Path.append (Path.decodeString "db") (Path.decodeString "building.csv")
3✔
23

24
parseBuildings :: IO ()
25
parseBuildings = do
1✔
26
    buildingInfo <- getBuildingsFromCSV =<< buildingsCSV
3✔
27
    runDb $ do
3✔
28
        liftIO $ putStrLn "Inserting buildings"
1✔
29
        deleteWhere ([] :: [Filter Building]) :: SqlPersistM ()
1✔
30
        insertMany_ buildingInfo :: SqlPersistM ()
3✔
31

32
-- | Extract building names, codes, addresses, postal codes, latitude and longitude from csv file
33
getBuildingsFromCSV :: String -> IO [Building]
34
getBuildingsFromCSV buildingCSVFile = do
3✔
35
    buildingCSVData <- parseFromFile csvFile buildingCSVFile
3✔
36
    case buildingCSVData of
3✔
NEW
37
        Left _ -> error "csv parse error"
×
38
        Right buildingData ->
39
            return $ map (\b -> Building (T.pack $ safeHead "" b)
513✔
40
                                        (T.pack (b !! 1))
513✔
41
                                        (T.pack (b !! 2))
513✔
42
                                        (T.pack (b !! 3))
513✔
43
                                        (read (b !! 4) :: Double)
513✔
44
                                        (read (b !! 5) :: Double)) $ drop 1 buildingData
513✔
45

46
-- | Given a building code, get the persistent Building associated with it
47
getBuilding :: Maybe T.Text -> SqlPersistM (Maybe Building)
48
getBuilding rm =
49
    case rm of
8✔
50
        Nothing -> return Nothing
4✔
51
        Just r -> do
4✔
52
            maybeEntityBuilding <- selectFirst [BuildingCode ==. T.take 2 r] []
4✔
53
            case maybeEntityBuilding of
4✔
NEW
54
                Nothing -> return Nothing
×
55
                Just entBuilding -> return $ Just (entityVal entBuilding)
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc