[phylo] some types fixes

parent 55589ac8
Pipeline #4048 failed with stage
in 0 seconds
......@@ -21,8 +21,8 @@ newtype PhyloJSON = PhyloJSON
, pd_data ::
{ _subgraph_cnt :: Int
, directed :: Boolean
, edges :: Array RawEdge
, objects :: Array RawObject
, edges :: Maybe (Array RawEdge)
, objects :: Maybe (Array RawObject)
, strict :: Boolean
| GraphData
}
......@@ -65,65 +65,65 @@ type GraphData =
--------------------------------------------------
type NodeData =
( height :: String
( height :: Maybe String
, label :: String
, name :: String
, nodeType :: String
, pos :: String
, shape :: String
, width :: String
, nodeType :: Maybe String
, pos :: Maybe String
, shape :: Maybe String
, width :: Maybe String
)
data RawObject
= GroupToNode
{ _gvid :: Int
, bId :: String
, branchId :: String
, fontname :: String
, foundation :: String
, frequence :: String
, from :: String
, lbl :: String
, penwidth :: String
, role :: String
, bId :: Maybe String
, branchId :: Maybe String
, fontname :: Maybe String
, foundation :: Maybe String
, frequence :: Maybe String
, from :: Maybe String
, lbl :: Maybe String
, penwidth :: Maybe String
, role :: Maybe String
-- @NOTE #219: not in API; but present in certain data (eg. "Knowledge
-- visualisation")
, seaLvl :: Maybe String
, source :: String
, source :: Maybe String
, strFrom :: Maybe String
, strTo :: Maybe String
, support :: String
, to :: String
, weight :: String
, support :: Maybe String
, to :: Maybe String
, weight :: Maybe String
| NodeData
}
| BranchToNode
{ _gvid :: Int
, age :: String
, bId :: String
, birth :: String
, branchId :: String
, branch_x :: String
, branch_y :: String
, fillcolor :: String
, fontname :: String
, age :: Maybe String
, bId :: Maybe String
, birth :: Maybe String
, branchId :: Maybe String
, branch_x :: Maybe String
, branch_y :: Maybe String
, fillcolor :: Maybe String
, fontname :: Maybe String
, fontsize :: String
, size :: String
, size :: Maybe String
, style :: String
| NodeData
}
| PeriodToNode
{ _gvid :: Int
, fontsize :: String
, from :: String
, from :: Maybe String
, strFrom :: Maybe String
, strTo :: Maybe String
, to :: String
, to :: Maybe String
| NodeData
}
| Layer
{ _gvid :: Int
, nodes :: Array Int
, nodes :: Maybe (Array Int)
| GraphData
}
......
......@@ -22,7 +22,7 @@ import Data.Date as Date
import Data.Generic.Rep (class Generic)
import Data.FunctorWithIndex (mapWithIndex)
import Data.Int as Int
import Data.Maybe (Maybe(..), maybe)
import Data.Maybe (Maybe(..), maybe, fromMaybe)
import Data.Newtype (class Newtype)
import Data.Number as Number
import Data.Show.Generic (genericShow)
......@@ -85,12 +85,12 @@ parseToPhyloSet (PhyloJSON o) = PhyloSet
epochTS = p.phyloTimeScale == "epoch"
ancestorLinks = parseAncestorLinks p.edges
branchLinks = parseBranchLinks p.edges
branches = parseBranches p.objects
groups = parseGroups epochTS p.objects
links = parseLinks p.edges
periods = parsePeriods epochTS p.objects
ancestorLinks = parseAncestorLinks $ fromMaybe [] p.edges
branchLinks = parseBranchLinks $ fromMaybe [] p.edges
branches = parseBranches $ fromMaybe [] p.objects
groups = parseGroups epochTS $ fromMaybe [] p.objects
links = parseLinks $ fromMaybe [] p.edges
periods = parsePeriods epochTS $ fromMaybe [] p.objects
----------------------------------------------------------------------
......@@ -121,12 +121,12 @@ instance Show PhyloData where show = genericShow
-----------------------------------------------------------
newtype Branch = Branch
{ bId :: Int
{ bId :: Maybe Int
, gvid :: Int
, label :: String
, x1 :: String
, x2 :: Number
, y :: String
, x1 :: Maybe String
, x2 :: Maybe Number
, y :: Maybe String
}
derive instance Generic Branch _
......@@ -141,11 +141,11 @@ parseBranches
where
parse :: RawObject -> Maybe Branch
parse (BranchToNode o) = Just $ Branch
{ bId : parseInt o.bId
{ bId : parseInt <$> o.bId
, gvid : o._gvid
, label : parseLabel o.label
, x1 : o.branch_x
, x2 : Tuple.fst $ parsePos o.pos
, x2 : Tuple.fst <$> parsePos <$> o.pos
, y : o.branch_y
}
parse _ = Nothing
......@@ -157,9 +157,9 @@ parseBranches
-----------------------------------------------------------
newtype Period = Period
{ from :: Date.Date
, to :: Date.Date
, y :: Number
{ from :: Maybe Date.Date
, to :: Maybe Date.Date
, y :: Maybe Number
}
derive instance Generic Period _
......@@ -174,27 +174,27 @@ parsePeriods epoch
where
parse :: RawObject -> Maybe Period
parse (PeriodToNode o) = Just $ Period
{ from : parseNodeDate o.strFrom o.from epoch
, to : parseNodeDate o.strTo o.to epoch
, y : Tuple.snd $ parsePos o.pos
{ from : (\f -> parseNodeDate o.strFrom f epoch) <$> o.from
, to : (\t -> parseNodeDate o.strTo t epoch) <$> o.to
, y : Tuple.snd <$> parsePos <$> o.pos
}
parse _ = Nothing
-----------------------------------------------------------
newtype Group = Group
{ bId :: Int
{ bId :: Maybe Int
, foundation :: Array Int -- @NOTE #219: Array String ???
, from :: Date.Date
, from :: Maybe Date.Date
, gId :: Int
, label :: Array String
, role :: Array Int
, size :: Int
, size :: Maybe Int
, source :: Array String
, to :: Date.Date
, weight :: Number
, x :: Number
, y :: Number
, to :: Maybe Date.Date
, weight :: Maybe Number
, x :: Maybe Number
, y :: Maybe Number
}
derive instance Generic Group _
......@@ -209,18 +209,18 @@ parseGroups epoch
where
parse :: RawObject -> Maybe Group
parse (GroupToNode o) = Just $ Group
{ bId : parseInt o.bId
, foundation : stringedArrayToArray' o.foundation
, from : parseNodeDate o.strFrom o.from epoch
{ bId : parseInt <$> o.bId
, foundation : fromMaybe [] $ stringedArrayToArray' <$> o.foundation
, from : (\f -> parseNodeDate o.strFrom f epoch) <$> o.from
, gId : o._gvid
, label : stringedArrayToArray o.lbl
, role : stringedArrayToArray_ o.role
, size : parseInt o.support
, source : parseSources o.source
, to : parseNodeDate o.strTo o.to epoch
, weight : stringedMaybeToNumber o.weight
, x : Tuple.fst $ parsePos o.pos
, y : Tuple.snd $ parsePos o.pos
, label : fromMaybe [] $ stringedArrayToArray <$> o.lbl
, role : fromMaybe [] $ stringedArrayToArray_ <$>o.role
, size : parseInt <$> o.support
, source : fromMaybe [] $ parseSources <$> o.source
, to : (\to -> parseNodeDate o.strTo to epoch) <$> o.to
, weight : stringedMaybeToNumber <$> o.weight
, x : Tuple.fst <$> parsePos <$> o.pos
, y : Tuple.snd <$> parsePos <$> o.pos
}
parse _ = Nothing
......@@ -433,7 +433,7 @@ getGlobalWeightedValue
= Array.last
>>> case _ of
Nothing -> false
Just (Group o) -> o.weight > 0.0
Just (Group o) -> fromMaybe 0.0 o.weight > 0.0
stringedMaybeToNumber :: String -> Number
stringedMaybeToNumber "Nothing" = 0.0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment