-
Notifications
You must be signed in to change notification settings - Fork 1
/
CountTotalHours.groovy
51 lines (44 loc) · 1.36 KB
/
CountTotalHours.groovy
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
import groovy.time.TimeCategory
import org.freeplane.plugin.script.proxy.Proxy.Node
import pm.*
import java.text.DateFormat
import java.text.SimpleDateFormat
def Node root = node
def List<Node> nodes = root.getChildren()
def Integer timedTasksCount = 0
def Integer doneTasksCount = 0
def Float doneTimeCount = 0
def Float spentTimeCount = 0
def countTotal
countTotal = { List<Node> nds ->
def Float total = 0
for (Node n : nds) {
def t = Task.getTask(n)
if (t) {
total += t.getEstimatedTime()
timedTasksCount += 1
if (t.isDone()) {
doneTasksCount += 1
doneTimeCount += t.getEstimatedTime()
}
def tt = t.getTimeTable()
if (tt) {
def Float spentTime = tt.getSpentTime()
t.node["spentTime"] = spentTime
spentTimeCount += spentTime
}
}
if (!n.getChildren().empty) {
def innerTotal = countTotal(n.getChildren())
if (innerTotal != 0) n["total"] = innerTotal
total += innerTotal
}
}
return total
}
root["totalTime"] = countTotal(nodes)
root["tasks"] = timedTasksCount
root["doneTasks"] = doneTasksCount
root["done%"] = doneTimeCount / root["totalTime"].toFloat() * 100
root["doneTime"] = doneTimeCount
root["spentTime"] = spentTimeCount