Exemple #1
0
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()
	}
}
Exemple #2
0
func report(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))

	db := new(database.Database)
	loadDatabase(fileLocation, db.Add)
	emitter := func(v string) {
		println(v)
	}

	aggNameSlice := c.StringSlice("agg")
	if len(aggNameSlice) == 0 {
		printResults(db.Query(start, end, filter), emitter)
		return
	}

	aggs, err := aggregators.Fetch(aggNameSlice...)
	fatalErr(err)
	results, aggResults := db.Aggregate(start, end, filter, aggs...)
	printResults(results, emitter)

	fmt.Println("===============\n")
	for i, aggResult := range aggResults {
		fmt.Printf("%s = %s\n", aggNameSlice[i], aggResult)
	}
}
Exemple #3
0
		})
	})

	It("has a map of aggregators", func() {
		aggregators.AddToStore("some-agg-name", someAgg)
		Expect(aggregators.Store()).To(HaveKey("some-agg-name"))
	})

	It("panics if the same name is added twice", func() {
		aggregators.AddToStore("some-other-name", nil)
		Expect(func() { aggregators.AddToStore("some-other-name", nil) }).To(Panic())
	})

	Describe("Fetch()", func() {
		It("returns all the matching aggregators", func() {
			aggregators.AddToStore("agg-1", someAgg)
			aggregators.AddToStore("agg-2", someAgg)
			aggs, err := aggregators.Fetch("agg-1", "agg-2")

			Expect(err).ToNot(HaveOccurred())
			Expect(aggs).To(HaveLen(2))
		})

		It("returns an error for an unknown name", func() {
			_, err := aggregators.Fetch("agg-3")
			Expect(err).To(HaveOccurred())
		})
	})

})