瀏覽代碼

Fix burndown combination bugs

Signed-off-by: Vadim Markovtsev <vadim@sourced.tech>
Vadim Markovtsev 6 年之前
父節點
當前提交
32353779f6
共有 2 個文件被更改,包括 277 次插入116 次删除
  1. 62 69
      leaves/burndown.go
  2. 215 47
      leaves/burndown_test.go

+ 62 - 69
leaves/burndown.go

@@ -6,6 +6,7 @@ import (
 	"io"
 	"io"
 	"io/ioutil"
 	"io/ioutil"
 	"log"
 	"log"
+	"math"
 	"os"
 	"os"
 	"sort"
 	"sort"
 	"sync"
 	"sync"
@@ -166,6 +167,7 @@ const (
 type sparseHistory = map[int]map[int]int64
 type sparseHistory = map[int]map[int]int64
 
 
 // DenseHistory is the matrix [number of samples][number of bands] -> number of lines.
 // DenseHistory is the matrix [number of samples][number of bands] -> number of lines.
+//                                    y                  x
 type DenseHistory = [][]int64
 type DenseHistory = [][]int64
 
 
 // Name of this PipelineItem. Uniquely identifies the type, used for mapping keys, etc.
 // Name of this PipelineItem. Uniquely identifies the type, used for mapping keys, etc.
@@ -499,17 +501,20 @@ func (analyser *BurndownAnalysis) Finalize() interface{} {
 			}
 			}
 		}
 		}
 	}
 	}
-	peopleMatrix := make(DenseHistory, analyser.PeopleNumber)
-	for i, row := range analyser.matrix {
-		mrow := make([]int64, analyser.PeopleNumber+2)
-		peopleMatrix[i] = mrow
-		for key, val := range row {
-			if key == identity.AuthorMissing {
-				key = -1
-			} else if key == authorSelf {
-				key = -2
+	var peopleMatrix DenseHistory
+	if len(analyser.matrix) > 0 {
+		peopleMatrix = make(DenseHistory, analyser.PeopleNumber)
+		for i, row := range analyser.matrix {
+			mrow := make([]int64, analyser.PeopleNumber+2)
+			peopleMatrix[i] = mrow
+			for key, val := range row {
+				if key == identity.AuthorMissing {
+					key = -1
+				} else if key == authorSelf {
+					key = -2
+				}
+				mrow[key+2] = val
 			}
 			}
-			mrow[key+2] = val
 		}
 		}
 	}
 	}
 	return BurndownResult{
 	return BurndownResult{
@@ -608,54 +613,19 @@ func (analyser *BurndownAnalysis) MergeResults(
 				c1, c2)
 				c1, c2)
 		}()
 		}()
 	}
 	}
