Add challenge versions

This commit is contained in:
Filip Gralinski 2019-08-27 22:36:51 +02:00
parent 1b122daad6
commit d9b92b772a
4 changed files with 49 additions and 2 deletions

View File

@ -89,6 +89,18 @@ doCreateChallenge name publicUrl publicBranch publicGitAnnexRemote privateUrl pr
Nothing -> return ()
Nothing -> return ()
defaultMajorVersion :: Int
defaultMajorVersion = 1
defaultMinorVersion :: Int
defaultMinorVersion = 0
defaultPatchVersion :: Int
defaultPatchVersion = 0
defaultInitialDescription :: Text
defaultInitialDescription = "initial version"
addChallenge :: Text -> (Key Repo) -> (Key Repo) -> Channel -> Handler ()
addChallenge name publicRepoId privateRepoId chan = do
msg chan "adding challenge..."
@ -111,7 +123,19 @@ addChallenge name publicRepoId privateRepoId chan = do
else do
return Nothing
privateRepo <- runDB $ get404 privateRepoId
time <- liftIO getCurrentTime
let commit=repoCurrentCommit $ privateRepo
_ <- runDB $ insert $ Version {
versionCommit=commit,
versionMajor=defaultMajorVersion,
versionMinor=defaultMinorVersion,
versionPatch=defaultPatchVersion,
versionDescription=defaultInitialDescription,
versionStamp=time}
challengeId <- runDB $ insert $ Challenge {
challengePublicRepo=publicRepoId,
challengePrivateRepo=privateRepoId,
@ -121,8 +145,11 @@ addChallenge name publicRepoId privateRepoId chan = do
challengeStamp=time,
challengeImage=mImage,
challengeStarred=False,
challengeArchived=Just False}
challengeArchived=Just False,
challengeVersion=Just commit}
updateTests challengeId chan
return ()
updateTests :: (Key Challenge) -> Channel -> Handler ()

View File

@ -441,6 +441,7 @@ getScoreForOut mainTestId out = do
getSubmission :: UserId -> Key Repo -> SHA1 -> Key Challenge -> Text -> Channel -> Handler (Key Submission)
getSubmission userId repoId commit challengeId description chan = do
challenge <- runDB $ get404 challengeId
maybeSubmission <- runDB $ getBy $ UniqueSubmissionRepoCommitChallenge repoId commit challengeId
case maybeSubmission of
Just (Entity submissionId _) -> do
@ -457,7 +458,8 @@ getSubmission userId repoId commit challengeId description chan = do
submissionStamp=time,
submissionSubmitter=userId,
submissionIsPublic=False,
submissionIsHidden=False }
submissionIsHidden=False,
submissionVersion=challengeVersion challenge}
getOuts :: Channel -> Key Submission -> M.Map Text Text -> Handler ([Out])
getOuts chan submissionId generalParams = do

6
add-versions.sql Normal file
View File

@ -0,0 +1,6 @@
/*insert into version("commit", major, minor, patch, description) select R.current_commit, 1, 0, 0, 'taken over' from challenge C, repo R where C.private_repo = R.id ;
update challenge set version = (select R.current_commit from repo R where private_repo = R.id);*/
update submission set version = (select R.current_commit from repo R, challenge C where C.private_repo = R.id and challenge = C.id);

View File

@ -40,6 +40,16 @@ Challenge
image ByteString Maybe
starred Bool
archived Bool Maybe
version SHA1 Maybe
-- challenge version
Version
commit SHA1
major Int
minor Int
patch Int
UniqueVersion commit major minor patch
description Text
stamp UTCTime default=now()
Test
challenge ChallengeId
metric EvaluationScheme
@ -59,6 +69,8 @@ Submission
submitter UserId
isPublic Bool default=False
isHidden Bool default=False
-- challenge version present when the submission was done
version SHA1 Maybe
UniqueSubmissionRepoCommitChallenge repo commit challenge
Variant
submission SubmissionId