1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
// 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
}
|