Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lichen.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ library
, Lichen.Plagiarism.Render
, Lichen.Plagiarism.Render.Index
, Lichen.Plagiarism.Render.Compare
, Lichen.Plagiarism.Render.PathGenerators
, Lichen.Count.Main
, Lichen.Count.Counters
, Lichen.Diagnostics.Main
Expand All @@ -57,7 +56,6 @@ library
, blaze-markup
, clay
, jmacro
, text-format
ghc-options: -Wall -fwarn-incomplete-patterns
default-language: Haskell2010

Expand Down
36 changes: 31 additions & 5 deletions src/Lichen/Config/Plagiarism.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,29 @@ import Data.Maybe
import Data.Aeson
import qualified Data.Text as T

import qualified Text.Blaze.Html5 as H

import Lichen.Config
import Lichen.Config.Languages
import Lichen.Plagiarism.Render.PathGenerators

newtype PathGenerator = PathGenerator { runPathGenerator :: Config -> String -> String -> H.AttributeValue }
instance FromJSON PathGenerator where
parseJSON (String s) = pure $ generatePathChoice generatePathSubmitty (Just $ T.unpack s)
parseJSON _ = pure generatePathSubmitty

generatePathStatic :: PathGenerator
generatePathStatic = PathGenerator $ \_ x y -> H.stringValue $ "compare/" ++ x ++ "_" ++ y ++ ".html"

generatePathSubmitty :: PathGenerator
generatePathSubmitty = PathGenerator $ \c x y -> H.stringValue $ mconcat [ "index.php?semester=", submittySemester c
, "&course=", submittyCourse c
, "&assignment=", submittyAssignment c
, "&component=admin&page=plagiarism&action=compare&studenta=", x, "&studentb=", y ]

generatePathChoice :: PathGenerator -> Maybe String -> PathGenerator
generatePathChoice d Nothing = d
generatePathChoice _ (Just "static") = generatePathStatic
generatePathChoice _ _ = generatePathSubmitty

data Config = Config
{ dataDir :: FilePath
Expand All @@ -19,7 +39,9 @@ data Config = Config
, language :: Language
, topMatches :: Int
, pathGenerator :: PathGenerator
, pathBase :: FilePath
, submittySemester :: FilePath
, submittyCourse :: FilePath
, submittyAssignment :: FilePath
, sourceDir :: Maybe FilePath
, pastDirs :: [FilePath]
}
Expand All @@ -33,21 +55,25 @@ instance FromJSON Config where
language <- fromMaybe (language defaultConfig) <$> o .:? "language"
topMatches <- fromMaybe (topMatches defaultConfig) <$> o .:? "top_matches"
pathGenerator <- fromMaybe (pathGenerator defaultConfig) <$> o .:? "path_generator"
pathBase <- fromMaybe (pathBase defaultConfig) <$> o .:? "path_base"
submittySemester <- fromMaybe (submittySemester defaultConfig) <$> o .:? "submitty_semester"
submittyCourse <- fromMaybe (submittyCourse defaultConfig) <$> o .:? "submitty_course"
submittyAssignment <- fromMaybe (submittyAssignment defaultConfig) <$> o .:? "submitty_assignment"
sourceDir <- fromMaybe (sourceDir defaultConfig) <$> o .:? "source_dir"
pastDirs <- fromMaybe (pastDirs defaultConfig) <$> o .:? "past_dirs"
return Config{..}

defaultConfig :: Config
defaultConfig = Config { dataDir = ".lichen"
defaultConfig = Config { dataDir = "plagiarism"
, concatDir = "concatenated"
, highlightDir = "highlighted"
, reportDir = "report"
, reportTitle = "Plagiarism Detection"
, language = langDummy
, topMatches = 100
, pathGenerator = generatePathSubmitty
, pathBase = ""
, submittySemester = "invalid"
, submittyCourse = "invalid"
, submittyAssignment = "invalid"
, sourceDir = Nothing
, pastDirs = []
}
Expand Down
5 changes: 3 additions & 2 deletions src/Lichen/Plagiarism/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import Lichen.Plagiarism.Concatenate
import Lichen.Plagiarism.Highlight
import Lichen.Plagiarism.Report
import Lichen.Plagiarism.Walk
import Lichen.Plagiarism.Render.PathGenerators

parseOptions :: Config -> Parser Config
parseOptions dc = Config
Expand All @@ -36,7 +35,9 @@ parseOptions dc = Config
<*> (languageChoice (language dc) <$> (optional . strOption $ long "language" <> short 'l' <> metavar "LANG" <> help "Language of student code"))
<*> option auto (long "top-matches" <> short 't' <> metavar "N" <> showDefault <> value (topMatches dc) <> help "Number of top matches to report")
<*> (generatePathChoice (pathGenerator dc) <$> (optional . strOption $ long "path-generator" <> metavar "GENERATOR" <> help "Path generation method for reports"))
<*> strOption (long "path-base" <> metavar "BASE" <> value (pathBase dc) <> help "Base to prepend to report paths")
<*> strOption (long "semester" <> metavar "SEMESTER" <> value (submittySemester dc) <> help "Semester for Submitty path generation")
<*> strOption (long "course" <> metavar "COURSE" <> value (submittyCourse dc) <> help "Course for Submitty path generation")
<*> strOption (long "assignment" <> metavar "ASSIGNMENT" <> value (submittyAssignment dc) <> help "Assignment for Submitty path generation")
<*> optional (argument str (metavar "SOURCE_DIR"))
<*> many (argument str (metavar "PAST_DIRS"))

Expand Down
4 changes: 1 addition & 3 deletions src/Lichen/Plagiarism/Render/Index.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import Numeric
import Lichen.Util
import Lichen.Config.Plagiarism
import Lichen.Plagiarism.Render
import Lichen.Plagiarism.Render.PathGenerators

renderEntry :: Show a => Config -> (Double, (b, a), (b, a)) -> H.Html
renderEntry config (match, (_, x), (_, y)) = H.tr (H.td (H.a ! A.href (H.stringValue (pathBase config)
<> runPathGenerator (pathGenerator config) (sq x) (sq y)) $ H.toHtml $ showFFloat (Just 2) (match * 100) "%")
renderEntry config (match, (_, x), (_, y)) = H.tr (H.td (H.a ! A.href (runPathGenerator (pathGenerator config) config (sq x) (sq y)) $ H.toHtml $ showFFloat (Just 2) (match * 100) "%")
<> H.td (hs x) <> H.td (hs y))

renderTable :: Show a => Config -> [(Double, (b, a), (b, a))] -> H.Html
Expand Down
24 changes: 0 additions & 24 deletions src/Lichen/Plagiarism/Render/PathGenerators.hs

This file was deleted.