Skip to content

Commit

Permalink
feat(core): add variable for default account to use in filters (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
janssen-io committed Feb 16, 2025
1 parent 6e14ac3 commit 9f5e85b
Show file tree
Hide file tree
Showing 34 changed files with 227 additions and 145 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ jobs:
- name: Build
run: >
dotnet run
--project ./src/TransactionQL.Build/TransactionQL.Build.fsproj
-e parallel-jobs=4
-e VERSION=${{ steps.version.outputs.VERSION }}
--project "./src/TransactionQL.Build/TransactionQL.Build.fsproj"
-e VERSION="${{ steps.version.outputs.VERSION }}"
--parallel 4
- name: Publish
uses: softprops/action-gh-release@v1
Expand Down
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dotnet run --project .\src\TransactionQL.Build\TransactionQL.Build.fsproj -t Complete
dotnet run --project .\src\TransactionQL.Build\TransactionQL.Build.fsproj -t Complete --parallel 4
9 changes: 4 additions & 5 deletions src/TransactionQL.Application/API.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ open System
open TransactionQL.Input.Converters
open TransactionQL.Parser.Interpretation



module API =
open FParsec
open TransactionQL.Input
Expand All @@ -26,10 +24,11 @@ module API =
| Some reader -> Left reader
| None -> Right $"Unable to load plugin from directory %s{pluginDirectory}"

let filter (reader: IConverter) (queries: Query array) rows =
let filter (reader: IConverter) (queries: Query array) (variables: Map<string, string>) rows =
rows
|> Seq.map (fun row ->
{ Variables = Map.empty
EnvVars = variables
Row = row
DateFormat = reader.DateFormat })
|> Seq.map (fun env -> QLInterpreter.evalProgram env (List.ofArray queries))
Expand All @@ -45,7 +44,7 @@ module API =
let lines =
trx
|> Array.map (fun (account, (currency: string), (amount: Nullable<decimal>)) ->
let acc = Account(account :: [])
let acc = (account :: [])

match (String.IsNullOrEmpty currency, Option.ofNullable amount) with
| true, _
Expand All @@ -55,7 +54,7 @@ module API =
Tag = None }
| _, Some a ->
{ Account = acc
Amount = Some(Commodity currency, float a)
Amount = Some(currency, float a)
Tag = None })
|> List.ofArray

Expand Down
6 changes: 3 additions & 3 deletions src/TransactionQL.Application/Formatter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Formatter =
let sprintLine
format
floatWidth
({ Account = Account accountParts
({ Account = accountParts
Amount = amount
Tag = tag }: Line)
=
Expand All @@ -34,7 +34,7 @@ module Formatter =

let line =
match amount with
| Some(Commodity commodity, sum) ->
| Some(commodity, sum) ->
// Accounts and commodities must be separated by atleast two spaces
sprintf "%s %*s %*.*f" account numOfSpaces commodity floatWidth format.Precision sum
| None -> account
Expand All @@ -54,7 +54,7 @@ module Formatter =
lines
|> List.map (fun ({ Amount = amount }: Line) ->
match amount with
| Some(Commodity _, number) -> (sprintf "%.*f" format.Precision number).Length
| Some(_, number) -> (sprintf "%.*f" format.Precision number).Length
| None -> 0)
|> List.max

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="9.0.101" />
<PackageReference Update="FSharp.Core" Version="9.0.201" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/TransactionQL.Build/TransactionQL.Build.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
<PackageReference Include="Fake.DotNet.Cli" Version="6.1.3" />
<PackageReference Include="Fake.Installer.InnoSetup" Version="6.1.3" />
<PackageReference Include="Fake.IO.Zip" Version="6.1.3" />
<PackageReference Include="MSBuild.StructuredLogger" Version="2.2.386" />
<PackageReference Include="MSBuild.StructuredLogger" Version="2.2.441" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="9.0.101" />
<PackageReference Update="FSharp.Core" Version="9.0.201" />
</ItemGroup>

</Project>
26 changes: 13 additions & 13 deletions src/TransactionQL.Console.Tests/FormatterTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let ``Header: ends with the payee`` () =

[<Fact>]
let ``Line: is indented`` () =
let line = line (Account [ "A"; "B" ], None, None)
let line = line ([ "A"; "B" ], None, None)

let result =
Formatter.sprintLine
Expand All @@ -55,7 +55,7 @@ let ``Line: is indented`` () =

[<Fact>]
let ``Line: concatenates accounts with colon`` () =
let line = line (Account [ "A"; "B" ], None, None)
let line = line ([ "A"; "B" ], None, None)

let result =
Formatter.sprintLine
Expand All @@ -69,7 +69,7 @@ let ``Line: concatenates accounts with colon`` () =

[<Fact>]
let ``Line: separates accounts and commodity with at least two spaces`` () =
let line = line (Account [ "A"; "B" ], Some(Commodity "$", 25.00), None)
let line = line ([ "A"; "B" ], Some("$", 25.00), None)

let result =
Formatter.sprintLine
Expand All @@ -95,7 +95,7 @@ let ``Line: prints the float with the given precision`` () =
Comment = "# " }

let amount = 25.12345678
let line = line (Account [ "A"; "B" ], Some(Commodity "", amount), None)
let line = line ([ "A"; "B" ], Some("", amount), None)
let result = Formatter.sprintLine format 0 line
Assert.EndsWith("25.123", result)

Expand All @@ -107,7 +107,7 @@ let ``Line: Adds tags (if any) after two spaces`` () =
Comment = "; " }

