コード例 #1
0
ファイル: main.go プロジェクト: apoydence/ledger
func grouping(c *cli.Context) {
	if len(c.Args()) != 2 {
		fatal("", c)
	}

	fileLocation := c.String(FileLocation)
	if len(fileLocation) == 0 {
		fatal(fmt.Sprintf("Missing required '--%s' flag\n", FileLocation), c)
	}

	filter := buildFilter(c)

	start := loadDate(c.Args().Get(0))
	end := loadDate(c.Args().Get(1))

	aggNameSlice := c.StringSlice("agg")
	if len(aggNameSlice) == 0 {
		fatal("Missing required '--agg' flag(s)\n", c)
	}

	grouping := database.NewGrouping()
	loadDatabase(fileLocation, grouping.Add)

	aggs, err := aggregators.Fetch(aggNameSlice...)
	fatalErr(err)
	results := grouping.Aggregate(start, end, filter, aggs...)

	for accName, value := range results {
		println(accName)
		for i, r := range value {
			fmt.Printf("\t%s = %s\n", aggNameSlice[i], r)
		}
		println()
	}
}
コード例 #2
0
ファイル: grouping_test.go プロジェクト: apoydence/ledger
			},
		}

		t2 = &transaction.Transaction{
			Date: transaction.NewDate(2015, 10, 11),
			Title: &transaction.Title{
				Value: "some-title",
			},
			Accounts: &transaction.AccountList{
				Accounts: acc2,
			},
		}

		mockFilter = newMockFilter()
		mockAgg = newMockAggregator()
		grouping = database.NewGrouping()
		grouping.Add(t1, t2)
	})

	It("groups based on account names", func() {
		mockAgg.resultCh <- "1234"
		mockAgg.resultCh <- "1234"
		results := grouping.Aggregate(start, end, nil, mockAgg)

		Expect(mockAgg.accountCh).To(HaveLen(2))
		var accs [][]*transaction.Account
		var acc []*transaction.Account
		Expect(mockAgg.accountCh).To(Receive(&acc))
		accs = append(accs, acc)
		Expect(mockAgg.accountCh).To(Receive(&acc))
		accs = append(accs, acc)