2017-04-10 71 views
-4
def numbers = [[duration:1, calldate:6, disposition:1], [duration:1, calldate:6, disposition:1], [duration:2, calldate:7, disposition:2], [duration:2, calldate:7, disposition:2], [duration:1, calldate:7, disposition:1], [duration:1, calldate:7, disposition:1], [duration:2, calldate:7, disposition:2], [duration:2, calldate:7, disposition:2], [duration:2, calldate:7, disposition:2], [duration:1, calldate:7, disposition:1], [duration:2, calldate:7, disposition:2], [duration:1, calldate:8, disposition:1], [duration:2, calldate:8, disposition:2], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:2, calldate:8, disposition:2], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:2, calldate:8, disposition:2], [duration:1, calldate:8, disposition:1], [duration:2, calldate:8, disposition:2], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:2, calldate:8, disposition:2], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1], [duration:1, calldate:8, disposition:1]] 

numbers.eachWithIndex { item, i -> 


println "${numbers[i]} calldate: ${item.calldate} Duration:   ${item.duration} Disposition: ${item.disposition}" 

     }; 

我需要計算從持續時間和處置對象,但通話日期必須是唯一的計數在每一個循環的對象與常規

+0

你能提供預期輸出? – Ramsharan

回答

1
numbers.groupBy { 
    it.calldate 
}.sort().each{ 
    def duration = (it.value*.duration).sum() 
    def disposition = (it.value*.disposition).sum() 
    println "$it.key $duration $disposition" 
} 

輸出:

6 2 2 
    7 15 15 
    8 94 94