let amount = 25.12345678
let line = line (Account [ "A"; "B" ], Some(Commodity "", amount), Some "My: Tag")
let line = line ([ "A"; "B" ], Some("", amount), Some "My: Tag")
let result = Formatter.sprintLine format 0 line
Assert.EndsWith(" ; My: Tag", result)

Expand All @@ -116,8 +116,8 @@ let ``Posting: prints header and lines on separate lines`` () =
let posting =
{ Header = Header(new DateTime(2019, 1, 1), "Payee")
Lines =
[ line (Account [ "A"; "B" ], Some(Commodity "", 10.00), None)
line (Account [ "C"; "D" ], None, None) ]
[ line ([ "A"; "B" ], Some("", 10.00), None)
line ([ "C"; "D" ], None, None) ]
Comments = [] }

let result =
Expand All @@ -137,8 +137,8 @@ let ``Posting: aligns amounts to the right`` () =
let posting =
{ Header = Header(new DateTime(2019, 1, 1), "Payee")
Lines =
[ line (Account [ "Assets"; "Checking" ], Some(Commodity "", 10.), None)
line (Account [ "Expenses"; "Vacation" ], Some(Commodity "$", -1000.), None) ]
[ line ([ "Assets"; "Checking" ], Some("", 10.), None)
line ([ "Expenses"; "Vacation" ], Some("$", -1000.), None) ]
Comments = [] }

let result =
Expand All @@ -160,8 +160,8 @@ let ``Missing posting: adds comment before each line`` () =
let posting =
{ Header = Header(new DateTime(2019, 1, 1), "Payee")
Lines =
[ line (Account [ "A"; "B" ], Some(Commodity "", 10.00), None)
line (Account [ "C"; "D" ], None, None) ]
[ line ([ "A"; "B" ], Some("", 10.00), None)
line ([ "C"; "D" ], None, None) ]
Comments = [] }

let format: Format =
Expand All @@ -178,8 +178,8 @@ let ``Comments: comments are added between the header and transactions`` () =
let posting =
{ Header = Header(new DateTime(2019, 1, 1), "Payee")
Lines =
[ line (Account [ "A"; "B" ], Some(Commodity "", 10.00), None)
line (Account [ "C"; "D" ], None, None) ]
[ line ([ "A"; "B" ], Some("", 10.00), None)
line ([ "C"; "D" ], None, None) ]
Comments = [ "Two lines"; "Of comments" ] }

let format: Format =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand All @@ -30,7 +30,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="9.0.100" />
<PackageReference Update="FSharp.Core" Version="9.0.201" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/TransactionQL.Console/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ module Program =
|> options.Reader.Read
|> Seq.map (fun row ->
{ Variables = Map.empty
EnvVars = Map.empty
Row = row
DateFormat = options.Reader.DateFormat })
|> Seq.map (fun env -> QLInterpreter.evalProgram env parsedFilters)
Expand Down
2 changes: 1 addition & 1 deletion src/TransactionQL.Console/TransactionQL.Console.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="9.0.101" />
<PackageReference Update="FSharp.Core" Version="9.0.201" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Avalonia.Headless.XUnit" Version="11.2.3" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.3" />
<PackageReference Include="FSharp.Core" Version="9.0.101" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Avalonia.Headless.XUnit" Version="11.2.4" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.4" />
<PackageReference Include="FSharp.Core" Version="9.0.201" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit 9f5e85b

Please sign in to comment.