From 23f8df8961e38b1039f3cb4ec6a9c60d1d858e16 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Tue, 29 Sep 2015 18:23:11 +0200 Subject: [PATCH] do evaluation with GEval --- Handler/CreateChallenge.hs | 3 ++- Handler/ShowChallenge.hs | 25 ++++++++++++++++++++++++- gonito.cabal | 2 ++ stack.yaml | 3 ++- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Handler/CreateChallenge.hs b/Handler/CreateChallenge.hs index e67faa2..6e100a8 100644 --- a/Handler/CreateChallenge.hs +++ b/Handler/CreateChallenge.hs @@ -9,6 +9,7 @@ import Handler.Extract import System.Directory (doesFileExist) import System.FilePath.Find as SFF +import System.FilePath import qualified Data.Text as T import PersistSHA1 @@ -94,7 +95,7 @@ checkTestDir chan challengeId commit testDir = do checksum <- liftIO $ gatherSHA1 testDir testId <- runDB $ insert $ Test { testChallenge=challengeId, - testName=T.pack testDir, + testName=T.pack $ takeFileName testDir, testChecksum=(SHA1 checksum), testCommit=commit, testActive=True } diff --git a/Handler/ShowChallenge.hs b/Handler/ShowChallenge.hs index 7b726a5..e2b77dd 100644 --- a/Handler/ShowChallenge.hs +++ b/Handler/ShowChallenge.hs @@ -13,6 +13,9 @@ import qualified Data.Text as T import Handler.Extract import Handler.Shared +import GEval.Core +import GEval.OptionsParser + import PersistSHA1 getShowChallengeR :: Text -> Handler Html @@ -57,7 +60,8 @@ doCreateSubmission challengeId description url branch chan = do Just repoId -> do repo <- runDB $ get404 repoId submissionId <- getSubmission repoId (repoCurrentCommit repo) challengeId description chan - msg chan "HAHA" + _ <- getOuts chan submissionId + msg chan "Done" Nothing -> return () getSubmission :: Key Repo -> SHA1 -> Key Challenge -> Text -> Channel -> Handler (Key Submission) @@ -112,12 +116,31 @@ checkOrInsertOut out = do checkOrInsertEvaluation :: FilePath -> Channel -> Out -> Handler () checkOrInsertEvaluation repoDir chan out = do test <- runDB $ get404 $ outTest out + challenge <- runDB $ get404 $ testChallenge test maybeEvaluation <- runDB $ getBy $ UniqueEvaluationTestChecksum (outTest out) (outChecksum out) case maybeEvaluation of Just (Entity _ evaluation) -> do msg chan $ concat ["Already evaluated with score ", (T.pack $ fromMaybe "???" $ show <$> evaluationScore evaluation)] Nothing -> do msg chan $ "Start evaluation..." + result <- liftIO $ runGEvalGetOptions ["--expected-directory", (getRepoDir $ challengePrivateRepo challenge), + "--out-directory", repoDir] + case result of + Left parseResult -> do + err chan "Cannot parse options, check the challenge repo" + Right (opts, Just result) -> do + msg chan $ concat [ "Evaluated! Score ", (T.pack $ show result) ] + time <- liftIO getCurrentTime + runDB $ insert $ Evaluation { + evaluationTest=outTest out, + evaluationChecksum=outChecksum out, + evaluationScore=Just result, + evaluationErrorMessage=Nothing, + evaluationStamp=time } + msg chan "Evaluation done" + Right (_, Nothing) -> do + err chan "Error during the evaluation" + getSubmissionRepo :: Key Challenge -> Text -> Text -> Channel -> Handler (Maybe (Key Repo)) getSubmissionRepo challengeId url branch chan = do diff --git a/gonito.cabal b/gonito.cabal index 944db9b..d2b81b0 100644 --- a/gonito.cabal +++ b/gonito.cabal @@ -102,6 +102,8 @@ library , filemanip , cryptohash , markdown + , geval + , filepath executable gonito if flag(library-only) diff --git a/stack.yaml b/stack.yaml index 9920e26..07bc085 100644 --- a/stack.yaml +++ b/stack.yaml @@ -4,5 +4,6 @@ flags: dev: false packages: - '.' -extra-deps: [markdown-0.1.13.2] +- '../geval' +extra-deps: [markdown-0.1.13.2,geval-0.1.0.0] resolver: nightly-2015-08-20