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
|
{-# LANGUAGE OverloadedStrings #-}
module IRE.Config (
ConfigFile(..)
, YOLO(..)
, defaultConfig
) where
import Control.Applicative (empty)
import Data.Aeson (FromJSON, parseJSON)
import Data.Yaml (Value(Object), (.:), (.:?), (.!=))
data ConfigFile = ConfigFile {
cfPort :: Int
, cfSocket :: Maybe FilePath
, cfYOLO :: YOLO
} deriving (Show)
data YOLO = YOLO {
yoloCfg :: FilePath
, yoloWeights :: FilePath
, yoloNames :: FilePath
} deriving (Show)
defaultConfig :: ConfigFile
defaultConfig = ConfigFile {
cfPort = 8080
, cfSocket = Nothing
, cfYOLO = YOLO {
yoloCfg = "yolo.cfg"
, yoloWeights = "yolo.weights"
, yoloNames = "yolo.names"
}
}
instance FromJSON ConfigFile where
parseJSON (Object m) = ConfigFile <$>
m .:? "port" .!= cfPort defaultConfig
<*> m .:? "socket" .!= cfSocket defaultConfig
<*> m .:? "yolo" .!= cfYOLO defaultConfig
parseJSON _ = empty
instance FromJSON YOLO where
parseJSON (Object m) = YOLO <$>
m .: "cfg"
<*> m .: "weights"
<*> m .: "names"
parseJSON _ = empty
|