<commit_before>import qualified Data.Map as Map
import Data.List
import qualified Data.String.Utils as Str
import Control.Monad
-- import System.IO
import System.Environment (getArgs)

import IgrepCashbook

-- general function
equalBy :: (Eq b) => ( a -> b ) -> a -> a -> Bool
equalBy f a1 a2 = f a1 == f a2
--

convertLines :: [String] -> [String]
convertLines c =
  concatMap formatGroup gs
  where
    is = map ( fixIncomeLine . parseLine ) c
    gs = groupBy sameDate is
    sameDate :: Item -> Item -> Bool
    sameDate [('#':_)] [('#':_)] = True
    sameDate [('#':_)] _ = False
    sameDate _ [('#':_)] = True
    sameDate i1 i2 = equalBy getDate i1 i2

fixIncomeLine :: Item -> Item
fixIncomeLine [day, name, price]
  | isSaraly name = day:name:price:["給料"]
  | otherwise = day:name:price:["その他"]
  where
    isSaraly x =
      x `isInfixOf` "給料" || x `isInfixOf` "財形貯蓄"
fixIncomeLine xs = xs

formatGroup :: [Item] -> [String]
formatGroup [] = []
formatGroup xs = concatDateGroup dateOfGroup withoutDate
  where
    dateOfGroup :: Maybe String
    dateOfGroup = fmap getDate $ find ( not . isComment ) xs
    withoutDate :: [String]<commit_msg>correct wrong usage of isInfixOf in convert-to-cashbook2.hs<commit_after>import qualified Data.Map as Map
import Data.List
import qualified Data.String.Utils as Str
import Control.Monad
-- import System.IO
import System.Environment (getArgs)

import IgrepCashbook

-- general function
equalBy :: (Eq b) => ( a -> b ) -> a -> a -> Bool
equalBy f a1 a2 = f a1 == f a2
--

convertLines :: [String] -> [String]
convertLines c =
  concatMap formatGroup gs
  where
    is = map ( fixIncomeLine . parseLine ) c
    gs = groupBy sameDate is
    sameDate :: Item -> Item -> Bool
    sameDate [('#':_)] [('#':_)] = True
    sameDate [('#':_)] _ = False
    sameDate _ [('#':_)] = True
    sameDate i1 i2 = equalBy getDate i1 i2

fixIncomeLine :: Item -> Item
fixIncomeLine [day, name, price]
  | isSaraly name = day:name:price:["給料"]
  | otherwise = day:name:price:["その他"]
fixIncomeLine xs = xs

isSaraly :: String -> Bool
isSaraly name =
  "給料" `isInfixOf` name || "財形貯蓄" `isInfixOf` name

formatGroup :: [Item] -> [String]
formatGroup [] = []
formatGroup xs = concatDateGroup dateOfGroup withoutDate
  where
    dateOfGroup :: Maybe String
    dateOfGroup = fmap getDate $ find ( not . isComment ) xs
    withoutDate :: [String]
{'fraction_non_alphanumeric': 0.1344289928360725, 'fraction_numerical': 0.007163927517909819, 'mean_word_length': 3.412639405204461, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, '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': '1750463', 'n_tokens_mistral': 851, 'n_tokens_neox': 821, 'n_words': 247}