Alt alternative leaderboard, fix wrong evaluation

This commit is contained in:
Filip Graliński 2019-12-16 16:39:20 +01:00
parent 34b34b1e90
commit 9267bf7f32
6 changed files with 60 additions and 14 deletions

View File

@ -217,7 +217,7 @@ checkOrInsertEvaluation repoDir chan version out = do
msg chan $ "Start evaluation..." msg chan $ "Start evaluation..."
challengeDir <- getRepoDir $ challengePrivateRepo challenge challengeDir <- getRepoDir $ challengePrivateRepo challenge
variant <- runDB $ get404 $ outVariant out variant <- runDB $ get404 $ outVariant out
resultOrException <- liftIO $ rawEval challengeDir (evaluationSchemeMetric $ testMetric test) repoDir (testName test) ((T.unpack $ variantName variant) <.> "tsv") resultOrException <- liftIO $ rawEval challengeDir (testMetric test) repoDir (testName test) ((T.unpack $ variantName variant) <.> "tsv")
case resultOrException of case resultOrException of
Right (Left _) -> do Right (Left _) -> do
err chan "Cannot parse options, check the challenge repo" err chan "Cannot parse options, check the challenge repo"
@ -240,7 +240,7 @@ checkOrInsertEvaluation repoDir chan version out = do
err chan $ "Evaluation failed: " ++ (T.pack $ show exception) err chan $ "Evaluation failed: " ++ (T.pack $ show exception)
rawEval :: FilePath rawEval :: FilePath
-> Metric -> EvaluationScheme
-> FilePath -> FilePath
-> Text -> Text
-> FilePath -> FilePath

View File

@ -83,7 +83,7 @@ submissionsToJSON :: ((Entity Submission) -> Bool) -> Text -> Handler Value
submissionsToJSON condition challengeName = do submissionsToJSON condition challengeName = do
(Entity challengeId _) <- runDB $ getBy404 $ UniqueName challengeName (Entity challengeId _) <- runDB $ getBy404 $ UniqueName challengeName
(entries, _) <- getLeaderboardEntriesByCriterion challengeId (entries, _) <- getLeaderboardEntriesByCriterion 1 challengeId
condition condition
(\entry -> [entityKey $ tableEntrySubmission entry]) (\entry -> [entityKey $ tableEntrySubmission entry])

View File

@ -81,7 +81,7 @@ getSampleLeaderboard :: Text -> HandlerFor App (WidgetFor App ())
getSampleLeaderboard name = do getSampleLeaderboard name = do
(Entity challengeId challenge) <- runDB $ getBy404 $ UniqueName name (Entity challengeId challenge) <- runDB $ getBy404 $ UniqueName name
(leaderboard, (_, tests)) <- getLeaderboardEntries BySubmitter challengeId (leaderboard, (_, tests)) <- getLeaderboardEntries 1 BySubmitter challengeId
let leaderboardWithRanks = zip [1..] (take 10 leaderboard) let leaderboardWithRanks = zip [1..] (take 10 leaderboard)
app <- getYesod app <- getYesod

View File

@ -61,7 +61,18 @@ getShowChallengeR name = do
challengeEnt@(Entity challengeId challenge) <- runDB $ getBy404 $ UniqueName name challengeEnt@(Entity challengeId challenge) <- runDB $ getBy404 $ UniqueName name
Just repo <- runDB $ get $ challengePublicRepo challenge Just repo <- runDB $ get $ challengePublicRepo challenge
(leaderboard, (entries, tests)) <- getLeaderboardEntries leaderboardStyle challengeId (leaderboard, (entries, tests)) <- getLeaderboardEntries 1 leaderboardStyle challengeId
showAltLeaderboard <- runDB $ hasMetricsOfSecondPriority challengeId
(altLeaderboard, altTests) <- if showAltLeaderboard
then
do
(leaderboard', (_, tests')) <- getLeaderboardEntries 2 ByTag challengeId
return $ (Just leaderboard', Just tests')
else
return (Nothing, Nothing)
mauth <- maybeAuth mauth <- maybeAuth
let params = getNumericalParams entries let params = getNumericalParams entries
@ -76,8 +87,16 @@ getShowChallengeR name = do
challengeRepo challengeRepo
repo repo
leaderboard leaderboard
altLeaderboard
params params
tests) tests
altTests)
hasMetricsOfSecondPriority challengeId = do
tests' <- selectList [TestChallenge ==. challengeId, TestActive ==. True] []
let tests = filter (\t -> (evaluationSchemePriority $ testMetric $ entityVal t) == 2) tests'
return $ not (null tests)
getChallengeReadmeR :: Text -> Handler Html getChallengeReadmeR :: Text -> Handler Html
getChallengeReadmeR name = do getChallengeReadmeR name = do
@ -100,8 +119,10 @@ showChallengeWidget :: Maybe (Entity User)
-> Repo -> Repo
-> Repo -> Repo
-> [LeaderboardEntry] -> [LeaderboardEntry]
-> (Maybe [LeaderboardEntry])
-> [Text] -> [Text]
-> [Entity Test] -> [Entity Test]
-> (Maybe [Entity Test])
-> WidgetFor App () -> WidgetFor App ()
showChallengeWidget mUserEnt showChallengeWidget mUserEnt
(Entity challengeId challenge) (Entity challengeId challenge)
@ -109,10 +130,13 @@ showChallengeWidget mUserEnt
challengeRepo challengeRepo
repo repo
leaderboard leaderboard
mAltLeaderboard
params params
tests tests
mAltTests
= $(widgetFile "show-challenge") = $(widgetFile "show-challenge")
where leaderboardWithRanks = zip [1..] leaderboard where leaderboardWithRanks = zip [1..] leaderboard
mAltLeaderboardWithRanks = zip [1..] <$> mAltLeaderboard
maybeRepoLink = getRepoLink repo maybeRepoLink = getRepoLink repo
delta = Number 4 delta = Number 4
higherTheBetterArray = getIsHigherTheBetterArray $ map entityVal tests higherTheBetterArray = getIsHigherTheBetterArray $ map entityVal tests

