<commit_before>module App.Clk.MonthFile (
      MonthFile
    , maybeMonthFile
) where

import Data.Period (Period(Period))
import Data.Time.Calendar
import Data.Time.Clock
import System.AbsolutePath
import Text.Regex.Posix

data MonthFile = MonthFile Period AbsolutePath

maybeMonthFile :: AbsolutePath -> Maybe MonthFile
maybeMonthFile path
    | isMonthFile path = Just $ MonthFile period path
    | otherwise        = Nothing
        where period = pathPeriod path

pathPeriod :: AbsolutePath -> Period
pathPeriod path = Period monthStart monthEnd
    where monthStart = firstSecond month
          monthEnd   = lastSecond  month
          month      = mkMonth $ takeBaseName path

isMonthFile :: AbsolutePath -> Bool
isMonthFile path = name && extension
    where name      = isYYYYMM   $ takeBaseName  path
          extension = (==".txt") $ takeExtension path

isYYYYMM :: String -> Bool
isYYYYMM x = x =~ "^[0-9]{4}-[0-9]{2}$"



-- a convenient type when working with MonthFile values
data Month = Month { year :: Integer, month :: Int }
mkMonth :: String -> Month
mkMonth yyyymm = Month (read yyyy) (read mm)
    where yyyy = take 4 yyyymm
          mm   = drop 5 yyyymm

firstSecond :: Month -> UTCTime<commit_msg>Add Show, Eq and Ord instances for MonthFile<commit_after>module App.Clk.MonthFile (
      MonthFile
    , maybeMonthFile
) where

import Data.Function (on)
import Data.Period (Period(Period),start)
import Data.Time.Calendar
import Data.Time.Clock
import System.AbsolutePath
import Text.Regex.Posix

data MonthFile = MonthFile {
        period :: Period,
        path   :: AbsolutePath
    } deriving (Show, Eq)

instance Ord MonthFile where
    compare = compare `on` (start.period)

maybeMonthFile :: AbsolutePath -> Maybe MonthFile
maybeMonthFile path
    | isMonthFile path = Just $ MonthFile period path
    | otherwise        = Nothing
        where period = pathPeriod path

pathPeriod :: AbsolutePath -> Period
pathPeriod path = Period monthStart monthEnd
    where monthStart = firstSecond month
          monthEnd   = lastSecond  month
          month      = mkMonth $ takeBaseName path

isMonthFile :: AbsolutePath -> Bool
isMonthFile path = name && extension
    where name      = isYYYYMM   $ takeBaseName  path
          extension = (==".txt") $ takeExtension path

isYYYYMM :: String -> Bool
isYYYYMM x = x =~ "^[0-9]{4}-[0-9]{2}$"



-- a convenient type when working with MonthFile values
data Month = Month { year :: Integer, month :: Int }
mkMonth :: String -> Month
mkMonth yyyymm = Month (read yyyy) (read mm)
    where yyyy = take 4 yyyymm
          mm   = drop 5 yyyymm

firstSecond :: Month -> UTCTime
{'fraction_non_alphanumeric': 0.08716981132075471, 'fraction_numerical': 0.0060377358490566035, 'mean_word_length': 3.0784615384615384, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '7278504', 'n_tokens_mistral': 779, 'n_tokens_neox': 753, 'n_words': 258}