Jelajahi Sumber

Fix sampling and the labours script

Vadim Markovtsev 8 tahun lalu
induk
melakukan
c970d92f77
3 mengubah file dengan 30 tambahan dan 5 penghapusan
  1. 13 2
      analyser.go
  2. 4 2
      cmd/hercules/main.go
  3. 13 1
      labours.py

+ 13 - 2
analyser.go

@@ -197,7 +197,12 @@ func (analyser *Analyser) groupStatus(status map[int]int64, day int) []int64 {
 	if granularity == 0 {
 		granularity = 1
 	}
-	result := make([]int64, day/granularity)
+	day++
+	adjust := 0
+	if day%granularity < granularity-1 {
+		adjust = 1
+	}
+	result := make([]int64, day/granularity+adjust)
 	var group int64
 	for i := 0; i < day; i++ {
 		group += status[i]
@@ -206,6 +211,9 @@ func (analyser *Analyser) groupStatus(status map[int]int64, day int) []int64 {
 			group = 0
 		}
 	}
+	if day%granularity < granularity-1 {
+		result[len(result)-1] = group
+	}
 	return result
 }
 
@@ -262,7 +270,10 @@ func (analyser *Analyser) Analyse(commits []*git.Commit) [][]int64 {
 			delta := (day / sampling) - (prev_day / sampling)
 			if delta > 0 {
 				prev_day = day
-				statuses = append(statuses, analyser.groupStatus(status, day))
+				gs := analyser.groupStatus(status, day)
+				for i := 0; i < delta; i++ {
+					statuses = append(statuses, gs)
+				}
 			}
 			tree_diff, err := git.DiffTree(prev_tree, tree)
 			if err != nil {

+ 4 - 2
cmd/hercules/main.go

@@ -115,7 +115,7 @@ func main() {
 		commits = loadCommitsFromFile(commitsFile, repository)
 	}
 	statuses := analyser.Analyse(commits)
-	fmt.Fprint(os.Stderr, "        \r")
+	fmt.Fprint(os.Stderr, "                \r")
 	if len(statuses) == 0 {
 		return
 	}
@@ -130,6 +130,8 @@ func main() {
 	}
 	width := len(strconv.FormatInt(maxnum, 10))
 	last := len(statuses[len(statuses) - 1])
+	// print the start date, granularity, sampling
+	fmt.Println(commits[0].Author.When.Unix(), granularity, sampling)
 	// print the resulting triangle matrix
 	for _, status := range statuses {
 		for i := 0; i < last; i++ {
@@ -139,6 +141,6 @@ func main() {
 			}
 			fmt.Printf("%[1]*[2]d ", width, val)
 		}
-		println()
+		fmt.Println()
 	}
 }

+ 13 - 1
labours.py

@@ -1,16 +1,28 @@
+from datetime import datetime, timedelta
 import sys
 
 import matplotlib.pyplot as pyplot
 import numpy
+import pandas
 import seaborn  # to get nice colors, he-he
 
 
 def main():
     matrix = []
+    start, granularity, sampling = input().split()
+    start = datetime.fromtimestamp(int(start))
+    granularity = int(granularity)
+    sampling = int(sampling)
     for line in sys.stdin.read().split("\n")[:-1]:
         matrix.append(numpy.fromstring(line, dtype=int, sep=" "))
     matrix = numpy.array(matrix).T
-    pyplot.stackplot(numpy.arange(matrix.shape[1]), matrix)
+    pyplot.stackplot(
+        pandas.date_range(start, periods=matrix.shape[1], freq="%dD" % sampling),
+        matrix,
+        labels=["%s - %s" % ((start + timedelta(days=i * granularity)).date(),
+                             (start + timedelta(days=(i + 1) * granularity)).date())
+                for i in range(matrix.shape[0])])
+    pyplot.legend(loc=2)
     pyplot.show()
 
 if __name__ == "__main__":