View File

@ -132,6 +132,19 @@ leaderboardTable mauthId challengeName repoScheme challengeRepo tests = mempty
leaderboardUserId e, leaderboardUserId e,
mauthId)) mauthId))
altLeaderboardTable :: Maybe UserId -> Text -> RepoScheme -> Repo -> [Entity Test] -> Table App (Int, LeaderboardEntry)
altLeaderboardTable mauthId challengeName repoScheme challengeRepo tests = mempty
++ Table.int "#" fst
++ leaderboardDescriptionCell mauthId
++ mconcat (map (\e@(Entity _ t) -> resultCell t (extractScoreFromLeaderboardEntry (getTestReference e) . snd)) tests)
++ statusCell challengeName repoScheme challengeRepo (\(_, e) -> (leaderboardBestSubmissionId e,
leaderboardBestSubmission e,
leaderboardBestVariantId e,
leaderboardBestVariant e,
leaderboardUserId e,
mauthId))
extractScoreFromLeaderboardEntry :: TestReference -> LeaderboardEntry -> Maybe Evaluation extractScoreFromLeaderboardEntry :: TestReference -> LeaderboardEntry -> Maybe Evaluation
extractScoreFromLeaderboardEntry k entry = lookup k (leaderboardEvaluationMap entry) extractScoreFromLeaderboardEntry k entry = lookup k (leaderboardEvaluationMap entry)
@ -219,12 +232,13 @@ compareVersions (aM, aN, aP) (bM, bN, bP) = (aM `compare` bM)
<> (aN `compare` bN) <> (aN `compare` bN)
<> (aP `compare` bP) <> (aP `compare` bP)
getLeaderboardEntriesByCriterion :: (Ord a) => Key Challenge getLeaderboardEntriesByCriterion :: (Ord a) => Int
-> Key Challenge
-> ((Entity Submission) -> Bool) -> ((Entity Submission) -> Bool)
-> (TableEntry -> [a]) -> (TableEntry -> [a])
-> Handler ([LeaderboardEntry], ([TableEntry], [Entity Test])) -> Handler ([LeaderboardEntry], ([TableEntry], [Entity Test]))
getLeaderboardEntriesByCriterion challengeId condition selector = do getLeaderboardEntriesByCriterion maxPriority challengeId condition selector = do
(evaluationMaps, tests) <- runDB $ getChallengeSubmissionInfos 1 condition (const True) challengeId (evaluationMaps, tests) <- runDB $ getChallengeSubmissionInfos maxPriority condition (const True) challengeId
let mainTests = getMainTests tests let mainTests = getMainTests tests
let mainTestEnt = getMainTest tests let mainTestEnt = getMainTest tests
let mainTestRef = getTestReference mainTestEnt let mainTestRef = getTestReference mainTestEnt
@ -293,13 +307,15 @@ toLeaderboardEntry challengeId tests ss = do
<> <>
(compareVersions v1 v2) (compareVersions v1 v2)
getLeaderboardEntries :: LeaderboardStyle -> Key Challenge -> Handler ([LeaderboardEntry], ([TableEntry], [Entity Test])) getLeaderboardEntries :: Int -> LeaderboardStyle -> Key Challenge -> Handler ([LeaderboardEntry], ([TableEntry], [Entity Test]))
getLeaderboardEntries BySubmitter challengeId = getLeaderboardEntries maxPriority BySubmitter challengeId =
getLeaderboardEntriesByCriterion challengeId getLeaderboardEntriesByCriterion maxPriority
challengeId
(const True) (const True)
(\entry -> [entityKey $ tableEntrySubmitter entry]) (\entry -> [entityKey $ tableEntrySubmitter entry])
getLeaderboardEntries ByTag challengeId = getLeaderboardEntries maxPriority ByTag challengeId =
getLeaderboardEntriesByCriterion challengeId getLeaderboardEntriesByCriterion maxPriority
challengeId
(const True) (const True)
(noEmptyList . (map (entityKey . fst)) . tableEntryTagsInfo) (noEmptyList . (map (entityKey . fst)) . tableEntryTagsInfo)
where noEmptyList [] = [Nothing] where noEmptyList [] = [Nothing]

View File

@ -21,6 +21,12 @@ $if (checkIfAdmin mUserEnt)
^{Table.buildBootstrap (leaderboardTable mUserId (challengeName challenge) scheme challengeRepo tests) leaderboardWithRanks} ^{Table.buildBootstrap (leaderboardTable mUserId (challengeName challenge) scheme challengeRepo tests) leaderboardWithRanks}
$maybe altLeaderboardWithRanks <- mAltLeaderboardWithRanks
$maybe altTests <- mAltTests
^{Table.buildBootstrap (altLeaderboardTable mUserId (challengeName challenge) scheme challengeRepo altTests) altLeaderboardWithRanks}
$nothing
$nothing
<div id="graph-container"> <div id="graph-container">
<script src="/static/js/sigma.min.js"> <script src="/static/js/sigma.min.js">