module RelationHTML where
import RelationType
import Relation
import RelationTuple
import qualified Data.HashSet as HS
import qualified Data.List as L
import RelationAttribute
attributesAsHTML :: Attributes -> String
attributesAsHTML attrs = "
" ++ (foldr folder "" attrNameList) ++ "
"
where
folder attrName acc = acc ++ "" ++ attrName ++ " | "
attrNameList = sortedAttributeNameList (attributeNameSet attrs)
relationAsHTML :: Relation -> String
relationAsHTML rel@(Relation attrNameSet tupleSet) = "" ++ (attributesAsHTML attrNameSet) ++ (tupleSetAsHTML tupleSet) ++ "" ++ tablefooter ++ "
"
where
tablefooter = "| " ++ show (cardinality rel) ++ " tuples |
"
writeHTML :: String -> IO ()
writeHTML = writeFile "/home/agentm/rel.html"
writeRel :: Relation -> IO ()
writeRel = writeHTML . relationAsHTML
atomAsHTML :: Atom -> String
atomAsHTML (StringAtom s) = s
atomAsHTML (IntAtom i) = show i
atomAsHTML (RelationAtom rel) = relationAsHTML rel
tupleAsHTML :: RelationTuple -> String
tupleAsHTML tuple = "" ++ L.foldr folder "" (tupleSortedAssocs tuple) ++ "
"
where
folder tup acc = acc ++ "" ++ (atomAsHTML (snd tup)) ++ " | "
tupleSetAsHTML :: RelationTupleSet -> String
tupleSetAsHTML tupSet = HS.foldr folder "" tupSet
where
folder tuple acc = acc ++ tupleAsHTML tuple