fix error in CommitSet to Freq func

This commit is contained in:
2023-01-30 23:45:27 -08:00
parent aa28e5b264
commit 31bb0d88c7
4 changed files with 14 additions and 30 deletions

View File

@@ -14,11 +14,11 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
freq, err := repoPaths.Frequency(n.Year(), []string{""}) freq, err := repoPaths.Frequency(n.Year(), []string{"Groot"})
if err != nil { if err != nil {
panic(err) panic(err)
} }
wfreq, err := repoPaths.GetWeekFreq([]string{""}) wfreq, err := repoPaths.GetWeekFreq([]string{"Groot"})
if err != nil { if err != nil {
panic(err) panic(err)
} }
@@ -29,4 +29,5 @@ func main() {
fmt.Println() fmt.Println()
fmt.Println("year:") fmt.Println("year:")
fmt.Println(term.GetYearUnicode(freq)) fmt.Println(term.GetYearUnicode(freq))
fmt.Println((freq))
} }

View File

@@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
"net/http" "net/http"
"strconv" "strconv"
"time" "time"
@@ -17,6 +18,7 @@ func main() {
r := mux.NewRouter() r := mux.NewRouter()
r.HandleFunc("/weekly.svg", func(w http.ResponseWriter, r *http.Request) { r.HandleFunc("/weekly.svg", func(w http.ResponseWriter, r *http.Request) {
author := r.URL.Query().Get("author") author := r.URL.Query().Get("author")
fmt.Println(author)
w.Header().Add("Content-Type", "text/html") w.Header().Add("Content-Type", "text/html")
repoPaths, err := commits.GetMRRepos() repoPaths, err := commits.GetMRRepos()
if err != nil { if err != nil {
@@ -26,6 +28,7 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
fmt.Println(week)
svg := svg.GetWeekSVG(week) svg := svg.GetWeekSVG(week)
svg.WriteTo(w) svg.WriteTo(w)
}) })
@@ -33,6 +36,7 @@ func main() {
year := time.Now().Year() year := time.Now().Year()
yst := r.URL.Query().Get("year") yst := r.URL.Query().Get("year")
author := r.URL.Query().Get("author") author := r.URL.Query().Get("author")
fmt.Println(author)
y, err := strconv.Atoi(yst) y, err := strconv.Atoi(yst)
if err == nil { if err == nil {
year = y year = y
@@ -45,6 +49,7 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
fmt.Println(freq)
svg := svg.GetYearSVG(freq) svg := svg.GetYearSVG(freq)
w.Header().Add("Content-Type", "text/html") w.Header().Add("Content-Type", "text/html")
svg.WriteTo(w) svg.WriteTo(w)

View File

@@ -59,9 +59,6 @@ func YearFreqFromChan(cc chan types.Commit, year int) types.Freq {
} }
freq := make([]int, yearLength) freq := make([]int, yearLength)
for commit := range cc { for commit := range cc {
if commit.TimeStamp.Year() != year {
continue
}
freq[commit.TimeStamp.YearDay()-1]++ freq[commit.TimeStamp.YearDay()-1]++
} }
return freq return freq
@@ -131,10 +128,11 @@ func FilterCChanByAuthor(in chan types.Commit, authors []string) (chan types.Com
} }
go func() { go func() {
for commit := range in { for commit := range in {
regset:
for _, r := range regSet { for _, r := range regSet {
if r.MatchString(commit.Author) { if r.MatchString(commit.Author) {
out <- commit out <- commit
break break regset
} }
} }
} }

View File

@@ -90,29 +90,8 @@ func (cs CommitSet) ToYearFreq() types.Freq {
yearLength++ yearLength++
} }
freq := make([]int, yearLength) freq := make([]int, yearLength)
data := types.NewDataSet() for _, v := range cs.Commits {
for _, commit := range cs.Commits { freq[v.TimeStamp.YearDay()-1]++
ts := commit.TimeStamp
roundedTS := ts.Round(time.Hour * 24)
wd, ok := data[roundedTS]
if !ok {
wd = types.WorkDay{}
wd.Commits = []types.Commit{}
}
wd.Commits = append(wd.Commits, commit)
wd.Count++
wd.Day = roundedTS
data[roundedTS] = wd
}
for k, v := range data {
if k.Year() != year {
continue
}
// this is equivalent to adding len(commits) to the freq total, but
// it's a stub for later when we do more here
for range v.Commits {
freq[k.YearDay()]++
}
} }
return freq return freq
} }
@@ -128,10 +107,11 @@ func (cs CommitSet) FilterByAuthorRegex(authors []string) (CommitSet, error) {
} }
newCS := CommitSet{Year: cs.Year} newCS := CommitSet{Year: cs.Year}
for _, commit := range cs.Commits { for _, commit := range cs.Commits {
regset:
for _, r := range regSet { for _, r := range regSet {
if r.MatchString(commit.Author) { if r.MatchString(commit.Author) {
newCS.Commits = append(newCS.Commits, commit) newCS.Commits = append(newCS.Commits, commit)
break break regset
} }
} }
} }