Просмотр исходного кода

Add yaml section 'people_coocc > author_files'

Alexander Bezzubov 7 лет назад
Родитель
Сommit
353be5943d
2 измененных файлов с 45 добавлено и 6 удалено
  1. 39 0
      cmd/hercules/main.go
  2. 6 6
      couples.go

+ 39 - 0
cmd/hercules/main.go

@@ -82,6 +82,7 @@ func printCouples(result *hercules.CouplesResult, peopleDict []string) {
 	for _, file := range result.Files {
 		fmt.Printf("    - %s\n", safeString(file))
 	}
+
 	fmt.Println("  matrix:")
 	for _, files := range result.FilesMatrix {
 		fmt.Print("    - {")
@@ -98,11 +99,13 @@ func printCouples(result *hercules.CouplesResult, peopleDict []string) {
 		}
 		fmt.Println("}")
 	}
+
 	fmt.Println("people_coocc:")
 	fmt.Println("  index:")
 	for _, person := range peopleDict {
 		fmt.Printf("    - %s\n", safeString(person))
 	}
+
 	fmt.Println("  matrix:")
 	for _, people := range result.PeopleMatrix {
 		fmt.Print("    - {")
@@ -119,6 +122,42 @@ func printCouples(result *hercules.CouplesResult, peopleDict []string) {
 		}
 		fmt.Println("}")
 	}
+
+	fmt.Println("  author_files:") // sorted by number of files each author changed
+	peopleFiles := sortByNumberOfFiles(result.PeopleFiles, peopleDict)
+	for _, authorFiles := range peopleFiles {
+		fmt.Printf("    - %s:\n", safeString(authorFiles.Author))
+		sort.Strings(authorFiles.Files)
+		for _, file := range authorFiles.Files {
+			fmt.Printf("      - %s\n", safeString(file)) // sorted by path
+		}
+	}
+}
+
+func sortByNumberOfFiles(peopleFiles [][]string, peopleDict []string) AuthorFilesList {
+	var pfl AuthorFilesList
+	for peopleIdx, files := range peopleFiles {
+		pfl = append(pfl, AuthorFiles{peopleDict[peopleIdx], files})
+	}
+	sort.Sort(pfl)
+	return pfl
+}
+
+type AuthorFiles struct {
+	Author string
+	Files  []string
+}
+
+type AuthorFilesList []AuthorFiles
+
+func (s AuthorFilesList) Len() int {
+	return len(s)
+}
+func (s AuthorFilesList) Swap(i, j int) {
+	s[i], s[j] = s[j], s[i]
+}
+func (s AuthorFilesList) Less(i, j int) bool {
+	return len(s[i].Files) < len(s[j].Files)
 }
 
 func sortedKeys(m map[string][][]int64) []string {

+ 6 - 6
couples.go

@@ -1,7 +1,6 @@
 package hercules
 
 import (
-	"fmt"
 	"sort"
 
 	"gopkg.in/src-d/go-git.v4"
@@ -23,6 +22,7 @@ type Couples struct {
 
 type CouplesResult struct {
 	PeopleMatrix []map[int]int64
+	PeopleFiles  [][]string
 	FilesMatrix  []map[int]int
 	Files        []string
 }
@@ -105,12 +105,13 @@ func (couples *Couples) Consume(deps map[string]interface{}) (map[string]interfa
 
 func (couples *Couples) Finalize() interface{} {
 	peopleMatrix := make([]map[int]int64, couples.PeopleNumber)
-	fmt.Printf("people_files:\n")
+	peopleFiles := make([][]string, couples.PeopleNumber)
 	for i := range peopleMatrix {
 		peopleMatrix[i] = map[int]int64{}
-		fmt.Printf("  %d: ", i)
 		for file, commits := range couples.people[i] {
-			fmt.Printf("%s, ", file)
+			//could be normalized further, by replacing file with idx in fileSequence
+			//but the would trade the space for readabilyt of result
+			peopleFiles[i] = append(peopleFiles[i], file)
 			for j, otherFiles := range couples.people {
 				if i == j {
 					continue
@@ -126,7 +127,6 @@ func (couples *Couples) Finalize() interface{} {
 			}
 		}
 		peopleMatrix[i][i] = int64(couples.people_commits[i])
-		fmt.Printf("\n")
 	}
 	filesSequence := make([]string, len(couples.files))
 	i := 0
@@ -146,5 +146,5 @@ func (couples *Couples) Finalize() interface{} {
 			filesMatrix[i][filesIndex[otherFile]] = cooccs
 		}
 	}
-	return CouplesResult{PeopleMatrix: peopleMatrix, Files: filesSequence, FilesMatrix: filesMatrix}
+	return CouplesResult{PeopleMatrix: peopleMatrix, PeopleFiles: peopleFiles, Files: filesSequence, FilesMatrix: filesMatrix}
 }