-	if len(bar1.FileHistories) > 0 || len(bar2.FileHistories) > 0 {
-		merged.FileHistories = map[string]DenseHistory{}
-		historyMutex := sync.Mutex{}
-		for key, fh1 := range bar1.FileHistories {
-			if fh2, exists := bar2.FileHistories[key]; exists {
-				wg.Add(1)
-				go func(fh1, fh2 DenseHistory, key string) {
-					defer wg.Done()
-					historyMutex.Lock()
-					defer historyMutex.Unlock()
-					merged.FileHistories[key] = mergeMatrices(
-						fh1, fh2, bar1.granularity, bar1.sampling, bar2.granularity, bar2.sampling, c1, c2)
-				}(fh1, fh2, key)
-			} else {
-				historyMutex.Lock()
-				merged.FileHistories[key] = fh1
-				historyMutex.Unlock()
-			}
-		}
-		for key, fh2 := range bar2.FileHistories {
-			if _, exists := bar1.FileHistories[key]; !exists {
-				historyMutex.Lock()
-				merged.FileHistories[key] = fh2
-				historyMutex.Unlock()
-			}
-		}
-	}
 	if len(merged.reversedPeopleDict) > 0 {
 	if len(merged.reversedPeopleDict) > 0 {
-		merged.PeopleHistories = make([]DenseHistory, len(merged.reversedPeopleDict))
-		for i, key := range merged.reversedPeopleDict {
-			ptrs := people[key]
-			if ptrs[1] < 0 {
-				if len(bar2.PeopleHistories) > 0 {
-					merged.PeopleHistories[i] = bar2.PeopleHistories[ptrs[2]]
-				}
-			} else if ptrs[2] < 0 {
-				if len(bar1.PeopleHistories) > 0 {
-					merged.PeopleHistories[i] = bar1.PeopleHistories[ptrs[1]]
-				}
-			} else {
+		if len(bar1.PeopleHistories) > 0 || len(bar2.PeopleHistories) > 0 {
+			merged.PeopleHistories = make([]DenseHistory, len(merged.reversedPeopleDict))
+			for i, key := range merged.reversedPeopleDict {
+				ptrs := people[key]
 				wg.Add(1)
 				wg.Add(1)
 				go func(i int) {
 				go func(i int) {
 					defer wg.Done()
 					defer wg.Done()
 					var m1, m2 DenseHistory
 					var m1, m2 DenseHistory
-					if len(bar1.PeopleHistories) > 0 {
+					if ptrs[1] >= 0 {
 						m1 = bar1.PeopleHistories[ptrs[1]]
 						m1 = bar1.PeopleHistories[ptrs[1]]
 					}
 					}
-					if len(bar2.PeopleHistories) > 0 {
+					if ptrs[2] >= 0 {
 						m2 = bar2.PeopleHistories[ptrs[2]]
 						m2 = bar2.PeopleHistories[ptrs[2]]
 					}
 					}
 					merged.PeopleHistories[i] = mergeMatrices(
 					merged.PeopleHistories[i] = mergeMatrices(
@@ -678,9 +648,11 @@ func (analyser *BurndownAnalysis) MergeResults(
 						merged.PeopleMatrix[i] = append(merged.PeopleMatrix[i], 0)
 						merged.PeopleMatrix[i] = append(merged.PeopleMatrix[i], 0)
 					}
 					}
 				}
 				}
-				for i := len(bar1.reversedPeopleDict); i < len(merged.reversedPeopleDict); i++ {
-					merged.PeopleMatrix = append(
-						merged.PeopleMatrix, make([]int64, len(merged.reversedPeopleDict)+2))
+				if len(bar1.PeopleMatrix) > 0 {
+					for i := len(bar1.reversedPeopleDict); i < len(merged.reversedPeopleDict); i++ {
+						merged.PeopleMatrix = append(
+							merged.PeopleMatrix, make([]int64, len(merged.reversedPeopleDict)+2))
+					}
 				}
 				}
 			} else {
 			} else {
 				merged.PeopleMatrix = make(DenseHistory, len(merged.reversedPeopleDict))
 				merged.PeopleMatrix = make(DenseHistory, len(merged.reversedPeopleDict))
@@ -709,6 +681,14 @@ func (analyser *BurndownAnalysis) MergeResults(
 	return merged
 	return merged
 }
 }
 
 
+func roundTime(unix int64, dir bool) int {
+	days := float64(unix) / (3600 * 24)
+	if dir {
+		return int(math.Ceil(days))
+	}
+	return int(math.Floor(days))
+}
+
 // mergeMatrices takes two [number of samples][number of bands] matrices,
 // mergeMatrices takes two [number of samples][number of bands] matrices,
 // resamples them to days so that they become square, sums and resamples back to the
 // resamples them to days so that they become square, sums and resamples back to the
 // least of (sampling1, sampling2) and (granularity1, granularity2).
 // least of (sampling1, sampling2) and (granularity1, granularity2).
@@ -729,31 +709,28 @@ func mergeMatrices(m1, m2 DenseHistory, granularity1, sampling1, granularity2, s
 		granularity = granularity2
 		granularity = granularity2
 	}
 	}
 
 
-	size := int((commonMerged.EndTime - commonMerged.BeginTime) / (3600 * 24))
-	daily := make([][]float32, size+granularity+1)
+	size := roundTime(commonMerged.EndTime, true) - roundTime(commonMerged.BeginTime, false)
+	daily := make([][]float32, size+granularity)
 	for i := range daily {
 	for i := range daily {
-		daily[i] = make([]float32, size+sampling+1)
+		daily[i] = make([]float32, size+sampling)
 	}
 	}
 	if len(m1) > 0 {
 	if len(m1) > 0 {
 		addBurndownMatrix(m1, granularity1, sampling1, daily,
 		addBurndownMatrix(m1, granularity1, sampling1, daily,
-			int(c1.BeginTime-commonMerged.BeginTime)/(3600*24))
+			roundTime(c1.BeginTime, false)-roundTime(commonMerged.BeginTime, false))
 	}
 	}
 	if len(m2) > 0 {
 	if len(m2) > 0 {
 		addBurndownMatrix(m2, granularity2, sampling2, daily,
 		addBurndownMatrix(m2, granularity2, sampling2, daily,
-			int(c2.BeginTime-commonMerged.BeginTime)/(3600*24))
+			roundTime(c2.BeginTime, false)-roundTime(commonMerged.BeginTime, false))
 	}
 	}
 
 
 	// convert daily to [][]int64
 	// convert daily to [][]int64
 	result := make(DenseHistory, (size+sampling-1)/sampling)
 	result := make(DenseHistory, (size+sampling-1)/sampling)
 	for i := range result {
 	for i := range result {
 		result[i] = make([]int64, (size+granularity-1)/granularity)
 		result[i] = make([]int64, (size+granularity-1)/granularity)
-		sampledIndex := i * sampling
-		if i == len(result)-1 {
-			sampledIndex = size - 1
-		}
+		sampledIndex := (i+1)*sampling - 1
 		for j := 0; j < len(result[i]); j++ {
 		for j := 0; j < len(result[i]); j++ {
 			accum := float32(0)
 			accum := float32(0)
-			for k := j * granularity; k < (j+1)*granularity && k < size; k++ {
+			for k := j * granularity; k < (j+1)*granularity; k++ {
 				accum += daily[sampledIndex][k]
 				accum += daily[sampledIndex][k]
 			}
 			}
 			result[i][j] = int64(accum)
 			result[i][j] = int64(accum)
@@ -768,7 +745,7 @@ func mergeMatrices(m1, m2 DenseHistory, granularity1, sampling1, granularity2, s
 // Rows: *at least* len(matrix) * sampling + offset
 // Rows: *at least* len(matrix) * sampling + offset
 // Columns: *at least* len(matrix[...]) * granularity + offset
 // Columns: *at least* len(matrix[...]) * granularity + offset
 // `matrix` can be sparse, so that the last columns which are equal to 0 are truncated.
 // `matrix` can be sparse, so that the last columns which are equal to 0 are truncated.
-func addBurndownMatrix(matrix DenseHistory, granularity, sampling int, daily [][]float32, offset int) {
+func addBurndownMatrix(matrix DenseHistory, granularity, sampling int, accdaily [][]float32, offset int) {
 	// Determine the maximum number of bands; the actual one may be larger but we do not care
 	// Determine the maximum number of bands; the actual one may be larger but we do not care
 	maxCols := 0
 	maxCols := 0
 	for _, row := range matrix {
 	for _, row := range matrix {
@@ -777,13 +754,17 @@ func addBurndownMatrix(matrix DenseHistory, granularity, sampling int, daily [][
 		}
 		}
 	}
 	}
 	neededRows := len(matrix)*sampling + offset
 	neededRows := len(matrix)*sampling + offset
-	if len(daily) < neededRows {
+	if len(accdaily) < neededRows {
 		log.Panicf("merge bug: too few daily rows: required %d, have %d",
 		log.Panicf("merge bug: too few daily rows: required %d, have %d",
-			neededRows, len(daily))
+			neededRows, len(accdaily))
 	}
 	}
-	if len(daily[0]) < maxCols {
+	if len(accdaily[0]) < maxCols {
 		log.Panicf("merge bug: too few daily cols: required %d, have %d",
 		log.Panicf("merge bug: too few daily cols: required %d, have %d",
-			maxCols, len(daily[0]))
+			maxCols, len(accdaily[0]))
+	}
+	daily := make([][]float32, len(accdaily))
+	for i, row := range accdaily {
+		daily[i] = make([]float32, len(row))
 	}
 	}
 	for x := 0; x < maxCols; x++ {
 	for x := 0; x < maxCols; x++ {
 		for y := 0; y < len(matrix); y++ {
 		for y := 0; y < len(matrix); y++ {
@@ -921,6 +902,16 @@ func addBurndownMatrix(matrix DenseHistory, granularity, sampling int, daily [][
 			}
 			}
 		}
 		}
 	}
 	}
+	for y := len(matrix) * sampling; y+offset < len(daily); y++ {
+		copy(daily[y+offset], daily[len(matrix)*sampling-1+offset])
+	}
+	// the original matrix has been resampled by day
+	// add it to the accumulator
+	for y, row := range daily {
+		for x, val := range row {
+			accdaily[y][x] += val
+		}
+	}
 }
 }
 
 
 func (analyser *BurndownAnalysis) serializeText(result *BurndownResult, writer io.Writer) {
 func (analyser *BurndownAnalysis) serializeText(result *BurndownResult, writer io.Writer) {
@@ -976,6 +967,8 @@ func (analyser *BurndownAnalysis) serializeBinary(result *BurndownResult, writer
 				message.People[key] = pb.ToBurndownSparseMatrix(val, result.reversedPeopleDict[key])
 				message.People[key] = pb.ToBurndownSparseMatrix(val, result.reversedPeopleDict[key])
 			}
 			}
 		}
 		}
+	}
+	if result.PeopleMatrix != nil {
 		message.PeopleInteraction = pb.DenseToCompressedSparseRowMatrix(result.PeopleMatrix)
 		message.PeopleInteraction = pb.DenseToCompressedSparseRowMatrix(result.PeopleMatrix)
 	}
 	}
 	serialized, err := proto.Marshal(&message)
 	serialized, err := proto.Marshal(&message)

+ 215 - 47
leaves/burndown_test.go

@@ -2,6 +2,7 @@ package leaves
 
 
 import (
 import (
 	"bytes"
 	"bytes"
+	"fmt"
 	"io"
 	"io"
 	"io/ioutil"
 	"io/ioutil"
 	"path"
 	"path"
@@ -949,8 +950,6 @@ func TestBurndownMergeGlobalHistory(t *testing.T) {
 			res1.GlobalHistory[i][2] = 150
 			res1.GlobalHistory[i][2] = 150
 		}
 		}
 	}
 	}
-	res1.FileHistories["file1"] = res1.GlobalHistory
-	res1.FileHistories["file2"] = res1.GlobalHistory
 	res1.PeopleHistories = append(res1.PeopleHistories, res1.GlobalHistory)
 	res1.PeopleHistories = append(res1.PeopleHistories, res1.GlobalHistory)
 	res1.PeopleHistories = append(res1.PeopleHistories, res1.GlobalHistory)
 	res1.PeopleHistories = append(res1.PeopleHistories, res1.GlobalHistory)
 	res1.PeopleMatrix = append(res1.PeopleMatrix, make([]int64, 4))
 	res1.PeopleMatrix = append(res1.PeopleMatrix, make([]int64, 4))
@@ -965,10 +964,10 @@ func TestBurndownMergeGlobalHistory(t *testing.T) {
 	res1.PeopleMatrix[1][3] = 80
 	res1.PeopleMatrix[1][3] = 80
 	people2 := [...]string{"two", "three"}
 	people2 := [...]string{"two", "three"}
 	res2 := BurndownResult{
 	res2 := BurndownResult{
-		GlobalHistory:      [][]int64{},
+		GlobalHistory:      nil,
 		FileHistories:      map[string][][]int64{},
 		FileHistories:      map[string][][]int64{},
-		PeopleHistories:    [][][]int64{},
-		PeopleMatrix:       [][]int64{},
+		PeopleHistories:    nil,
+		PeopleMatrix:       nil,
 		reversedPeopleDict: people2[:],
 		reversedPeopleDict: people2[:],
 		sampling:           14,
 		sampling:           14,
 		granularity:        19,
 		granularity:        19,
@@ -999,8 +998,6 @@ func TestBurndownMergeGlobalHistory(t *testing.T) {
 			res2.GlobalHistory[i][2] = 600
 			res2.GlobalHistory[i][2] = 600
 		}
 		}
 	}
 	}
-	res2.FileHistories["file2"] = res2.GlobalHistory
-	res2.FileHistories["file3"] = res2.GlobalHistory
 	res2.PeopleHistories = append(res2.PeopleHistories, res2.GlobalHistory)
 	res2.PeopleHistories = append(res2.PeopleHistories, res2.GlobalHistory)
 	res2.PeopleHistories = append(res2.PeopleHistories, res2.GlobalHistory)
 	res2.PeopleHistories = append(res2.PeopleHistories, res2.GlobalHistory)
 	res2.PeopleMatrix = append(res2.PeopleMatrix, make([]int64, 4))
 	res2.PeopleMatrix = append(res2.PeopleMatrix, make([]int64, 4))
@@ -1021,13 +1018,11 @@ func TestBurndownMergeGlobalHistory(t *testing.T) {
 	for _, row := range merged.GlobalHistory {
 	for _, row := range merged.GlobalHistory {
 		assert.Len(t, row, 4)
 		assert.Len(t, row, 4)
 	}
 	}
-	assert.Equal(t, merged.FileHistories["file1"], res1.GlobalHistory)
-	assert.Equal(t, merged.FileHistories["file2"], merged.GlobalHistory)
-	assert.Equal(t, merged.FileHistories["file3"], res2.GlobalHistory)
+	assert.Nil(t, merged.FileHistories)
 	assert.Len(t, merged.reversedPeopleDict, 3)
 	assert.Len(t, merged.reversedPeopleDict, 3)
-	assert.Equal(t, merged.PeopleHistories[0], res1.GlobalHistory)
+	assert.NotEqual(t, merged.PeopleHistories[0], res1.GlobalHistory)
 	assert.Equal(t, merged.PeopleHistories[1], merged.GlobalHistory)
 	assert.Equal(t, merged.PeopleHistories[1], merged.GlobalHistory)
-	assert.Equal(t, merged.PeopleHistories[2], res2.GlobalHistory)
+	assert.NotEqual(t, merged.PeopleHistories[2], res2.GlobalHistory)
 	assert.Len(t, merged.PeopleMatrix, 3)
 	assert.Len(t, merged.PeopleMatrix, 3)
 	for _, row := range merged.PeopleMatrix {
 	for _, row := range merged.PeopleMatrix {
 		assert.Len(t, row, 5)
 		assert.Len(t, row, 5)
@@ -1049,16 +1044,16 @@ func TestBurndownMergeGlobalHistory(t *testing.T) {
 	assert.Equal(t, merged.PeopleMatrix[2][2], int64(0))
 	assert.Equal(t, merged.PeopleMatrix[2][2], int64(0))
 	assert.Equal(t, merged.PeopleMatrix[2][3], int64(700))
 	assert.Equal(t, merged.PeopleMatrix[2][3], int64(700))
 	assert.Equal(t, merged.PeopleMatrix[2][4], int64(800))
 	assert.Equal(t, merged.PeopleMatrix[2][4], int64(800))
-	burndown.serializeBinary(&merged, ioutil.Discard)
+	assert.Nil(t, burndown.serializeBinary(&merged, ioutil.Discard))
 }
 }
 
 
 func TestBurndownMergeNils(t *testing.T) {
 func TestBurndownMergeNils(t *testing.T) {
 	res1 := BurndownResult{
 	res1 := BurndownResult{
-		GlobalHistory:      [][]int64{},
+		GlobalHistory:      nil,
 		FileHistories:      map[string][][]int64{},
 		FileHistories:      map[string][][]int64{},
-		PeopleHistories:    [][][]int64{},
-		PeopleMatrix:       [][]int64{},
-		reversedPeopleDict: []string{},
+		PeopleHistories:    nil,
+		PeopleMatrix:       nil,
+		reversedPeopleDict: nil,
 		sampling:           15,
 		sampling:           15,
 		granularity:        20,
 		granularity:        20,
 	}
 	}
@@ -1091,27 +1086,15 @@ func TestBurndownMergeNils(t *testing.T) {
 	assert.Nil(t, merged.FileHistories)
 	assert.Nil(t, merged.FileHistories)
 	assert.Nil(t, merged.PeopleHistories)
 	assert.Nil(t, merged.PeopleHistories)
 	assert.Nil(t, merged.PeopleMatrix)
 	assert.Nil(t, merged.PeopleMatrix)
-	burndown.serializeBinary(&merged, ioutil.Discard)
+	assert.Nil(t, burndown.serializeBinary(&merged, ioutil.Discard))
 
 
-	res2.GlobalHistory = make([][]int64, 56/14 /* 4 samples */)
-	for i := range res2.GlobalHistory {
-		res2.GlobalHistory[i] = make([]int64, 56/19+1 /* 3 bands */)
-		switch i {
-		case 0:
-			res2.GlobalHistory[i][0] = 900
-		case 1:
-			res2.GlobalHistory[i][0] = 1100
-			res2.GlobalHistory[i][1] = 400
-		case 2:
-			res2.GlobalHistory[i][0] = 900
-			res2.GlobalHistory[i][1] = 750
-			res2.GlobalHistory[i][2] = 100
-		case 3:
-			res2.GlobalHistory[i][0] = 800
-			res2.GlobalHistory[i][1] = 600
-			res2.GlobalHistory[i][2] = 600
-		}
+	res2.GlobalHistory = [][]int64{
+		{900, 0, 0},
+		{1100, 400, 0},
+		{900, 750, 100},
+		{800, 600, 600},
 	}
 	}
+	res2.FileHistories = map[string]DenseHistory{"test": res2.GlobalHistory}
 	people1 := [...]string{"one", "two"}
 	people1 := [...]string{"one", "two"}
 	res1.reversedPeopleDict = people1[:]
 	res1.reversedPeopleDict = people1[:]
 	res1.PeopleMatrix = append(res1.PeopleMatrix, make([]int64, 4))
 	res1.PeopleMatrix = append(res1.PeopleMatrix, make([]int64, 4))
@@ -1127,18 +1110,17 @@ func TestBurndownMergeNils(t *testing.T) {
 	people2 := [...]string{"two", "three"}
 	people2 := [...]string{"two", "three"}
 	res2.reversedPeopleDict = people2[:]
 	res2.reversedPeopleDict = people2[:]
 	merged = burndown.MergeResults(res1, res2, &c1, &c2).(BurndownResult)
 	merged = burndown.MergeResults(res1, res2, &c1, &c2).(BurndownResult)
-	mgh := [5][4]int64{
-		{0, 0, 0, 0},
-		{578, 0, 0, 0},
-		{798, 546, 0, 0},
-		{664, 884, 222, 0},
+	// calculated in a spreadsheet
+	mgh := [][]int64{
+		{514, 0, 0, 0},
+		{808, 506, 0, 0},
+		{674, 889, 177, 0},
+		{576, 720, 595, 0},
 		{547, 663, 610, 178},
 		{547, 663, 610, 178},
 	}
 	}
-	mgh2 := [...][]int64{
-		mgh[0][:], mgh[1][:], mgh[2][:], mgh[3][:], mgh[4][:],
-	}
-	mgh3 := mgh2[:]
-	assert.Equal(t, mgh3, merged.GlobalHistory)
+	assert.Equal(t, mgh, merged.GlobalHistory)
+	assert.Nil(t, merged.FileHistories)
+	assert.Nil(t, merged.PeopleHistories)
 	assert.Len(t, merged.PeopleMatrix, 3)
 	assert.Len(t, merged.PeopleMatrix, 3)
 	for _, row := range merged.PeopleMatrix {
 	for _, row := range merged.PeopleMatrix {
 		assert.Len(t, row, 5)
 		assert.Len(t, row, 5)
@@ -1160,7 +1142,7 @@ func TestBurndownMergeNils(t *testing.T) {
 	assert.Equal(t, merged.PeopleMatrix[2][2], int64(0))
 	assert.Equal(t, merged.PeopleMatrix[2][2], int64(0))
 	assert.Equal(t, merged.PeopleMatrix[2][3], int64(0))
 	assert.Equal(t, merged.PeopleMatrix[2][3], int64(0))
 	assert.Equal(t, merged.PeopleMatrix[2][4], int64(0))
 	assert.Equal(t, merged.PeopleMatrix[2][4], int64(0))
-	burndown.serializeBinary(&merged, ioutil.Discard)
+	assert.Nil(t, burndown.serializeBinary(&merged, ioutil.Discard))
 }
 }
 
 
 func TestBurndownDeserialize(t *testing.T) {
 func TestBurndownDeserialize(t *testing.T) {
@@ -1241,3 +1223,189 @@ func TestBurndownHibernateBootSerialize(t *testing.T) {
 	assert.Equal(t, burndown.fileAllocator.Used(), 155)
 	assert.Equal(t, burndown.fileAllocator.Used(), 155)
 	assert.Empty(t, burndown.hibernatedFileName)
 	assert.Empty(t, burndown.hibernatedFileName)
 }
 }
+
+func TestBurndownAddBurndownMatrix(t *testing.T) {
+	h := DenseHistory{
+		[]int64{13430, 0, 0, 0},
+		[]int64{7698, 23316, 0, 0},
+		[]int64{7181, 18750, 55841, 0},
+		[]int64{6345, 16704, 17110, 55981},
+	}
+	daily := make([][]float32, 4*30)
+	for i := range daily {
+		daily[i] = make([]float32, 4*30)
+	}
+	addBurndownMatrix(h, 30, 30, daily, 0)
+	sum := func(x, y int) int64 {
+		var accum float32
+		row := (y+1)*30 - 1
+		offset := x * 30
+		for i := offset; i < offset+30; i++ {
+			accum += daily[row][i]
+		}
+		return int64(accum)
+	}
+	for y, row := range h {
+		for x, val := range row {
+			assert.InDelta(t, sum(x, y), val, 1)
+		}
+	}
+}
+
+func TestBurndownMergeMatrices(t *testing.T) {
+	h := DenseHistory{
+		[]int64{13430, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{7698, 23316, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{7181, 18750, 55841, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{6345, 16704, 17110, 55981, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{6191, 15805, 15006, 41212, 26384, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{6020, 14760, 13000, 16292, 18157, 58615, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{5885, 14506, 11934, 15229, 16026, 54157, 27561, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{5684, 13997, 11588, 14939, 13034, 27032, 22242, 46431, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{5469, 13635, 11188, 13864, 12159, 25496, 20517, 42373, 62033, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{5431, 13088, 10608, 12546, 10615, 20405, 15111, 16412, 52677, 49573, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{4745, 12649, 9321, 11041, 9373, 12969, 11185, 14161, 38560, 43302, 24281, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{4546, 12540, 9205, 10621, 9038, 12728, 10760, 13651, 36806, 42229, 17719, 15903, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{3272, 7972, 4706, 8728, 4948, 11527, 4744, 7395, 29937, 38897, 8874, 7898, 46522, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{3136, 7653, 4434, 7760, 4113, 11325, 3855, 6988, 27395, 37709, 7983, 7467, 42685, 29844, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{2608, 5432, 4096, 7465, 3539, 11005, 3625, 5963, 19364, 36904, 7426, 6491, 36095, 25025, 22280, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{2157, 4033, 3000, 6968, 3186, 9687, 3191, 4955, 16729, 35998, 7200, 6372, 34196, 21592, 18757, 25304, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1887, 3847, 2939, 6573, 2829, 9496, 3050, 4829, 16312, 29070, 6910, 6270, 33138, 19577, 18101, 22819, 39223, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1869, 3660, 2634, 5744, 2478, 9265, 2876, 4442, 10362, 28338, 5908, 5266, 26172, 17293, 14834, 19263, 37511, 36830, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1860, 3642, 2589, 5717, 2410, 9237, 2836, 4278, 8712, 28152, 5458, 4970, 24725, 16106, 14158, 18201, 36032, 32884, 26193, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1840, 3622, 2533, 5545, 2274, 8955, 2783, 4247, 8467, 27810, 5068, 4864, 23757, 14822, 13453, 16199, 29994, 30955, 23038, 25745, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1782, 3429, 2459, 5362, 2160, 8526, 2473, 3237, 7238, 27376, 4899, 3839, 20857, 13491, 11719, 15045, 28905, 26343, 19202, 20732, 41048, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1535, 2608, 1800, 5012, 1882, 8261, 2373, 1846, 5039, 27180, 4522, 3464, 15816, 11562, 9868, 13729, 27709, 21367, 15626, 18095, 33529, 44821, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1524, 2598, 1798, 4847, 1862, 8233, 2354, 1791, 5005, 26743, 4218, 3358, 15241, 10329, 9304, 12594, 27478, 20230, 15011, 17382, 31331, 41415, 24488, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1474, 2532, 1795, 4260, 1756, 8125, 2344, 1627, 4879, 26543, 4134, 3198, 14132, 9776, 9175, 12243, 27019, 19818, 13999, 16697, 29687, 37543, 23669, 13238, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1427, 2507, 1778, 4192, 1718, 8102, 2326, 1554, 4818, 9726, 3963, 3099, 13642, 9523, 8975, 11940, 8967, 19035, 13584, 15627, 28388, 35931, 22954, 12218, 51230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1414, 2266, 1759, 3924, 1613, 8083, 2302, 1522, 4590, 9396, 3835, 2987, 12616, 9076, 8538, 11603, 8664, 18267, 13011, 14926, 26676, 34225, 22091, 9581, 48080, 29792, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1394, 2243, 1731, 3911, 1594, 7911, 2284, 1518, 4544, 8452, 3832, 2975, 12533, 8875, 8238, 11274, 8467, 16358, 12471, 14468, 25468, 33459, 21417, 9267, 30708, 28383, 30913, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1393, 2243, 1728, 3902, 1591, 7899, 2248, 1463, 4503, 8445, 3677, 2872, 12271, 8779, 8127, 11118, 8436, 16271, 12229, 14177, 24719, 31578, 21036, 8874, 29685, 26663, 29919, 20499, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1390, 2131, 1663, 3863, 1564, 7873, 2242, 1422, 4476, 8385, 3669, 2856, 12197, 8650, 7932, 10844, 8202, 16149, 12065, 13529, 24289, 30669, 20806, 8701, 29238, 25926, 27111, 19383, 53864, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1390, 2116, 1663, 3848, 1531, 7852, 2232, 1417, 4472, 8335, 3544, 1524, 11920, 8635, 7860, 10726, 8064, 14483, 11369, 5956, 22559, 28467, 20308, 7767, 28403, 24070, 26682, 17395, 51966, 23389, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1388, 2113, 1626, 3832, 1524, 7840, 2232, 1407, 4460, 8292, 3534, 1489, 11307, 8602, 7794, 10671, 7996, 14393, 11339, 5915, 22253, 28291, 20214, 7729, 28344, 23585, 26486, 17152, 51532, 22845, 22435, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1386, 2110, 1558, 3823, 1518, 7745, 2232, 1087, 4404, 8082, 3382, 1316, 11080, 8229, 6774, 9887, 7855, 14086, 10997, 5158, 16647, 27042, 19173, 7345, 27367, 21983, 25194, 13957, 48597, 21030, 22008, 54558, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1379, 2105, 1557, 3740, 1488, 7621, 2200, 1080, 4370, 7820, 3338, 1293, 10279, 8180, 6417, 9686, 7767, 13410, 10762, 4678, 15603, 26465, 18850, 7169, 9580, 20556, 10501, 13019, 42837, 19989, 19586, 42354, 60288, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1379, 2103, 1557, 3740, 1482, 7615, 2082, 762, 4316, 7806, 3222, 1293, 10070, 7684, 5422, 8902, 7588, 13136, 10382, 3847, 9978, 25574, 17809, 6799, 8567, 18272, 9149, 9626, 40377, 18337, 19295, 41783, 58014, 33979, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1375, 2102, 1555, 3653, 1480, 7606, 2029, 756, 4312, 7795, 3222, 1291, 10011, 7669, 5390, 8851, 7580, 13132, 10376, 3768, 9898, 25298, 17522, 6415, 8526, 17475, 9113, 9269, 39856, 18230, 19197, 41134, 57566, 33320, 8047, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1375, 2102, 1555, 3651, 1480, 7606, 2029, 756, 4312, 7795, 3222, 1291, 10010, 7666, 5385, 8851, 7580, 13117, 10376, 3767, 9880, 25298, 17517, 6415, 8515, 17457, 9104, 9238, 39852, 18184, 19147, 41123, 57518, 33264, 8033, 941, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1370, 2099, 1498, 3523, 1474, 7605, 2009, 756, 4264, 7582, 3171, 1289, 9707, 7421, 5212, 8624, 7428, 12473, 10168, 3589, 9523, 24409, 17406, 6134, 8279, 16596, 9016, 9128, 39152, 17615, 19102, 36069, 56969, 32962, 7903, 927, 264665, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1109, 1678, 1236, 3409, 1440, 7406, 1974, 753, 4156, 7545, 3115, 1260, 9570, 7197, 4876, 7510, 6892, 11915, 9497, 2961, 8319, 23488, 15831, 5793, 7703, 8839, 8705, 7206, 36800, 16372, 17816, 34229, 55779, 26494, 7514, 814, 263077, 292742, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1099, 1662, 1226, 3151, 1399, 7369, 1912, 747, 4073, 7359, 3091, 1228, 9491, 6991, 4661, 7381, 6824, 11587, 9313, 2821, 7502, 22897, 15583, 5626, 7603, 8070, 8472, 6915, 36110, 16001, 17580, 33765, 55121, 26096, 7278, 761, 262798, 290965, 30113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1045, 1658, 1222, 3124, 1365, 7133, 1854, 739, 3869, 7002, 3071, 1156, 8935, 6797, 4353, 6980, 6690, 11369, 8921, 2244, 6801, 22237, 14775, 5138, 7370, 6502, 8039, 6595, 34778, 14976, 16851, 32794, 54195, 24775, 6683, 748, 136421, 286458, 27127, 154181, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1042, 1658, 1222, 3108, 1300, 7126, 1853, 719, 3763, 6987, 3062, 1153, 8915, 6557, 4203, 6906, 6387, 11159, 8602, 2103, 5919, 20200, 14394, 3729, 6571, 5697, 7380, 5954, 32604, 13465, 16498, 28686, 53547, 24057, 6570, 690, 130726, 285240, 25497, 35819, 38609, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1042, 1657, 1209, 3088, 1295, 7114, 1849, 686, 3592, 4745, 2926, 1038, 8292, 5755, 3580, 6552, 6078, 10321, 7821, 1661, 5568, 19864, 13563, 3122, 6175, 5396, 6831, 5035, 32307, 13088, 16006, 27828, 50777, 23149, 6182, 601, 130329, 283925, 23394, 31912, 28622, 47146, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{1001, 1617, 1154, 2933, 1290, 7054, 1837, 676, 3487, 3203, 2268, 905, 7953, 5673, 3431, 4772, 5407, 9200, 7453, 939, 4947, 19334, 13054, 2401, 5316, 3768, 3949, 4580, 31317, 12444, 15323, 26602, 49590, 22753, 5702, 572, 26696, 275964, 22184, 27561, 26049, 24501, 194501, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{997, 1614, 1148, 2902, 1247, 6786, 1761, 672, 3401, 2938, 2248, 890, 7233, 5645, 3383, 4644, 5198, 8926, 7162, 208, 4231, 18575, 12876, 2012, 5196, 1806, 3731, 4451, 29976, 11199, 13122, 25866, 46032, 22122, 4663, 559, 24258, 274857, 21675, 26662, 24590, 21522, 191082, 39811, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{996, 1614, 1148, 2897, 1235, 6776, 1761, 672, 3400, 2937, 2248, 890, 7177, 5643, 3360, 4631, 5187, 8788, 7156, 202, 4205, 18484, 12861, 1969, 5183, 1578, 3674, 4281, 29948, 11147, 13094, 25801, 45910, 21985, 4647, 559, 24203, 274714, 20945, 26380, 24366, 20885, 190910, 37655, 35516, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{996, 1612, 1135, 2886, 1235, 6770, 1756, 672, 3398, 2927, 2246, 889, 7170, 5557, 3352, 4576, 5013, 8754, 7155, 149, 4163, 18382, 12834, 1937, 4732, 1459, 3633, 4270, 29914, 11131, 13086, 25774, 45895, 21946, 4617, 553, 24178, 274369, 20853, 25969, 23513, 20144, 188818, 34194, 33294, 24826, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{995, 1610, 1134, 2885, 1227, 6764, 1754, 672, 3385, 2921, 2231, 889, 7169, 5531, 3336, 4548, 4856, 8706, 7134, 126, 4152, 18327, 12772, 1912, 4720, 1449, 3600, 4246, 29899, 11081, 13037, 25513, 45806, 21900, 4613, 553, 24140, 274216, 20635, 25858, 23281, 19924, 188450, 33878, 33100, 24496, 8738, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{992, 1610, 1134, 2885, 1227, 6754, 1754, 670, 3384, 2920, 2230, 889, 7156, 5523, 3336, 4545, 4831, 8692, 7124, 113, 4137, 18316, 12758, 1907, 4711, 1447, 3598, 4181, 29892, 11042, 13029, 25345, 45768, 21865, 4587, 553, 24135, 274146, 20566, 25732, 23088, 19794, 188302, 33520, 32831, 24273, 8042, 8540, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{991, 1608, 1133, 2737, 1224, 6735, 1754, 670, 3377, 2918, 2228, 889, 7145, 5438, 3320, 4518, 4613, 8624, 7114, 76, 4088, 18155, 12692, 1906, 4686, 1401, 3551, 4112, 29826, 10930, 13006, 25072, 45665, 21819, 4567, 539, 24083, 274046, 20388, 25299, 22340, 19444, 188132, 32795, 31377, 22972, 7705, 8119, 80636, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{989, 1601, 1132, 2735, 1224, 6735, 1754, 669, 3377, 2918, 2220, 888, 7094, 5411, 3314, 4491, 4558, 8615, 7085, 39, 3625, 18062, 12620, 1904, 4622, 1359, 3523, 4060, 29711, 10795, 12978, 24990, 45607, 21774, 4499, 528, 23956, 272619, 20261, 25201, 21853, 18608, 176147, 32404, 30632, 22515, 7013, 6830, 78714, 37873, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{984, 1597, 1132, 2734, 1213, 6734, 1751, 667, 3374, 2917, 2215, 888, 7055, 5378, 3259, 4440, 4539, 8574, 7010, 2, 3567, 16954, 12516, 1823, 4468, 1264, 3471, 3967, 29669, 10711, 12929, 24918, 45543, 21645, 4487, 526, 14508, 272464, 19936, 22042, 21435, 18484, 80372, 31942, 30300, 20509, 6910, 6488, 76858, 36148, 93628, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{984, 1597, 1132, 2734, 1213, 6734, 1751, 667, 3373, 2915, 2214, 888, 7053, 5361, 3248, 4428, 4536, 8549, 6987, 0, 3557, 16871, 12496, 1820, 4457, 1236, 3453, 3966, 29667, 10670, 12881, 24880, 45531, 21638, 4485, 521, 14450, 272424, 19880, 21565, 20920, 18335, 80100, 31675, 30111, 20472, 6874, 6247, 76447, 35839, 93226, 10524, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{982, 1593, 1131, 2727, 1024, 6592, 1745, 666, 3370, 2883, 2068, 874, 6842, 5270, 3235, 4363, 4518, 8380, 6828, 0, 3417, 15931, 12442, 1783, 4434, 1036, 1692, 3810, 29535, 10015, 12697, 23628, 43199, 21571, 4350, 491, 14300, 272352, 19801, 21154, 20578, 16149, 78373, 26640, 27871, 19540, 6584, 5990, 40360, 31708, 91775, 10012, 54599, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{982, 1593, 1125, 2723, 1024, 6591, 1736, 660, 3348, 2688, 2063, 846, 6820, 5270, 3230, 4288, 4515, 8340, 6725, 0, 3340, 15868, 12307, 1538, 4425, 771, 1637, 3638, 29241, 9884, 12517, 23436, 43120, 21401, 4170, 484, 5707, 272273, 19447, 18178, 20176, 15941, 0, 25917, 27377, 16849, 6499, 5398, 35743, 28901, 89846, 8224, 50802, 107205, 0, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{982, 1593, 1125, 2723, 1024, 6571, 1734, 660, 3347, 2683, 2063, 846, 6753, 5270, 3118, 4282, 4513, 8310, 6721, 0, 3240, 15836, 12304, 1538, 4421, 760, 1634, 3617, 29231, 9856, 12461, 23380, 43105, 21366, 3902, 484, 5701, 272248, 19163, 17637, 20087, 15799, 0, 25548, 27302, 16790, 6449, 5328, 35513, 28600, 89762, 7782, 50485, 103692, 11923, 0, 0, 0, 0, 0, 0, 0},
+		[]int64{981, 1593, 1120, 2702, 1023, 5922, 1722, 660, 3344, 2681, 2061, 843, 6737, 5267, 3117, 4280, 4513, 8309, 6715, 0, 3180, 15800, 12268, 1535, 4419, 743, 1620, 3611, 29221, 9844, 12454, 23214, 43053, 21356, 3895, 479, 5700, 272209, 19102, 17525, 20046, 15771, 0, 25487, 27260, 16785, 6391, 5288, 35341, 27452, 89683, 7719, 50379, 102035, 11787, 48873, 0, 0, 0, 0, 0, 0},
+		[]int64{975, 1593, 1120, 2686, 1019, 5920, 1718, 658, 3340, 2681, 2061, 843, 6733, 5266, 3117, 4269, 4499, 8306, 6713, 0, 3179, 15783, 12254, 1531, 4416, 739, 1612, 3592, 29217, 9839, 12452, 23202, 43043, 21350, 3885, 479, 5699, 272199, 18974, 17520, 19898, 15742, 0, 24718, 27197, 16765, 6377, 5281, 35306, 27384, 89531, 7502, 50238, 101815, 11720, 47787, 23800, 0, 0, 0, 0, 0},
+		[]int64{975, 1593, 1117, 2686, 1019, 5920, 1717, 658, 3337, 2681, 2060, 842, 6723, 5240, 3116, 4256, 4494, 8296, 6701, 0, 3160, 15743, 12235, 1523, 4414, 693, 1602, 3572, 29206, 9821, 12433, 22983, 42992, 20999, 3855, 476, 5692, 272158, 18811, 17443, 19846, 15616, 0, 24558, 27098, 16618, 6313, 5255, 35056, 27196, 89341, 7400, 49814, 101672, 11526, 47117, 21002, 16664, 0, 0, 0, 0},
+		[]int64{972, 1593, 1117, 2672, 1019, 5920, 1717, 658, 3337, 2681, 2059, 842, 6723, 5240, 3111, 4256, 4473, 8290, 6698, 0, 3152, 15716, 12172, 1523, 4412, 687, 1597, 3548, 29180, 9810, 12354, 22937, 42980, 20996, 3851, 475, 0, 271082, 18798, 14752, 19712, 15557, 0, 24487, 27006, 16132, 6213, 5095, 34845, 27103, 89281, 7268, 49516, 99034, 11501, 47105, 20886, 16499, 99277, 0, 0, 0},
+		[]int64{967, 1593, 1117, 2672, 1019, 5920, 1717, 658, 3337, 2681, 2059, 842, 6723, 5240, 3106, 4256, 4396, 8285, 6691, 0, 3110, 15709, 12161, 1522, 4408, 680, 1592, 3392, 29167, 9804, 12352, 22927, 42979, 20994, 3849, 474, 0, 268871, 18740, 11751, 19601, 15451, 0, 24392, 8970, 14411, 4245, 4729, 33890, 26298, 88696, 7003, 49177, 33580, 11422, 46951, 20798, 15839, 85988, 6823, 0, 0},
+		[]int64{967, 1592, 1116, 2660, 1018, 5920, 1714, 656, 3332, 2675, 2049, 842, 6679, 5204, 3091, 4139, 4322, 8206, 6644, 0, 2989, 15157, 11992, 1493, 4330, 634, 1553, 3320, 28555, 9724, 12317, 22700, 42501, 20936, 3835, 464, 0, 268531, 18694, 11669, 18754, 15247, 0, 21731, 8928, 14090, 4186, 4680, 30445, 25961, 88490, 6882, 48779, 33363, 11059, 46565, 19447, 14792, 85627, 6554, 17703, 0},
+		[]int64{967, 1592, 1116, 2660, 1018, 5920, 1712, 656, 3332, 2674, 2049, 839, 6547, 5204, 3061, 4136, 4319, 8189, 6644, 0, 2863, 15098, 11958, 1491, 4314, 623, 1543, 3314, 28438, 9544, 12096, 22657, 42411, 20900, 3831, 459, 0, 268413, 17451, 11506, 18691, 15171, 0, 21575, 8912, 14042, 4173, 4663, 30235, 25574, 88256, 6823, 48510, 33297, 8623, 46286, 19276, 14663, 85617, 6410, 16838, 17004},
+	}
+	cr := &core.CommonAnalysisResult{
+		BeginTime:     1390499270,
+		EndTime:       1549992932,
+		CommitsNumber: 6982,
+		RunTime:       1567214,
+	}
+	nh := mergeMatrices(h, nil, 30, 30, 30, 30, cr, cr)
+	for y, row := range nh {
+		for x, v := range row {
+			assert.InDelta(t, v, h[y][x], 1, fmt.Sprintf("y=%d x=%d", y, x))
+		}
+	}
+	nh = mergeMatrices(h, h, 30, 30, 30, 30, cr, cr)
+	for y, row := range nh {
+		for x, v := range row {
+			assert.InDelta(t, v, h[y][x]*2, 1, fmt.Sprintf("y=%d x=%d", y, x))
+		}
+	}
+}
+
+func TestBurndownMergePeopleHistories(t *testing.T) {
+	h1 := [][]int64{
+		{50, 0, 0},
+		{40, 80, 0},
+		{30, 50, 70},
+	}
+	h2 := [][]int64{
+		{900, 0, 0},
+		{1100, 400, 0},
+		{900, 750, 100},
+		{800, 600, 600},
+	}
+	res1 := BurndownResult{
+		GlobalHistory:      h1,
+		FileHistories:      map[string][][]int64{},
+		PeopleHistories:    [][][]int64{h1, h1},
+		PeopleMatrix:       nil,
+		reversedPeopleDict: []string{"one", "three"},
+		sampling:           15, // 3
+		granularity:        20, // 3
+	}
+	c1 := core.CommonAnalysisResult{
+		BeginTime:     600566400, // 1989 Jan 12
+		EndTime:       604540800, // 1989 February 27
+		CommitsNumber: 10,
+		RunTime:       100000,
+	}
+	res2 := BurndownResult{
+		GlobalHistory:      h2,
+		FileHistories:      nil,
+		PeopleHistories:    [][][]int64{h2, h2},
+		PeopleMatrix:       nil,
+		reversedPeopleDict: []string{"one", "two"},
+		sampling:           14,
+		granularity:        19,
+	}
+	c2 := core.CommonAnalysisResult{
+		BeginTime:     601084800, // 1989 Jan 18
+		EndTime:       605923200, // 1989 March 15
+		CommitsNumber: 10,
+		RunTime:       100000,
+	}
+	burndown := BurndownAnalysis{}
+	merged := burndown.MergeResults(res1, res2, &c1, &c2).(BurndownResult)
+	mh := [][]int64{
+		{560, 0, 0, 0},
+		{851, 572, 0, 0},
+		{704, 995, 217, 0},
+		{605, 767, 670, 0},
+		{575, 709, 685, 178},
+	}
+	assert.Equal(t, merged.reversedPeopleDict, []string{"one", "three", "two"})
+	assert.Equal(t, merged.PeopleHistories[0], mh)
+	mh = [][]int64{
+		{46, 0, 0, 0},
+		{43, 66, 0, 0},
+		{30, 106, 39, 0},
+		{28, 46, 75, 0},
+		{28, 46, 75, 0},
+	}
+	assert.Equal(t, merged.PeopleHistories[1], mh)
+	mh = [][]int64{
+		{514, 0, 0, 0},
+		{808, 506, 0, 0},
+		{674, 889, 177, 0},
+		{576, 720, 595, 0},
+		{547, 663, 610, 178},
+	}
+	assert.Equal(t, merged.PeopleHistories[2], mh)
+	assert.Nil(t, merged.PeopleMatrix)
+	assert.Nil(t, burndown.serializeBinary(&merged, ioutil.Discard))
+}