2020-10-16 15:36:44 +00:00
|
|
|
package z
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"fmt"
|
2020-10-16 20:41:19 +00:00
|
|
|
"time"
|
2020-10-17 00:33:21 +00:00
|
|
|
"strings"
|
2020-10-16 15:36:44 +00:00
|
|
|
"github.com/spf13/cobra"
|
2020-10-16 20:41:19 +00:00
|
|
|
// "github.com/shopspring/decimal"
|
|
|
|
// "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) {
|
2020-10-16 20:41:19 +00:00
|
|
|
user := GetCurrentUser()
|
2020-10-16 15:36:44 +00:00
|
|
|
|
2020-10-16 20:41:19 +00:00
|
|
|
entries, err := database.ListEntries(user)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("%s %+v\n", CharError, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2020-10-16 15:36:44 +00:00
|
|
|
|
2020-10-16 20:41:19 +00:00
|
|
|
cal, _ := NewCalendar(entries)
|
2020-10-16 15:36:44 +00:00
|
|
|
|
2020-10-16 20:41:19 +00:00
|
|
|
today := time.Now()
|
|
|
|
month, weeknumber := GetISOWeekInMonth(today)
|
|
|
|
month0 := month - 1
|
|
|
|
weeknumber0 := weeknumber - 1
|
|
|
|
thisWeek := cal.GetOutputForWeekCalendar(today, month0, weeknumber0)
|
2020-10-16 15:36:44 +00:00
|
|
|
|
2020-10-16 20:41:19 +00:00
|
|
|
oneWeekAgo := today.AddDate(0, 0, -7)
|
|
|
|
month, weeknumber = GetISOWeekInMonth(oneWeekAgo)
|
|
|
|
month0 = month - 1
|
|
|
|
weeknumber0 = weeknumber - 1
|
|
|
|
previousWeek := cal.GetOutputForWeekCalendar(oneWeekAgo, month0, weeknumber0)
|
2020-10-16 15:36:44 +00:00
|
|
|
|
|
|
|
|
2020-10-17 00:33:21 +00:00
|
|
|
fmt.Printf("\n%s\n\n", strings.ToUpper(today.Month().String()))
|
|
|
|
fmt.Printf("%s\n\n\n", OutputAppendRight(thisWeek, previousWeek, 16))
|
2020-10-16 21:37:48 +00:00
|
|
|
fmt.Printf("%s\n", cal.GetOutputForDistribution())
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|