Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more granular intervals (replace 'days' with generic 'ticks') #245

Merged
merged 19 commits into from Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 17 additions & 17 deletions contrib/_plugin_example/churn_analysis.go
Expand Up @@ -33,7 +33,7 @@ type ChurnAnalysis struct {
}

type editInfo struct {
Day int
Tick int
Added int
Removed int
}
Expand All @@ -45,7 +45,7 @@ type ChurnAnalysisResult struct {
}

type Edits struct {
Days []int
Ticks []int
Additions []int
Removals []int
}
Expand All @@ -68,14 +68,14 @@ func (churn *ChurnAnalysis) Provides() []string {
// file_diff - line diff for each commit change
// changes - list of changed files for each commit
// blob_cache - set of blobs affected by each commit
// day - number of days since start for each commit
// dick - number of ticks since start for each commit
bobheadxi marked this conversation as resolved.
Show resolved Hide resolved
// author - author of the commit
func (churn *ChurnAnalysis) Requires() []string {
arr := [...]string{
hercules.DependencyFileDiff,
hercules.DependencyTreeChanges,
hercules.DependencyBlobCache,
hercules.DependencyDay,
hercules.DependencyTick,
hercules.DependencyAuthor}
return arr[:]
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func (churn *ChurnAnalysis) Consume(deps map[string]interface{}) (map[string]int
fileDiffs := deps[hercules.DependencyFileDiff].(map[string]hercules.FileDiffData)
treeDiffs := deps[hercules.DependencyTreeChanges].(object.Changes)
cache := deps[hercules.DependencyBlobCache].(map[plumbing.Hash]*hercules.CachedBlob)
day := deps[hercules.DependencyDay].(int)
tick := deps[hercules.DependencyTick].(int)
author := deps[hercules.DependencyAuthor].(int)
for _, change := range treeDiffs {
action, err := change.Action()
Expand Down Expand Up @@ -161,7 +161,7 @@ func (churn *ChurnAnalysis) Consume(deps map[string]interface{}) (map[string]int
if err != nil {
return nil, err
}
ei := editInfo{Day: day, Added: added, Removed: removed}
ei := editInfo{Tick: tick, Added: added, Removed: removed}
churn.global = append(churn.global, ei)
if churn.TrackPeople {
seq, exists := churn.people[author]
Expand Down Expand Up @@ -230,28 +230,28 @@ func (churn *ChurnAnalysis) serializeBinary(result *ChurnAnalysisResult, writer
func editInfosToEdits(eis []editInfo) Edits {
aux := map[int]*editInfo{}
for _, ei := range eis {
ptr := aux[ei.Day]
ptr := aux[ei.Tick]
if ptr == nil {
ptr = &editInfo{Day: ei.Day}
ptr = &editInfo{Tick: ei.Tick}
}
ptr.Added += ei.Added
ptr.Removed += ei.Removed
aux[ei.Day] = ptr
aux[ei.Tick] = ptr
}
seq := []int{}
for key := range aux {
seq = append(seq, key)
}
sort.Ints(seq)
edits := Edits{
Days: make([]int, len(seq)),
Ticks: make([]int, len(seq)),
Additions: make([]int, len(seq)),
Removals: make([]int, len(seq)),
}
for i, day := range seq {
edits.Days[i] = day
edits.Additions[i] = aux[day].Added
edits.Removals[i] = aux[day].Removed
for i, tick := range seq {
edits.Ticks[i] = tick
edits.Additions[i] = aux[tick].Added
edits.Removals[i] = aux[tick].Removed
}
return edits
}
Expand All @@ -268,14 +268,14 @@ func printEdits(edits Edits, writer io.Writer, indent int) {
}
}
}
printArray(edits.Days, "days")
printArray(edits.Ticks, "ticks")
printArray(edits.Additions, "additions")
printArray(edits.Removals, "removals")
}

func editsToEditsMessage(edits Edits) *EditsMessage {
message := &EditsMessage{
Days: make([]uint32, len(edits.Days)),
Ticks: make([]uint32, len(edits.Ticks)),
Additions: make([]uint32, len(edits.Additions)),
Removals: make([]uint32, len(edits.Removals)),
}
Expand All @@ -284,7 +284,7 @@ func editsToEditsMessage(edits Edits) *EditsMessage {
where[i] = uint32(v)
}
}
copyInts(edits.Days, message.Days)
copyInts(edits.Ticks, message.Ticks)
copyInts(edits.Additions, message.Additions)
copyInts(edits.Removals, message.Removals)
return message
Expand Down
2 changes: 1 addition & 1 deletion contrib/_plugin_example/churn_analysis.proto
Expand Up @@ -3,7 +3,7 @@ option go_package = "main";

message EditsMessage {
// all three are of the same length
repeated uint32 days = 1;
repeated uint32 ticks = 1;
repeated uint32 additions = 2;
repeated uint32 removals = 3;
}
Expand Down
10 changes: 5 additions & 5 deletions core.go
Expand Up @@ -122,9 +122,9 @@ const (
DependencyAuthor = identity.DependencyAuthor
// DependencyBlobCache identifies the dependency provided by BlobCache.
DependencyBlobCache = plumbing.DependencyBlobCache
// DependencyDay is the name of the dependency which DaysSinceStart provides - the number
// of days since the first commit in the analysed sequence.
DependencyDay = plumbing.DependencyDay
// DependencyTick is the name of the dependency which TicksSinceStart provides - the number
// of ticks since the first commit in the analysed sequence.
DependencyTick = plumbing.DependencyTick
// DependencyFileDiff is the name of the dependency provided by FileDiff.
DependencyFileDiff = plumbing.DependencyFileDiff
// DependencyTreeChanges is the name of the dependency provided by TreeDiff.
Expand All @@ -133,8 +133,8 @@ const (
DependencyUastChanges = uast.DependencyUastChanges
// DependencyUasts is the name of the dependency provided by Extractor.
DependencyUasts = uast.DependencyUasts
// FactCommitsByDay contains the mapping between day indices and the corresponding commits.
FactCommitsByDay = plumbing.FactCommitsByDay
// FactCommitsByTick contains the mapping between tick indices and the corresponding commits.
FactCommitsByTick = plumbing.FactCommitsByTick
// FactIdentityDetectorPeopleCount is the name of the fact which is inserted in
// identity.Detector.Configure(). It is equal to the overall number of unique authors
// (the length of ReversedPeopleDict).
Expand Down
2 changes: 1 addition & 1 deletion internal/burndown/file.go
Expand Up @@ -31,7 +31,7 @@ type File struct {
// TreeEnd denotes the value of the last leaf in the tree.
const TreeEnd = math.MaxUint32

// TreeMaxBinPower is the binary power value which corresponds to the maximum day which
// TreeMaxBinPower is the binary power value which corresponds to the maximum tick which
// can be stored in the tree.
const TreeMaxBinPower = 14

Expand Down
8 changes: 4 additions & 4 deletions internal/global_test.go
Expand Up @@ -28,7 +28,7 @@ func TestPipelineSerialize(t *testing.T) {
dot := string(bdot)
assert.Equal(t, `digraph Hercules {
"6 BlobCache" -> "7 [blob_cache]"
"0 DaysSinceStart" -> "3 [day]"
"0 TicksSinceStart" -> "3 [tick]"
"9 FileDiff" -> "11 [file_diff]"
"15 FileDiffRefiner" -> "16 Burndown"
"1 IdentityDetector" -> "4 [author]"
Expand All @@ -47,7 +47,7 @@ func TestPipelineSerialize(t *testing.T) {
"14 [changed_uasts]" -> "15 FileDiffRefiner"
"5 [changes]" -> "6 BlobCache"
"5 [changes]" -> "8 RenameAnalysis"
"3 [day]" -> "16 Burndown"
"3 [tick]" -> "16 Burndown"
"11 [file_diff]" -> "15 FileDiffRefiner"
"12 [uasts]" -> "13 UASTChanges"
}`, dot)
Expand All @@ -68,7 +68,7 @@ func TestPipelineSerializeNoUast(t *testing.T) {
dot := string(bdot)
assert.Equal(t, `digraph Hercules {
"6 BlobCache" -> "7 [blob_cache]"
"0 DaysSinceStart" -> "3 [day]"
"0 TicksSinceStart" -> "3 [tick]"
"9 FileDiff" -> "10 [file_diff]"
"1 IdentityDetector" -> "4 [author]"
"8 RenameAnalysis" -> "11 Burndown"
Expand All @@ -80,7 +80,7 @@ func TestPipelineSerializeNoUast(t *testing.T) {
"7 [blob_cache]" -> "8 RenameAnalysis"
"5 [changes]" -> "6 BlobCache"
"5 [changes]" -> "8 RenameAnalysis"
"3 [day]" -> "11 Burndown"
"3 [tick]" -> "11 Burndown"
"10 [file_diff]" -> "11 Burndown"
}`, dot)
}
Expand Down