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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
// analyze.go contains all data analysis
package main
import (
"fmt"
)
// Daydata
type Daydata struct {
Day int
Taskcount int
Projectcount int
Workhours float64
Workvalue float64
}
// Data for Month
type Month struct {
Month int
MonthName string
Year int
Days []int
Daydatas []Daydata
Earnings float64
Workvalue float64
Workhours float64
//Workdays int
Tasks []int
Projects []int
}
// Yearly Data
type Year struct {
Year int
Months []int
Days []int
Earnings float64
Workvalue float64
Workhours float64
Tasks []int
Projects []int
}
func (d Daydata)Show()(out string){
out = fmt.Sprintf("%v. : %v Tasks in %v Projects: %.2f [h] for %.2f[€]",d.Day,d.Taskcount,d.Projectcount,d.Workhours,d.Workvalue)
return
}
var analysis []Month
var yearly []Year
//Analyze all tasks and PAyments
func MakeAnalysis() {
fmt.Println("Making Analysis")
analysis = nil
yearly = nil
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()
val := ta.Money()
if exist {
dex,dexid := DaydataExists(day,analysis[exid].Daydatas)
if !isElement(day,analysis[exid].Days){
analysis[exid].Days = append(analysis[exid].Days,day)
}else{
if dex {
analysis[exid].Daydatas[dexid].Workvalue += val
analysis[exid].Daydatas[dexid].Workhours += dur
analysis[exid].Daydatas[dexid].Taskcount += 1
}
}
analysis[exid].Workvalue += val
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{
if dex {
analysis[exid].Daydatas[dexid].Projectcount += 1
}
}
}else{
daydat := Daydata{day,1,1, dur,val}
analysis = append(analysis,Month{
month,
monthstr,
year,
[]int{day},
[]Daydata{daydat},
0.0, //Earning
val, // Workvalue
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{},
[]Daydata{},
py.Amount, //Earning
0.0, //Workvalue
0.0, //Workhours
[]int{},
[]int{}})
}
}
//fmt.Println("Length:",len(analysis))
for _,mo := range analysis {
exist,exid := YearExists(mo.Year)
if exist{
yearly[exid].Months = append(yearly[exid].Months,mo.Month)
yearly[exid].Days = append(yearly[exid].Days,mo.Days...)
//yearly[exid].Days = AddNewElement(yearly[exid].Days,mo.Days)
yearly[exid].Earnings += mo.Earnings
yearly[exid].Workvalue += mo.Workvalue
yearly[exid].Workhours += mo.Workhours
yearly[exid].Tasks = AddNewElement(yearly[exid].Tasks,mo.Tasks)
yearly[exid].Projects = AddNewElement(yearly[exid].Projects,mo.Projects)
}else{
yearly = append(yearly,Year{
mo.Year,
[]int{mo.Month},
mo.Days,
mo.Earnings,
mo.Workvalue,
mo.Workhours,
mo.Tasks,
mo.Projects})
}
}
// ShowMonthlyAnalysis()
// ShowYearlyAnalysis()
}
//Show Yearly analysis
func ShowYearlyAnalysis() {
fmt.Println(frame("Yearly Analysis",true))
for _,yr := range yearly {
cnt, hr, dur := AnalyzeTasks(GetSelectedTasks(yr.Tasks))
fmt.Println(sli,yr.Year)
fmt.Printf("%s Workhours: %.2f[h]\n",nli,yr.Workhours)
fmt.Printf("%s Earnings: %.2f[€]\n",nli,yr.Earnings)
fmt.Printf("%s %.2f[€/m]\n",nli,yr.Earnings/float64(len(yr.Months)))
fmt.Printf("%s Workvalue: %.2f[€]\n",nli,yr.Workvalue)
fmt.Printf("%s %.2f[€/m]\n",nli,yr.Workvalue/float64(len(yr.Months)))
fmt.Printf("%s Projects: %v\n",nli,len(yr.Projects))
fmt.Printf("%s Days: %v\n",nli,len(yr.Days))
fmt.Printf("%s Tasks: %v Hours: %.2f[h]\n",nli,cnt, hr)
fmt.Printf("%s %s\n",nli,dur)
fmt.Printf("%s Hourly Rate: %.2f[€/h]\n",nli,yr.Earnings/yr.Workhours)
fmt.Printf("%s Productivity: %.2f[h/d]\n",nli,yr.Workhours/float64(len(yr.Days)))
fmt.Printf("%s %.2f[h/m]\n",nli,yr.Workhours/float64(len(yr.Months)))
fmt.Printf("%s %.2f[d/m]\n",nli,float64(len(yr.Days))/float64(len(yr.Months)))
fmt.Println(nli)
}
fmt.Println(frame("",false))
}
//Show Mothly analysis
func ShowMonthlyAnalysis() {
fmt.Println(frame("Monthly Analysis",true))
for _,mo := range analysis {
cnt, hr, dur := AnalyzeTasks(GetSelectedTasks(mo.Tasks))
fmt.Println(sub(fmt.Sprint(mo.Year,mo.MonthName)))
fmt.Printf("%s Workhours: %.2f[h]\n",nli,mo.Workhours)
fmt.Printf("%s Earnings: %.2f[€]\n",nli,mo.Earnings)
fmt.Printf("%s Workvalue: %.2f[€]\n",nli,mo.Workvalue)
fmt.Printf("%s Projects: %v\n",nli,len(mo.Projects))
fmt.Printf("%s Days: %v\n",nli,len(mo.Days))
fmt.Printf("%s Tasks: %v Hours: %.2f[h]\n",nli,cnt, hr)
fmt.Printf("%s %s\n",nli,dur)
fmt.Printf("%s Hourly Rate: %.2f[€/h]\n",nli,mo.Earnings/mo.Workhours)
fmt.Printf("%s Productivity: %.2f[h/d]\n",nli,mo.Workhours/float64(len(mo.Days)))
fmt.Println(sli,"Days:")
for _,dt := range mo.Daydatas {
fmt.Println(nli,dt.Show())
}
fmt.Println(nli)
}
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
}
// Test if yearly slice conatins the year already and return its id if
func YearExists(year int) (exist bool, id int) {
for i,yr := range yearly {
if yr.Year == year {
return true,i
}
}
return false,-1
}
// Test if yearly slice conatins the year already and return its id if
func DaydataExists(day int, data []Daydata) (exist bool, id int) {
for i,dat := range data {
if dat.Day == day {
return true,i
}
}
return false,-1
}
|