ENH don't use exact matching

This commit is contained in:
Nathan Dwarshuis 2022-12-24 17:54:20 -05:00
parent 966576ab1a
commit 137d56a139
3 changed files with 7 additions and 20 deletions

View File

@ -101,10 +101,7 @@ let MatchYMD = < Y : Natural | YM : GregorianM | YMD : Gregorian >
let MatchDate = < On : MatchYMD | In : { _1 : MatchYMD, _2 : Natural } >
let MatchDesc = < Re : Text | Exact : Text >
let MatchOther =
< Desc : Field Text MatchDesc | Val : Field Text MatchVal.Type >
let MatchOther = < Desc : Field Text Text | Val : Field Text MatchVal.Type >
let SplitNum = < LookupN : Text | ConstN : Decimal | AmountN >
@ -141,7 +138,7 @@ let Match =
{ Type =
{ mDate : Optional MatchDate
, mVal : MatchVal.Type
, mDesc : Optional MatchDesc
, mDesc : Optional Text
, mOther : List MatchOther
, mTx : Optional ToTx
, mTimes : Optional Natural
@ -150,7 +147,7 @@ let Match =
, default =
{ mDate = None MatchDate
, mVal = MatchVal::{=}
, mDesc = None MatchDesc
, mDesc = None Text
, mOther = [] : List MatchOther
, mTx = None ToTx
, mTimes = None Natural
@ -235,7 +232,6 @@ in { CurID
, MatchVal
, MatchYMD
, MatchDate
, MatchDesc
, MatchOther
, SplitNum
, Field

View File

@ -45,7 +45,6 @@ makeHaskellTypesWith (defaultGenerateOptions { generateToDhallInstance = False }
, MultipleConstructors "DatePat" "(./dhall/Types.dhall).DatePat"
, MultipleConstructors "MatchYMD" "(./dhall/Types.dhall).MatchYMD"
, MultipleConstructors "MatchDate" "(./dhall/Types.dhall).MatchDate"
, MultipleConstructors "MatchDesc" "(./dhall/Types.dhall).MatchDesc"
, MultipleConstructors "SplitNum" "(./dhall/Types.dhall).SplitNum"
, MultipleConstructors "Bucket" "(./dhall/Types.dhall).Bucket"
@ -340,11 +339,7 @@ data Field k v = Field
type FieldMap k v = Field k (M.Map k v)
deriving instance Eq MatchDesc
deriving instance Show MatchDesc
deriving instance Hashable MatchDesc
data MatchOther = Desc (Field T.Text MatchDesc)
data MatchOther = Desc (Field T.Text T.Text)
| Val (Field T.Text MatchVal)
deriving (Show, Eq, Hashable, Generic, FromDhall)
@ -358,7 +353,7 @@ data ToTx = ToTx
data Match = Match
{ mDate :: Maybe MatchDate
, mVal :: MatchVal
, mDesc :: Maybe MatchDesc
, mDesc :: Maybe Text
, mOther :: ![MatchOther]
, mTx :: Maybe ToTx
, mTimes :: Maybe Natural

View File

@ -19,10 +19,6 @@ import Internal.Types
import Text.Read
import Text.Regex.TDFA
descMatches :: MatchDesc -> T.Text -> Bool
descMatches (Re re) = (=~ re)
descMatches (Exact t) = (== t)
-- when bifunctor fails...
thrice :: (a -> d) -> (b -> e) -> (c -> f) -> (a, b, c) -> (d, e, f)
thrice f1 f2 f3 (x, y, z) = (f1 x, f2 y, f3 z)
@ -123,7 +119,7 @@ matches Match {..} r@TxRecord {..}
where
allPass = checkMaybe (`dateMatches` trDate) mDate
&& valMatches mVal trAmount
&& checkMaybe (`descMatches` trDesc) mDesc
&& checkMaybe (=~ trDesc) mDesc
&& all (fieldMatches trOther) mOther
eval (ToTx cur a ss) = toTx cur a ss r
@ -134,7 +130,7 @@ fieldMatches dict m = case m of
(Just v) -> valMatches mv v
_ -> error "you dummy"
Desc (Field n md) -> case M.lookup n dict of
(Just d) -> descMatches md d
(Just d) -> d =~ md
_ -> error "you dummy"
checkMaybe :: (a -> Bool) -> Maybe a -> Bool