<commit_before>-----------------------------------------------------------------------------
-- Copyright 2008, Open Universiteit Nederland. This file is distributed 
-- under the terms of the GNU General Public License. For more information, 
-- see the file "LICENSE.txt", which is included in the distribution.
-----------------------------------------------------------------------------
-- |
-- Maintainer  :  <EMAIL>
-- Stability   :  provisional
-- Portability :  portable (depends on ghc)
--
-- Helper CGI script to view entries in the log files
--
-----------------------------------------------------------------------------
module Main (main) where

import Control.Monad.State
import Data.Char
import Data.List
import Data.Maybe
import Network.CGI
import Service.HTML
import System.Directory
import ViewLog.LogEntry

main :: IO ()
main = runCGI $ do
   fileField <- getInput "file"     -- read fields
   lineField <- getInput "line"
   server <- serverName
   script <- scriptName
   
   let self = "http://" ++ server ++ script
       mID  = case (fileField, lineField) of
                 (Just f, Just l) | all isDigit l && not (null l) -> 
                    Just (f, read l)
                 _ -> Nothing
   
   setHeader "Content-type" "text/html"
   case mID of
      Just entryID -> do
         e <- lift $ getEntry entryID
         output $ showHTML $ entryToHTML e
      Nothing -> do
         infos <- lift readMetaInfos
         output $ showHTML $ (infosToHTML self infos)

readMetaInfos :: IO [MetaInfo]
readMetaInfos = do
   files <- getDirectoryContents "."
   let logFiles = filter (".log" `isSuffixOf`) files
   lists <- mapM readIndexFile logFiles
   return (concat lists)
   
---------------------------------------------------------
  
groupByDay :: [MetaInfo] -> [[MetaInfo]]
groupByDay = groupBy (\x y -> f x == f y)
 where
   f i = (day (timeStamp i), month (timeStamp i))
  
-------------------------------------------------------------------------

infosToHTML :: String -> [MetaInfo] -> HTML
infosToHTML self infos = htmlPage "Logs"
   (mapM_ formatGroup list)
 where
   list  = groupByDay infos
   formatGroup xs@(info:_) = do
      h2 (date (timeStamp info) ++ " (" ++ show (length xs) ++ ")")
      table (map makeRow xs)
   formatGroup _ = return ()
   makeRow info = 
      [ let params = "?file=" ++ (fst $ entryID info) ++ "&line=" ++ (show $ snd $ entryID info)<commit_msg>minor changes to view log entries<commit_after>-----------------------------------------------------------------------------
-- Copyright 2008, Open Universiteit Nederland. This file is distributed 
-- under the terms of the GNU General Public License. For more information, 
-- see the file "LICENSE.txt", which is included in the distribution.
-----------------------------------------------------------------------------
-- |
-- Maintainer  :  <EMAIL>
-- Stability   :  provisional
-- Portability :  portable (depends on ghc)
--
-- Helper CGI script to view entries in the log files
--
-----------------------------------------------------------------------------
module Main (main) where

import Control.Monad.State
import Data.Char
import Data.List
import Data.Maybe
import Network.CGI
import Service.HTML
import System.Directory
import ViewLog.LogEntry

main :: IO ()
main = runCGI $ do
   fileField <- getInput "file"     -- read fields
   lineField <- getInput "line"
   server <- serverName
   script <- scriptName
   
   let self = "http://" ++ server ++ script
       mID  = case (fileField, lineField) of
                 (Just f, Just l) | all isDigit l && not (null l) -> 
                    Just (f, read l)
                 _ -> Nothing
   
   setHeader "Content-type" "text/html"
   case mID of
      Just entryID -> do
         e <- lift $ getEntry entryID
         output $ showHTML $ entryToHTML e
      Nothing -> do
         infos <- lift readMetaInfos
         output $ showHTML $ (infosToHTML self infos)

readMetaInfos :: IO [MetaInfo]
readMetaInfos = do
   files1 <- getDirectoryContents "."
   files2 <- getDirectoryContents ".."
   let logFiles = filter (".log" `isSuffixOf`) (sort files1) ++
                  filter (== "service.log") files2
   lists <- mapM readIndexFile logFiles
   return (reverse (concat lists))
   
---------------------------------------------------------
  
groupByDay :: [MetaInfo] -> [[MetaInfo]]
groupByDay = groupBy (\x y -> f x == f y)
 where
   f i = (day (timeStamp i), month (timeStamp i))
  
-------------------------------------------------------------------------

infosToHTML :: String -> [MetaInfo] -> HTML
infosToHTML self infos = htmlPage "Logs"
   (mapM_ formatGroup list)
 where
   list  = groupByDay infos
   formatGroup xs@(info:_) = do
      h2 (date (timeStamp info) ++ " (" ++ show (length xs) ++ ")")
      table (map makeRow xs)
   formatGroup _ = return ()
   makeRow info = 
      [ let params = "?file=" ++ (fst $ entryID info) ++ "&line=" ++ (show $ snd $ entryID info)
{'fraction_non_alphanumeric': 0.24356395816572807, 'fraction_numerical': 0.0028157683024939663, 'mean_word_length': 1.5820353063343717, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6938183', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1322, 'n_words': 461}