// analyze.go contains all data analysis package main import ( "fmt" ) // Data for Month type Month struct { Month int MonthName string Year int Days []int Earnings float64 Workhours float64 //Workdays int Tasks []int Projects []int } var analysis []Month //Analyze all tasks and PAyments func MakeAnalysis() { fmt.Println("Making Analysis") tids := GetTaskIds() alltasks := GetSelectedTasks(tids) for _,ta := range alltasks { year,monthn,day := ta.Start.Local().Date() month := int(monthn) monthstr := fmt.Sprintf("%v",monthn) exist, exid := MonthExists(year,month) dur := ta.Duration() if exist { if !isElement(day,analysis[exid].Days){ analysis[exid].Days = append(analysis[exid].Days,day) } analysis[exid].Workhours += dur analysis[exid].Tasks = append(analysis[exid].Tasks,ta.Id) if !isElement(ta.Projectid,analysis[exid].Projects){ analysis[exid].Projects = append(analysis[exid].Projects,ta.Projectid) } }else{ analysis = append(analysis,Month{ month, monthstr, year, []int{day}, 0.0, //Earning dur, //Workhours []int{ta.Id},[]int{ta.Projectid}}) } } pays := GetAllPayments() for _,py := range pays { year,monthn,_ := py.Date.Local().Date() month := int(monthn) monthstr := fmt.Sprintf("%v",monthn) exist, exid := MonthExists(year,month) if exist { analysis[exid].Earnings += py.Amount }else{ analysis = append(analysis,Month{ month, monthstr, year, []int{}, py.Amount, //Earning 0.0, //Workhours []int{}, []int{}}) } } //fmt.Println("Length:",len(analysis)) ShowFullAnalysis() } //Show full analysis func ShowFullAnalysis() { fmt.Println(frame("Full Analysis",true)) for _,mo := range analysis { fmt.Println(sli,mo.Year,mo.MonthName) fmt.Printf("%s Workhours: %.2f\n",nli,mo.Workhours) fmt.Println(nli," Days:",mo.Days) cnt, hr, dur := AnalyzeTasks(GetSelectedTasks(mo.Tasks)) fmt.Println(nli," Tasks:",cnt,"Hours:", hr) fmt.Println(nli,dur) fmt.Println(nli,"Projects:",len(mo.Projects)) } fmt.Println(frame("",false)) } // Test if analysis slice conatins the month already and return its id if func MonthExists(year, month int) (exist bool, id int) { for i,mo := range analysis { if mo.Month == month && mo.Year == year { return true,i } } return false,-1 }