Handle metric priorities

This commit is contained in:
Filip Gralinski 2019-12-14 22:24:22 +01:00
parent 04483849e8
commit b2742f06e2
7 changed files with 24 additions and 14 deletions

View File

@ -251,7 +251,7 @@ getOngoingTargets challengeId = do
return indicator return indicator
indicatorEntries <- mapM indicatorToEntry indicators indicatorEntries <- mapM indicatorToEntry indicators
theNow <- liftIO $ getCurrentTime theNow <- liftIO $ getCurrentTime
(entries, _) <- runDB $ getChallengeSubmissionInfos (const True) (const True) challengeId (entries, _) <- runDB $ getChallengeSubmissionInfos 1 (const True) (const True) challengeId
let indicatorEntries' = map (onlyWithOngoingTargets theNow entries) indicatorEntries let indicatorEntries' = map (onlyWithOngoingTargets theNow entries) indicatorEntries
return indicatorEntries' return indicatorEntries'

View File

@ -33,7 +33,7 @@ getChallengeParamGraphDataR challengeName testId paramName = do
test <- runDB $ get404 testId test <- runDB $ get404 testId
let testRef = getTestReference (Entity testId test) let testRef = getTestReference (Entity testId test)
(entries, _) <- runDB $ getChallengeSubmissionInfos (const True) (const True) challengeId (entries, _) <- runDB $ getChallengeSubmissionInfos 1 (const True) (const True) challengeId
let values = map (findParamValue paramName) entries let values = map (findParamValue paramName) entries
@ -162,7 +162,7 @@ getIndicatorGraphDataR indicatorId = do
test <- runDB $ get404 testId test <- runDB $ get404 testId
let mPrecision = testPrecision test let mPrecision = testPrecision test
(entries, _) <- runDB $ getChallengeSubmissionInfos (const True) (const True) (testChallenge test) (entries, _) <- runDB $ getChallengeSubmissionInfos 1 (const True) (const True) (testChallenge test)
theNow <- liftIO $ getCurrentTime -- needed to draw the "now" vertical line theNow <- liftIO $ getCurrentTime -- needed to draw the "now" vertical line

View File

@ -36,7 +36,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) <- runDB $ getChallengeSubmissionInfos condition (const True) challengeId (evaluationMaps', tests) <- runDB $ getChallengeSubmissionInfos 1 condition (const True) challengeId
let evaluationMaps = take 10 evaluationMaps' let evaluationMaps = take 10 evaluationMaps'
sampleLeaderboard <- getSampleLeaderboard sampleChallengeName sampleLeaderboard <- getSampleLeaderboard sampleChallengeName
@ -57,7 +57,7 @@ getPresentationPSNC2019R = 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) <- runDB $ getChallengeSubmissionInfos condition (const True) challengeId (evaluationMaps', tests) <- runDB $ getChallengeSubmissionInfos 1 condition (const True) challengeId
let evaluationMaps = take 10 evaluationMaps' let evaluationMaps = take 10 evaluationMaps'
sampleLeaderboard <- getSampleLeaderboard sampleChallengeName sampleLeaderboard <- getSampleLeaderboard sampleChallengeName

View File

@ -186,7 +186,8 @@ getViewVariantR variantId = do
let theSubmissionId = variantSubmission variant let theSubmissionId = variantSubmission variant
theSubmission <- runDB $ get404 theSubmissionId theSubmission <- runDB $ get404 theSubmissionId
([entry], tests') <- runDB $ getChallengeSubmissionInfos (\e -> entityKey e == theSubmissionId) ([entry], tests') <- runDB $ getChallengeSubmissionInfos 3
(\e -> entityKey e == theSubmissionId)
(\e -> entityKey e == variantId) (\e -> entityKey e == variantId)
(submissionChallenge theSubmission) (submissionChallenge theSubmission)
let tests = sortBy (flip testComparator) tests' let tests = sortBy (flip testComparator) tests'
@ -295,7 +296,8 @@ resultTable :: Entity Submission -> WidgetFor App ()
resultTable (Entity submissionId submission) = do resultTable (Entity submissionId submission) = do
(tableEntries, tests) <- handlerToWidget (tableEntries, tests) <- handlerToWidget
$ runDB $ runDB
$ getChallengeSubmissionInfos (\s -> entityKey s == submissionId) $ getChallengeSubmissionInfos 2
(\s -> entityKey s == submissionId)
(const True) (const True)
(submissionChallenge submission) (submissionChallenge submission)
let paramNames = let paramNames =

View File

@ -437,7 +437,7 @@ checkIndicators user challengeId submissionId submissionLink relevantIndicators
checkIndicator :: UTCTime -> User -> ChallengeId -> SubmissionId -> Text -> IndicatorEntry -> Channel -> Handler () checkIndicator :: UTCTime -> User -> ChallengeId -> SubmissionId -> Text -> IndicatorEntry -> Channel -> Handler ()
checkIndicator theNow user challengeId submissionId submissionLink indicator chan = do checkIndicator theNow user challengeId submissionId submissionLink indicator chan = do
(entries, _) <- runDB $ getChallengeSubmissionInfos (\(Entity sid _) -> sid == submissionId) (const True) challengeId (entries, _) <- runDB $ getChallengeSubmissionInfos 1 (\(Entity sid _) -> sid == submissionId) (const True) challengeId
mapM_ (\t -> checkTarget theNow user submissionLink entries indicator t chan) (indicatorEntryTargets indicator) mapM_ (\t -> checkTarget theNow user submissionLink entries indicator t chan) (indicatorEntryTargets indicator)
checkTarget :: UTCTime -> User -> Text -> [TableEntry] -> IndicatorEntry -> Entity Target -> Channel -> Handler () checkTarget :: UTCTime -> User -> Text -> [TableEntry] -> IndicatorEntry -> Entity Target -> Channel -> Handler ()
@ -535,7 +535,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') <- runDB $ getChallengeSubmissionInfos condition (const True) challengeId (evaluationMaps, tests') <- runDB $ getChallengeSubmissionInfos 1 condition (const True) 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

