-
Notifications
You must be signed in to change notification settings - Fork 1
/
analyzer.go
79 lines (61 loc) · 1.74 KB
/
analyzer.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package inspector
import (
"math"
"encoding/json"
"fmt"
"log"
)
type block struct {
key string
file string
unit_type int
value float64
size int
}
func (b block) MarshalJSON() ([]byte, error) {
m := make(map[string]string)
m["key"] = b.key
m["file"] = b.file
m["unit_type"] = fmt.Sprintf("%d", b.unit_type)
m["value"] = fmt.Sprintf("%.6f", b.value)
m["size"] = fmt.Sprintf("%d", b.size)
return json.Marshal(m)
}
func AnalyzeRepo(repoName string) (returnBlocks []block) {
// everything := Harvest(repoName)
everything := Harvest(repoName)
if everything == nil {
log.Println("YOURE DONE M8:w")
return returnBlocks
}
// absoluteTotalNumberOfCommits := len(everything.Commits)
totalNumberOfCommits := len(everything.Commits)
for _, file := range everything.Files {
log.Println("LOGGING FILES")
for _, unit := range file.Units {
numberOfCommits := unit.TimesChanged
// //BULLSHIT START
// rand.Seed(time.Now().UTC().UnixNano())
//
// numberOfCommits = rand.Intn(100) + 1
// totalNumberOfCommits = rand.Intn(30) + numberOfCommits
// //BULLSHIT END
//
log.Println("-----")
log.Printf("%d", totalNumberOfCommits)
log.Printf("%d", numberOfCommits)
log.Printf("%f", unit.RatioSum)
log.Printf("%f", unit.RatioSum / float64(numberOfCommits))
log.Printf("%f", float64(totalNumberOfCommits) / float64(numberOfCommits))
log.Printf("%f", math.Log(float64(totalNumberOfCommits / numberOfCommits)))
returnBlocks = append(returnBlocks, block{
key: unit.Name,
file: file.Path,
unit_type: unit.Type,
value: (unit.RatioSum / float64(numberOfCommits)) * math.Log(float64(totalNumberOfCommits) / float64(numberOfCommits)),
size: unit.Size(),
})
}
}
return returnBlocks
}