finished
This commit is contained in:
parent
c08ef8b714
commit
b9579046ba
4 changed files with 26 additions and 16 deletions
|
@ -9,7 +9,8 @@ module Algorithm.BaseQuery
|
|||
CardFace(..),
|
||||
ImageUris(..),
|
||||
isLegal,
|
||||
notSuperType
|
||||
notSuperType,
|
||||
color
|
||||
) where
|
||||
import qualified Data.Text as T
|
||||
import Database.SQLite.Simple
|
||||
|
@ -192,4 +193,5 @@ isLegal qry = do
|
|||
cards <- fetchCardsWithIds res
|
||||
return $ Holder cards
|
||||
|
||||
color :: String -> IO Tree
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ data QueryDef =
|
|||
CMCLT Int |
|
||||
CMCMT Int |
|
||||
CMCEQ Int |
|
||||
IsLegal String
|
||||
IsLegal String
|
||||
deriving Show
|
||||
data Operator =
|
||||
Union |
|
||||
|
@ -105,7 +105,7 @@ seperator ("(":rest) ((start,end):points) = case drop (end-start) rest of
|
|||
a -> Left $ ParseError $ "Could not parse input, error happened at: " ++ (show (concat a))
|
||||
seperator [name, " ", value, ")"] _ = case extractQueryDef (name, value) of
|
||||
Left a -> Left a
|
||||
Right b -> Right $ Queri $ b
|
||||
Right b -> Right $ b
|
||||
seperator a _ = Left (ParseError ("Something went wrong tokenizing the input!\n" ++ (show a)))
|
||||
|
||||
spawnBranch :: Operator -> (Either ParseError Token) -> (Either ParseError Token) -> (Either ParseError Token)
|
||||
|
@ -116,19 +116,26 @@ spawnBranch operator (Right res1) (Right res2) = Right (Func operator res1 res2)
|
|||
|
||||
|
||||
|
||||
extractQueryDef :: (String, String) -> Either ParseError QueryDef
|
||||
extractQueryDef ("SuperType", value) = Right $ SuperType value
|
||||
extractQueryDef ("NotSuperType", value) = Right $ NotSuperType value
|
||||
extractQueryDef :: (String, String) -> Either ParseError Token
|
||||
extractQueryDef ("SuperType", value) = Right $ Queri $ SuperType value
|
||||
extractQueryDef ("NotSuperType", value) = Right $ Queri $ NotSuperType value
|
||||
extractQueryDef ("CmcLT", value) = case readMaybe value :: Maybe Int of
|
||||
Just a -> Right $ CMCLT a
|
||||
Just a -> Right $ Queri $ CMCLT a
|
||||
Nothing -> Left $ ParseError "Could not parse number from call to CmcLT"
|
||||
extractQueryDef ("CmcMT", value) = case readMaybe value :: Maybe Int of
|
||||
Just a -> Right $ CMCMT a
|
||||
Just a -> Right $ Queri $ CMCMT a
|
||||
Nothing -> Left $ ParseError "Could not parse number from call to CmcMT"
|
||||
extractQueryDef ("CmcEQ", value) = case readMaybe value :: Maybe Int of
|
||||
Just a -> Right $ CMCEQ a
|
||||
Just a -> Right $ Queri $ CMCEQ a
|
||||
Nothing -> Left $ ParseError "Could not parse number from call to CmcEQ"
|
||||
extractQueryDef ("IsLegal", value) = Right $ IsLegal value
|
||||
extractQueryDef ("CmcLTEQ", value) = case readMaybe value :: Maybe Int of
|
||||
Just a -> Right $ Func Union (Queri $ CMCLT a) (Queri $ CMCEQ a)
|
||||
Nothing -> Left $ ParseError "Could not parse number from call to CmcLTEQ"
|
||||
extractQueryDef ("CmcMTEQ", value) = case readMaybe value :: Maybe Int of
|
||||
Just a -> Right $ Func Union (Queri $ CMCMT a) (Queri $ CMCEQ a)
|
||||
Nothing -> Left $ ParseError "Could not parse number from call to CmcLTEQ"
|
||||
extractQueryDef ("Color", value) = Right $ Queri $ Color value
|
||||
extractQueryDef ("IsLegal", value) = Right $ Queri $ IsLegal value
|
||||
extractQueryDef (a,b) = Left $ ParseError $ "The following command is invalid " ++ show a
|
||||
|
||||
extractOperator "union" = Union
|
||||
|
|
|
@ -7,9 +7,9 @@ module Algorithm.Operator
|
|||
|
||||
|
||||
union :: Eq a => [a] -> [a] -> [a]
|
||||
union (a:as) bs | a `elem` bs = union as bs
|
||||
union (a:as) bs = a : union as bs
|
||||
union [] _ = []
|
||||
union (a:as) bs | a `notElem` bs =a : union as bs
|
||||
union (a:as) bs = union as bs
|
||||
union [] bs = bs
|
||||
|
||||
intersect :: Eq a => [a] -> [a] -> [a]
|
||||
intersect (a:as) b = if a `elem` b then a: intersect as b else intersect as b
|
||||
|
|
|
@ -26,7 +26,7 @@ search q = do
|
|||
tree <- executeBottomQuery tokens
|
||||
let queryRes = executeQuery tree
|
||||
let hyperText = buildHtml queryRes
|
||||
return hyperText
|
||||
return $ "<div style=\"display:flex;flex-wrap:wrap;\">" ++ hyperText ++ "</div>"
|
||||
--In order to avoid IO when performing the operators, we fetch all the "bottom" queries first, then perform
|
||||
--the operators on them based on the Tree
|
||||
|
||||
|
@ -53,6 +53,7 @@ executeBottomQuery (Queri (CMCLT value)) = cmcLT value
|
|||
executeBottomQuery (Queri (CMCMT value)) = cmcMT value
|
||||
executeBottomQuery (Queri (CMCEQ value)) = cmcEQ value
|
||||
executeBottomQuery (Queri (IsLegal value)) | map toLower value `elem` formats = isLegal $ map toLower value
|
||||
executeBottomQuery (Queri (Color value)) = color value
|
||||
executeBottomQuery (Queri _) = error $ "Not implemented yet"
|
||||
executeBottomQuery (Func operator left right) = do
|
||||
left <- executeBottomQuery left
|
||||
|
@ -65,11 +66,11 @@ cardToHtml :: Card -> String
|
|||
cardToHtml (Card _ _ _ _ _ _ _ _ [cardFace]) = singleCardFaceHTML cardFace
|
||||
|
||||
--Multiface card!
|
||||
cardToHtml (Card _ _ _ _ _ _ _ _ cardFaces) = "<div style=\"text-align:center;\"><div style=\"display: inline-flex\">" ++ concatMap singleCardFaceHTML cardFaces ++"</div></div>"
|
||||
cardToHtml (Card _ _ _ _ _ _ _ _ cardFaces) = "<div style=\"text-align:center;margin:10px;\"><div style=\"display: inline-flex\">" ++ concatMap singleCardFaceHTML cardFaces ++"</div></div>"
|
||||
|
||||
singleCardFaceHTML :: CardFace -> String
|
||||
singleCardFaceHTML (CardFace _ _ name _ oracle_text type_line mana_cost (ImageUris _ _ _ image _ _ _ _)) =
|
||||
"<div style=\"text-align:center;\">" ++
|
||||
"<div style=\"text-align:center;margin:10px;\">" ++
|
||||
"<h2>" ++ unpack name ++ "</h2>" ++
|
||||
"<img src=" ++ unpack image ++ " width=\"200px\"/>"++
|
||||
"<p style=\"width:205px;margin: 5 auto;font-size:16;\">" ++ unpack (Data.Maybe.fromMaybe "" type_line) ++ "</p>"++
|
||||
|
|
Loading…
Reference in a new issue