View File

@ -224,7 +224,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) <- runDB $ getChallengeSubmissionInfos condition (const True) challengeId (evaluationMaps, tests) <- runDB $ getChallengeSubmissionInfos 1 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
@ -311,13 +311,21 @@ compareResult _ (Just _) Nothing = GT
compareResult _ Nothing (Just _) = LT compareResult _ Nothing (Just _) = LT
compareResult _ Nothing Nothing = EQ compareResult _ Nothing Nothing = EQ
getChallengeSubmissionInfos :: (MonadIO m, PersistQueryRead backend, BackendCompatible SqlBackend backend, PersistUniqueRead backend, BaseBackend backend ~ SqlBackend) => (Entity Submission -> Bool) -> (Entity Variant -> Bool) -> Key Challenge -> ReaderT backend m ([TableEntry], [Entity Test]) getChallengeSubmissionInfos :: (MonadIO m,
getChallengeSubmissionInfos condition variantCondition challengeId = do PersistQueryRead backend,
BackendCompatible SqlBackend backend,
PersistUniqueRead backend, BaseBackend backend ~ SqlBackend)
=> Int
-> (Entity Submission -> Bool)
-> (Entity Variant -> Bool)
-> Key Challenge -> ReaderT backend m ([TableEntry], [Entity Test])
getChallengeSubmissionInfos maxMetricPriority condition variantCondition challengeId = do
challenge <- get404 challengeId challenge <- get404 challengeId
let commit = challengeVersion challenge let commit = challengeVersion challenge
tests <- selectList [TestChallenge ==. challengeId, TestActive ==. True, TestCommit ==. commit] [] tests' <- selectList [TestChallenge ==. challengeId, TestActive ==. True, TestCommit ==. commit] []
let tests = filter (\t -> (evaluationSchemePriority $ testMetric $ entityVal t) <= maxMetricPriority) tests'
let mainTest = getMainTest tests let mainTest = getMainTest tests
allSubmissionsVariants <- E.select $ E.from $ \(submission, variant) -> do allSubmissionsVariants <- E.select $ E.from $ \(submission, variant) -> do

View File

@ -128,7 +128,7 @@ library
, filemanip , filemanip
, cryptohash , cryptohash
, markdown , markdown
, geval >= 1.21.1.0 && < 1.25 , geval >= 1.24 && < 1.25
, filepath , filepath
, yesod-table , yesod-table
, regex-tdfa , regex-tdfa