forked from filipg/gonito
show tags at leaderboard
This commit is contained in:
parent
4918015dbd
commit
25b1b2e801
@ -5,6 +5,7 @@ module Handler.Tables where
|
|||||||
import Import
|
import Import
|
||||||
import Handler.Shared
|
import Handler.Shared
|
||||||
import Handler.SubmissionView
|
import Handler.SubmissionView
|
||||||
|
import Handler.TagUtils
|
||||||
|
|
||||||
import qualified Yesod.Table as Table
|
import qualified Yesod.Table as Table
|
||||||
import Yesod.Table (Table)
|
import Yesod.Table (Table)
|
||||||
@ -27,7 +28,8 @@ data LeaderboardEntry = LeaderboardEntry {
|
|||||||
leaderboardBestSubmission :: Submission,
|
leaderboardBestSubmission :: Submission,
|
||||||
leaderboardBestSubmissionId :: SubmissionId,
|
leaderboardBestSubmissionId :: SubmissionId,
|
||||||
leaderboardEvaluation :: Evaluation,
|
leaderboardEvaluation :: Evaluation,
|
||||||
leaderboardNumberOfSubmissions :: Int
|
leaderboardNumberOfSubmissions :: Int,
|
||||||
|
leaderboardTags :: [Entity Tag]
|
||||||
}
|
}
|
||||||
|
|
||||||
submissionsTable :: Maybe UserId -> Text -> [Entity Test] -> Table App (Entity Submission, Entity User, Map (Key Test) Evaluation, [Entity Tag])
|
submissionsTable :: Maybe UserId -> Text -> [Entity Test] -> Table App (Entity Submission, Entity User, Map (Key Test) Evaluation, [Entity Tag])
|
||||||
@ -39,14 +41,7 @@ submissionsTable mauthId challengeName tests = mempty
|
|||||||
++ statusCell challengeName (\(Entity submissionId submission, Entity userId _, _, _) -> (submissionId, submission, userId, mauthId))
|
++ statusCell challengeName (\(Entity submissionId submission, Entity userId _, _, _) -> (submissionId, submission, userId, mauthId))
|
||||||
|
|
||||||
descriptionCell = Table.widget "description" (
|
descriptionCell = Table.widget "description" (
|
||||||
\(Entity _ s, _, _ ,tagEnts) -> [whamlet|
|
\(Entity _ s, _, _ ,tagEnts) -> fragmentWithTags (submissionDescription s) tagEnts)
|
||||||
#{submissionDescription s}
|
|
||||||
|
|
||||||
$forall (Entity _ v) <- tagEnts
|
|
||||||
\ <span class="label label-primary">#{tagName v}</span>
|
|
||||||
|])
|
|
||||||
|
|
||||||
-- Table.text "description" (submissionDescription . (\(Entity _ s, _, _, _) -> s))
|
|
||||||
|
|
||||||
extractScore :: Key Test -> (Entity Submission, Entity User, Map (Key Test) Evaluation, [Entity Tag]) -> Maybe Evaluation
|
extractScore :: Key Test -> (Entity Submission, Entity User, Map (Key Test) Evaluation, [Entity Tag]) -> Maybe Evaluation
|
||||||
extractScore k (_, _, m, _) = lookup k m
|
extractScore k (_, _, m, _) = lookup k m
|
||||||
@ -56,7 +51,7 @@ leaderboardTable mauthId challengeName test = mempty
|
|||||||
++ Table.int "#" fst
|
++ Table.int "#" fst
|
||||||
++ Table.text "submitter" (formatSubmitter . leaderboardUser . snd)
|
++ Table.text "submitter" (formatSubmitter . leaderboardUser . snd)
|
||||||
++ timestampCell "when" (submissionStamp . leaderboardBestSubmission . snd)
|
++ timestampCell "when" (submissionStamp . leaderboardBestSubmission . snd)
|
||||||
++ Table.text "description" (submissionDescription . leaderboardBestSubmission . snd)
|
++ leaderboardDescriptionCell
|
||||||
++ resultCell test ((\e -> Just e) . leaderboardEvaluation . snd)
|
++ resultCell test ((\e -> Just e) . leaderboardEvaluation . snd)
|
||||||
++ Table.int "×" (leaderboardNumberOfSubmissions . snd)
|
++ Table.int "×" (leaderboardNumberOfSubmissions . snd)
|
||||||
++ statusCell challengeName (\(_, e) -> (leaderboardBestSubmissionId e,
|
++ statusCell challengeName (\(_, e) -> (leaderboardBestSubmissionId e,
|
||||||
@ -64,6 +59,10 @@ leaderboardTable mauthId challengeName test = mempty
|
|||||||
leaderboardUserId e,
|
leaderboardUserId e,
|
||||||
mauthId))
|
mauthId))
|
||||||
|
|
||||||
|
leaderboardDescriptionCell = Table.widget "description" (
|
||||||
|
\(_,entry) -> fragmentWithTags (submissionDescription $ leaderboardBestSubmission entry) (leaderboardTags entry))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
hoverTextCell :: Text -> (a -> Text) -> (a -> Text) -> Table site a
|
hoverTextCell :: Text -> (a -> Text) -> (a -> Text) -> Table site a
|
||||||
hoverTextCell h mainTextFun hoverTextFun = Table.widget h (
|
hoverTextCell h mainTextFun hoverTextFun = Table.widget h (
|
||||||
@ -130,19 +129,25 @@ getLeaderboardEntries challengeId = do
|
|||||||
let auxSubmissions = getAuxSubmissionEnts mainTestId evaluationMaps
|
let auxSubmissions = getAuxSubmissionEnts mainTestId evaluationMaps
|
||||||
let submissionsByUser = Map.fromListWith (\(u1, l1) (_, l2) -> (u1, l1++l2)) auxSubmissions
|
let submissionsByUser = Map.fromListWith (\(u1, l1) (_, l2) -> (u1, l1++l2)) auxSubmissions
|
||||||
let entryComparator a b = (compareResult mainTest) (evaluationScore $ leaderboardEvaluation a) (evaluationScore $ leaderboardEvaluation b)
|
let entryComparator a b = (compareResult mainTest) (evaluationScore $ leaderboardEvaluation a) (evaluationScore $ leaderboardEvaluation b)
|
||||||
let entries = sortBy (flip entryComparator) $ map (toEntry mainTest) $ filter (\(_, (_, s)) -> not (null s)) $ Map.toList submissionsByUser
|
entries' <- mapM (toEntry mainTest) $ filter (\(_, (_, s)) -> not (null s)) $ Map.toList submissionsByUser
|
||||||
|
let entries = sortBy (flip entryComparator) entries'
|
||||||
return (mainTest, entries)
|
return (mainTest, entries)
|
||||||
where submissionComparator mainTest (_, e1) (_, e2) = (compareResult mainTest) (evaluationScore e1) (evaluationScore e2)
|
|
||||||
toEntry mainTest (ui, (u, ss)) = LeaderboardEntry {
|
|
||||||
|
toEntry mainTest (ui, (u, ss)) = do
|
||||||
|
let bestOne = DL.maximumBy (submissionComparator mainTest) ss
|
||||||
|
let submissionId = entityKey $ fst bestOne
|
||||||
|
tagEnts <- runDB $ getTags submissionId
|
||||||
|
return $ LeaderboardEntry {
|
||||||
leaderboardUser = u,
|
leaderboardUser = u,
|
||||||
leaderboardUserId = ui,
|
leaderboardUserId = ui,
|
||||||
leaderboardBestSubmission = (\(Entity _ s) -> s) $ fst bestOne,
|
leaderboardBestSubmission = (\(Entity _ s) -> s) $ fst bestOne,
|
||||||
leaderboardBestSubmissionId = (\(Entity si _) -> si) $ fst bestOne,
|
leaderboardBestSubmissionId = (\(Entity si _) -> si) $ fst bestOne,
|
||||||
leaderboardEvaluation = snd bestOne,
|
leaderboardEvaluation = snd bestOne,
|
||||||
leaderboardNumberOfSubmissions = length ss
|
leaderboardNumberOfSubmissions = length ss,
|
||||||
|
leaderboardTags = tagEnts
|
||||||
}
|
}
|
||||||
where bestOne = DL.maximumBy (submissionComparator mainTest) ss
|
where submissionComparator mainTest (_, e1) (_, e2) = (compareResult mainTest) (evaluationScore e1) (evaluationScore e2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
compareResult :: Test -> Maybe Double -> Maybe Double -> Ordering
|
compareResult :: Test -> Maybe Double -> Maybe Double -> Ordering
|
||||||
|
@ -20,3 +20,10 @@ tagsAsTextToTagIds mTagsAsText = do
|
|||||||
Nothing -> []
|
Nothing -> []
|
||||||
mTs <- mapM (\t -> getBy $ UniqueTagName t) newTags
|
mTs <- mapM (\t -> getBy $ UniqueTagName t) newTags
|
||||||
return $ Import.map entityKey $ Import.catMaybes mTs
|
return $ Import.map entityKey $ Import.catMaybes mTs
|
||||||
|
|
||||||
|
fragmentWithTags t tagEnts = [whamlet|
|
||||||
|
#{t}
|
||||||
|
|
||||||
|
$forall (Entity _ v) <- tagEnts
|
||||||
|
\ <span class="label label-primary">#{tagName v}</span>
|
||||||
|
|]
|
||||||
|
Loading…
Reference in New Issue
Block a user