zeit/z/stats.go

80 lines
2.6 KiB
Go
Raw Normal View History

2020-10-16 15:36:44 +00:00
package z
import (
"os"
"fmt"
"github.com/spf13/cobra"
"github.com/shopspring/decimal"
2020-10-16 17:11:33 +00:00
"github.com/gookit/color"
2020-10-16 15:36:44 +00:00
)
var statsCmd = &cobra.Command{
Use: "stats",
Short: "Display activity statistics",
Long: "Display statistics on all tracked activities.",
Run: func(cmd *cobra.Command, args []string) {
// user := GetCurrentUser()
// entries, err := database.ListEntries(user)
// if err != nil {
// fmt.Printf("%s %+v\n", CharError, err)
// os.Exit(1)
// }
// for _, entry := range entries {
// fmt.Printf("%s\n", entry.GetOutput())
// }
var cal Calendar
2020-10-16 17:11:33 +00:00
var data = make(map[string][]Statistic)
2020-10-16 15:36:44 +00:00
2020-10-16 17:11:33 +00:00
data["Mo"] = []Statistic {
Statistic{ Hours: decimal.NewFromFloat(12.0), Project: "zeit", Color: color.FgRed.Render },
Statistic{ Hours: decimal.NewFromFloat(3.5), Project: "blog", Color: color.FgGreen.Render },
}
data["Tu"] = []Statistic {
Statistic{ Hours: decimal.NewFromFloat(2.25), Project: "zeit", Color: color.FgRed.Render },
Statistic{ Hours: decimal.NewFromFloat(4.0), Project: "blog", Color: color.FgGreen.Render },
}
data["We"] = []Statistic {
Statistic{ Hours: decimal.NewFromFloat(10.0), Project: "zeit", Color: color.FgRed.Render },
Statistic{ Hours: decimal.NewFromFloat(1.5), Project: "blog", Color: color.FgGreen.Render },
}
data["Th"] = []Statistic {
Statistic{ Hours: decimal.NewFromFloat(4.0), Project: "zeit", Color: color.FgRed.Render },
Statistic{ Hours: decimal.NewFromFloat(4.5), Project: "blog", Color: color.FgGreen.Render },
}
data["Fr"] = []Statistic {
Statistic{ Hours: decimal.NewFromFloat(0.5), Project: "zeit", Color: color.FgRed.Render },
Statistic{ Hours: decimal.NewFromFloat(3.5), Project: "blog", Color: color.FgGreen.Render },
}
data["Sa"] = []Statistic {
Statistic{ Hours: decimal.NewFromFloat(1.0), Project: "zeit", Color: color.FgRed.Render },
Statistic{ Hours: decimal.NewFromFloat(1.0), Project: "blog", Color: color.FgGreen.Render },
}
data["Su"] = []Statistic {
Statistic{ Hours: decimal.NewFromFloat(10.0), Project: "zeit", Color: color.FgRed.Render },
Statistic{ Hours: decimal.NewFromFloat(0.5), Project: "blog", Color: color.FgGreen.Render },
}
2020-10-16 15:36:44 +00:00
2020-10-16 16:02:41 +00:00
out := cal.GetOutputForWeekCalendar(1, data)
out2 := cal.GetOutputForWeekCalendar(2, data)
2020-10-16 15:36:44 +00:00
2020-10-16 16:02:41 +00:00
fmt.Printf("%s\n", OutputAppendRight(out, out2, 10))
2020-10-16 15:36:44 +00:00
return
},
}
func init() {
rootCmd.AddCommand(statsCmd)
var err error
database, err = InitDatabase()
if err != nil {
fmt.Printf("%s %+v\n", CharError, err)
os.Exit(1)
}
}