Show result tables
This commit is contained in:
parent
6b87181454
commit
0e8846b06c
@ -9,6 +9,7 @@ import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3, bfs)
|
|||||||
|
|
||||||
import Handler.TagUtils
|
import Handler.TagUtils
|
||||||
import Handler.MakePublic
|
import Handler.MakePublic
|
||||||
|
import Handler.Query
|
||||||
|
|
||||||
import Gonito.ExtractMetadata (parseTags)
|
import Gonito.ExtractMetadata (parseTags)
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ getChallengeParamGraphDataR challengeName testId paramName = do
|
|||||||
(Entity challengeId _) <- runDB $ getBy404 $ UniqueName challengeName
|
(Entity challengeId _) <- runDB $ getBy404 $ UniqueName challengeName
|
||||||
test <- runDB $ get404 testId
|
test <- runDB $ get404 testId
|
||||||
|
|
||||||
(entries, _) <- getChallengeSubmissionInfos (const True) challengeId
|
(entries, _) <- runDB $ getChallengeSubmissionInfos (const True) challengeId
|
||||||
|
|
||||||
let values = map (findParamValue paramName) entries
|
let values = map (findParamValue paramName) entries
|
||||||
|
|
||||||
@ -154,7 +154,7 @@ getIndicatorGraphDataR indicatorId = do
|
|||||||
test <- runDB $ get404 testId
|
test <- runDB $ get404 testId
|
||||||
let mPrecision = testPrecision test
|
let mPrecision = testPrecision test
|
||||||
|
|
||||||
(entries, _) <- getChallengeSubmissionInfos (const True) (testChallenge test)
|
(entries, _) <- runDB $ getChallengeSubmissionInfos (const True) (testChallenge test)
|
||||||
|
|
||||||
theNow <- liftIO $ getCurrentTime -- needed to draw the "now" vertical line
|
theNow <- liftIO $ getCurrentTime -- needed to draw the "now" vertical line
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ getPresentation4RealR = do
|
|||||||
|
|
||||||
(Just (Entity sampleUserId _)) <- runDB $ getBy $ UniqueUser sampleUserIdent
|
(Just (Entity sampleUserId _)) <- runDB $ getBy $ UniqueUser sampleUserIdent
|
||||||
let condition = (\(Entity _ submission) -> (submissionSubmitter submission == sampleUserId))
|
let condition = (\(Entity _ submission) -> (submissionSubmitter submission == sampleUserId))
|
||||||
(evaluationMaps', tests) <- getChallengeSubmissionInfos condition challengeId
|
(evaluationMaps', tests) <- runDB $ getChallengeSubmissionInfos condition challengeId
|
||||||
let evaluationMaps = take 10 evaluationMaps'
|
let evaluationMaps = take 10 evaluationMaps'
|
||||||
|
|
||||||
sampleLeaderboard <- getSampleLeaderboard sampleChallengeName
|
sampleLeaderboard <- getSampleLeaderboard sampleChallengeName
|
||||||
|
@ -5,12 +5,22 @@ import Import
|
|||||||
import Handler.SubmissionView
|
import Handler.SubmissionView
|
||||||
import Handler.Shared
|
import Handler.Shared
|
||||||
import Handler.TagUtils
|
import Handler.TagUtils
|
||||||
|
import PersistSHA1
|
||||||
|
|
||||||
|
import Handler.Tables
|
||||||
|
|
||||||
|
import qualified Yesod.Table as Table
|
||||||
|
import Yesod.Table (Table)
|
||||||
|
|
||||||
import Database.Persist.Sql
|
import Database.Persist.Sql
|
||||||
|
|
||||||
import qualified Database.Esqueleto as E
|
import qualified Database.Esqueleto as E
|
||||||
import Database.Esqueleto ((^.))
|
import Database.Esqueleto ((^.))
|
||||||
|
|
||||||
|
import qualified Data.Text as T
|
||||||
|
|
||||||
|
import Data.List (nub)
|
||||||
|
|
||||||
import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3)
|
import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3)
|
||||||
|
|
||||||
rawCommitQuery :: (MonadIO m, RawSql a) => Text -> ReaderT SqlBackend m [a]
|
rawCommitQuery :: (MonadIO m, RawSql a) => Text -> ReaderT SqlBackend m [a]
|
||||||
@ -83,5 +93,32 @@ processQuery query = do
|
|||||||
setTitle "query results"
|
setTitle "query results"
|
||||||
$(widgetFile "query-results")
|
$(widgetFile "query-results")
|
||||||
|
|
||||||
|
resultTable :: Entity Submission -> WidgetFor App ()
|
||||||
|
resultTable (Entity submissionId submission) = do
|
||||||
|
(tableEntries, tests) <- handlerToWidget $ runDB $ getChallengeSubmissionInfos (\s -> entityKey s == submissionId)
|
||||||
|
(submissionChallenge submission)
|
||||||
|
let paramNames =
|
||||||
|
nub
|
||||||
|
$ map (parameterName . entityVal)
|
||||||
|
$ concat
|
||||||
|
$ map tableEntryParams tableEntries
|
||||||
|
|
||||||
|
let resultId = show $ fromSqlKey submissionId
|
||||||
|
let jsSelector = String $ T.pack ("#t" ++ resultId ++ " > table")
|
||||||
|
|
||||||
|
let delta = Number $ fromIntegral ((length paramNames) + 1)
|
||||||
|
let higherTheBetterArray = getIsHigherTheBetterArray $ map entityVal tests
|
||||||
|
|
||||||
|
$(widgetFile "result-table")
|
||||||
|
|
||||||
|
queryResult submission = do
|
||||||
|
$(widgetFile "query-result")
|
||||||
|
where commitSha1AsText = fromSHA1ToText $ submissionCommit $ fsiSubmission submission
|
||||||
|
submitter = formatSubmitter $ fsiUser submission
|
||||||
|
publicSubmissionBranch = getPublicSubmissionBranch $ fsiSubmissionId submission
|
||||||
|
publicSubmissionRepo = getReadOnlySubmissionUrl (fsiScheme submission) (fsiChallengeRepo submission) $ challengeName $ fsiChallenge submission
|
||||||
|
browsableUrl = browsableGitRepoBranch (fsiScheme submission) (fsiChallengeRepo submission) (challengeName $ fsiChallenge submission) publicSubmissionBranch
|
||||||
|
stamp = T.pack $ show $ submissionStamp $ fsiSubmission submission
|
||||||
|
|
||||||
queryForm :: Form Text
|
queryForm :: Form Text
|
||||||
queryForm = renderBootstrap3 BootstrapBasicForm $ areq textField (fieldSettingsLabel MsgGitCommitSha1) Nothing
|
queryForm = renderBootstrap3 BootstrapBasicForm $ areq textField (fieldSettingsLabel MsgGitCommitSha1) Nothing
|
||||||
|
@ -494,7 +494,7 @@ getChallengeAllSubmissionsR name = getChallengeSubmissions (\_ -> True) name
|
|||||||
getChallengeSubmissions :: ((Entity Submission) -> Bool) -> Text -> Handler Html
|
getChallengeSubmissions :: ((Entity Submission) -> Bool) -> Text -> Handler Html
|
||||||
getChallengeSubmissions condition name = do
|
getChallengeSubmissions condition name = do
|
||||||
Entity challengeId challenge <- runDB $ getBy404 $ UniqueName name
|
Entity challengeId challenge <- runDB $ getBy404 $ UniqueName name
|
||||||
(evaluationMaps, tests') <- getChallengeSubmissionInfos condition challengeId
|
(evaluationMaps, tests') <- runDB $ getChallengeSubmissionInfos condition challengeId
|
||||||
let tests = sortBy testComparator tests'
|
let tests = sortBy testComparator tests'
|
||||||
mauth <- maybeAuth
|
mauth <- maybeAuth
|
||||||
let muserId = (\(Entity uid _) -> uid) <$> mauth
|
let muserId = (\(Entity uid _) -> uid) <$> mauth
|
||||||
|
@ -7,6 +7,9 @@ import Handler.TagUtils
|
|||||||
|
|
||||||
import Data.Text as T(pack)
|
import Data.Text as T(pack)
|
||||||
|
|
||||||
|
import qualified Yesod.Table as Table
|
||||||
|
import Yesod.Table (Table)
|
||||||
|
|
||||||
data FullSubmissionInfo = FullSubmissionInfo {
|
data FullSubmissionInfo = FullSubmissionInfo {
|
||||||
fsiSubmissionId :: SubmissionId,
|
fsiSubmissionId :: SubmissionId,
|
||||||
fsiSubmission :: Submission,
|
fsiSubmission :: Submission,
|
||||||
@ -39,16 +42,6 @@ getFullInfo (Entity submissionId submission) = do
|
|||||||
fsiScheme = scheme,
|
fsiScheme = scheme,
|
||||||
fsiTags = tags }
|
fsiTags = tags }
|
||||||
|
|
||||||
|
|
||||||
queryResult submission = do
|
|
||||||
$(widgetFile "query-result")
|
|
||||||
where commitSha1AsText = fromSHA1ToText $ submissionCommit $ fsiSubmission submission
|
|
||||||
submitter = formatSubmitter $ fsiUser submission
|
|
||||||
publicSubmissionBranch = getPublicSubmissionBranch $ fsiSubmissionId submission
|
|
||||||
publicSubmissionRepo = getReadOnlySubmissionUrl (fsiScheme submission) (fsiChallengeRepo submission) $ challengeName $ fsiChallenge submission
|
|
||||||
browsableUrl = browsableGitRepoBranch (fsiScheme submission) (fsiChallengeRepo submission) (challengeName $ fsiChallenge submission) publicSubmissionBranch
|
|
||||||
stamp = T.pack $ show $ submissionStamp $ fsiSubmission submission
|
|
||||||
|
|
||||||
getTags submissionId = do
|
getTags submissionId = do
|
||||||
sts <- selectList [SubmissionTagSubmission ==. submissionId] []
|
sts <- selectList [SubmissionTagSubmission ==. submissionId] []
|
||||||
let tagIds = Import.map (submissionTagTag . entityVal) sts
|
let tagIds = Import.map (submissionTagTag . entityVal) sts
|
||||||
|
@ -64,6 +64,21 @@ submissionsTable mauthId challengeName repoScheme challengeRepo tests = mempty
|
|||||||
entityKey $ tableEntrySubmitter tableEntry,
|
entityKey $ tableEntrySubmitter tableEntry,
|
||||||
mauthId))
|
mauthId))
|
||||||
|
|
||||||
|
paramTable :: [Text] -> [Entity Test] -> Table App TableEntry
|
||||||
|
paramTable paramNames tests = mempty
|
||||||
|
++ Table.int "#" tableEntryRank
|
||||||
|
++ mconcat (map paramExtractor paramNames)
|
||||||
|
++ mconcat (map (\(Entity k t) -> resultCell t (extractScore k)) tests)
|
||||||
|
|
||||||
|
paramExtractor :: Text -> Table App TableEntry
|
||||||
|
paramExtractor paramName = Table.text paramName (\entry ->
|
||||||
|
fromMaybe ""
|
||||||
|
$ listToMaybe
|
||||||
|
$ map parameterValue
|
||||||
|
$ filter (\p -> parameterName p == paramName)
|
||||||
|
$ map entityVal
|
||||||
|
$ tableEntryParams entry)
|
||||||
|
|
||||||
descriptionCell :: Maybe UserId -> Table App TableEntry
|
descriptionCell :: Maybe UserId -> Table App TableEntry
|
||||||
descriptionCell mauthId = Table.widget "description" (
|
descriptionCell mauthId = Table.widget "description" (
|
||||||
\(TableEntry (Entity _ s) (Entity _ v) (Entity u _) _ tagEnts paramEnts _) -> fragmentWithSubmissionTags
|
\(TableEntry (Entity _ s) (Entity _ v) (Entity u _) _ tagEnts paramEnts _) -> fragmentWithSubmissionTags
|
||||||
@ -166,7 +181,7 @@ getLeaderboardEntriesByCriterion :: (Ord a) => Key Challenge
|
|||||||
-> (TableEntry -> [a])
|
-> (TableEntry -> [a])
|
||||||
-> Handler ([LeaderboardEntry], ([TableEntry], [Entity Test]))
|
-> Handler ([LeaderboardEntry], ([TableEntry], [Entity Test]))
|
||||||
getLeaderboardEntriesByCriterion challengeId condition selector = do
|
getLeaderboardEntriesByCriterion challengeId condition selector = do
|
||||||
(evaluationMaps, tests) <- getChallengeSubmissionInfos condition challengeId
|
(evaluationMaps, tests) <- runDB $ getChallengeSubmissionInfos condition challengeId
|
||||||
let mainTests = getMainTests tests
|
let mainTests = getMainTests tests
|
||||||
let mainTestEnt = getMainTest tests
|
let mainTestEnt = getMainTest tests
|
||||||
let (Entity mainTestId mainTest) = mainTestEnt
|
let (Entity mainTestId mainTest) = mainTestEnt
|
||||||
@ -233,20 +248,17 @@ compareResult _ (Just _) Nothing = GT
|
|||||||
compareResult _ Nothing (Just _) = LT
|
compareResult _ Nothing (Just _) = LT
|
||||||
compareResult _ Nothing Nothing = EQ
|
compareResult _ Nothing Nothing = EQ
|
||||||
|
|
||||||
getChallengeSubmissionInfos :: ((Entity Submission) -> Bool)
|
|
||||||
-> Key Challenge
|
|
||||||
-> Handler ([TableEntry], [Entity Test])
|
|
||||||
getChallengeSubmissionInfos condition challengeId = do
|
getChallengeSubmissionInfos condition challengeId = do
|
||||||
tests <- runDB $ selectList [TestChallenge ==. challengeId, TestActive ==. True] []
|
tests <- selectList [TestChallenge ==. challengeId, TestActive ==. True] []
|
||||||
let mainTest = getMainTest tests
|
let mainTest = getMainTest tests
|
||||||
|
|
||||||
allSubmissionsVariants <- runDB $ E.select $ E.from $ \(submission, variant) -> do
|
allSubmissionsVariants <- E.select $ E.from $ \(submission, variant) -> do
|
||||||
E.where_ (submission ^. SubmissionChallenge E.==. E.val challengeId
|
E.where_ (submission ^. SubmissionChallenge E.==. E.val challengeId
|
||||||
E.&&. submission ^. SubmissionIsHidden E.!=. E.val (Just True)
|
E.&&. submission ^. SubmissionIsHidden E.!=. E.val (Just True)
|
||||||
E.&&. variant ^. VariantSubmission E.==. submission ^. SubmissionId)
|
E.&&. variant ^. VariantSubmission E.==. submission ^. SubmissionId)
|
||||||
return (submission, variant)
|
return (submission, variant)
|
||||||
|
|
||||||
scores <- runDB $ mapM (getScore (entityKey mainTest)) $ map (entityKey . snd) allSubmissionsVariants
|
scores <- mapM (getScore (entityKey mainTest)) $ map (entityKey . snd) allSubmissionsVariants
|
||||||
|
|
||||||
let allSubmissionsVariantsWithRanks =
|
let allSubmissionsVariantsWithRanks =
|
||||||
sortBy (\(r1, (s1, _)) (r2, (s2, _)) -> (submissionStamp (entityVal s2) `compare` submissionStamp (entityVal s1))
|
sortBy (\(r1, (s1, _)) (r2, (s2, _)) -> (submissionStamp (entityVal s2) `compare` submissionStamp (entityVal s1))
|
||||||
@ -272,15 +284,15 @@ getScore testId variantId = do
|
|||||||
(e:_) -> evaluationScore $ entityVal e
|
(e:_) -> evaluationScore $ entityVal e
|
||||||
[] -> Nothing
|
[] -> Nothing
|
||||||
|
|
||||||
getEvaluationMap :: (Int, (Entity Submission, Entity Variant)) -> Handler TableEntry
|
|
||||||
getEvaluationMap (rank, (s@(Entity submissionId submission), v@(Entity variantId _))) = do
|
getEvaluationMap (rank, (s@(Entity submissionId submission), v@(Entity variantId _))) = do
|
||||||
outs <- runDB $ selectList [OutVariant ==. variantId] []
|
outs <- selectList [OutVariant ==. variantId] []
|
||||||
user <- runDB $ get404 $ submissionSubmitter submission
|
user <- get404 $ submissionSubmitter submission
|
||||||
maybeEvaluations <- runDB $ mapM (\(Entity _ o) -> getBy $ UniqueEvaluationTestChecksum (outTest o) (outChecksum o)) outs
|
maybeEvaluations <- mapM (\(Entity _ o) -> getBy $ UniqueEvaluationTestChecksum (outTest o) (outChecksum o)) outs
|
||||||
let evaluations = catMaybes maybeEvaluations
|
let evaluations = catMaybes maybeEvaluations
|
||||||
let m = Map.fromList $ map (\(Entity _ e) -> (evaluationTest e, e)) evaluations
|
let m = Map.fromList $ map (\(Entity _ e) -> (evaluationTest e, e)) evaluations
|
||||||
tagEnts <- runDB $ getTags submissionId
|
tagEnts <- getTags submissionId
|
||||||
|
|
||||||
parameters <- runDB $ selectList [ParameterVariant ==. variantId] [Asc ParameterName]
|
parameters <- selectList [ParameterVariant ==. variantId] [Asc ParameterName]
|
||||||
|
|
||||||
return $ TableEntry s v (Entity (submissionSubmitter submission) user) m tagEnts parameters rank
|
return $ TableEntry s v (Entity (submissionSubmitter submission) user) m tagEnts parameters rank
|
||||||
|
@ -17,4 +17,7 @@
|
|||||||
<dd><a href="#{browsableUrl}">#{browsableUrl}</a>
|
<dd><a href="#{browsableUrl}">#{browsableUrl}</a>
|
||||||
<dt>clone by
|
<dt>clone by
|
||||||
<dd><code>git clone --single-branch #{publicSubmissionRepo} -b #{publicSubmissionBranch}</code>
|
<dd><code>git clone --single-branch #{publicSubmissionRepo} -b #{publicSubmissionBranch}</code>
|
||||||
|
|
||||||
|
^{resultTable (Entity (fsiSubmissionId submission) (fsiSubmission submission))}
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
5
templates/result-table.hamlet
Normal file
5
templates/result-table.hamlet
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<div id="t#{resultId}">
|
||||||
|
$if null tableEntries
|
||||||
|
<p>No results available. The submission is probably broken.
|
||||||
|
$else
|
||||||
|
^{Table.buildBootstrap (paramTable paramNames tests) tableEntries}
|
8
templates/result-table.julius
Normal file
8
templates/result-table.julius
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
$(#{jsSelector}).DataTable({
|
||||||
|
'pageLength': 50,
|
||||||
|
'order': [[0, 'asc'], [#{delta} + ($.fn.dataTable.getColumnDefs(#{delta}, #{higherTheBetterArray})).length-1, 'desc']],
|
||||||
|
'columnDefs': $.fn.dataTable.getColumnDefs(#{delta}, #{higherTheBetterArray})
|
||||||
|
});
|
||||||
|
} );
|
Loading…
Reference in New Issue
Block a user