Skip to content

Commit

Permalink
Merge pull request #3 from kamermans/trim-years
Browse files Browse the repository at this point in the history
Trim start year to the first year of contribution
  • Loading branch information
kamermans authored Dec 17, 2024
2 parents d194a0c + 70d6d03 commit 14b9486
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import (
)

const (
version = "1.1.1"
version = "1.1.2"
)

var (
username string
token string
saveContribs bool
contribsFile string
trimContribs bool
outputFile string
startYear int
endYear int
Expand All @@ -45,6 +46,7 @@ func init() {
flag.StringVarP(&token, "token", "t", os.Getenv("GITHUB_TOKEN"), "GitHub token")
flag.BoolVarP(&saveContribs, "save", "s", false, "Save contributions to a file")
flag.StringVarP(&contribsFile, "contributions", "f", "contributions.json", "File to save/load contributions")
flag.BoolVarP(&trimContribs, "trim", "T", true, "Trim years from the start that contain no contributions")
flag.StringVarP(&outputFile, "output", "o", "skyline.scad", "Output file (.scad and .stl are supported, but stl requires 'openscad')")
flag.IntVarP(&startYear, "start", "b", 0, "Start year")
flag.IntVarP(&endYear, "end", "e", 0, "End year")
Expand Down Expand Up @@ -126,6 +128,12 @@ func main() {
}
}

if trimContribs {
if contribs.TrimStartYear() {
fmt.Printf("Trimmed start year to %v\n", contribs.FirstDate[:4])
}
}

fmt.Printf("Total contributions: %d between %v and %v\n", contribs.TotalContributions, contribs.FirstDate, contribs.LastDate)

fmt.Printf("Generating OpenSCAD ...\n")
Expand Down
2 changes: 1 addition & 1 deletion pkg/skyline/cad.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ var (
if (textEnable) {
textOffset = baseOffset+baseMargin;
textSize = baseHeight-baseMargin;
textSize = baseHeight-baseMargin-1;
rotate([90-baseAngle, 0 ,0])
translate([textOffset, 1, 0])
Expand Down
45 changes: 45 additions & 0 deletions pkg/skyline/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,51 @@ type Contributions struct {
ByDate map[string]int `json:"by_date"`
}

// TrimStartYear trims the contributions to the first year with at least one contribution
func (c *Contributions) TrimStartYear() bool {
firstContributionYear := 0
for date, numContribs := range c.ByDate {

if numContribs == 0 {
continue
}

year, err := time.Parse("2006-01-02", date)
if err != nil {
panic(err)
}

if firstContributionYear == 0 || year.Year() < firstContributionYear {
firstContributionYear = year.Year()
}
}

fmt.Printf("First contribution year: %d\n", firstContributionYear)

if firstContributionYear == 0 {
return false
}

for date := range c.ByDate {
year, err := time.Parse("2006-01-02", date)
if err != nil {
panic(err)
}

if year.Year() < firstContributionYear {
delete(c.ByDate, date)
}
}

firstDate := fmt.Sprintf("%d-01-01", firstContributionYear)
if firstDate != c.FirstDate {
c.FirstDate = firstDate
return true
}

return false
}

func (c *Contributions) YearRangeText() string {
startYear := c.FirstDate[:4]
endYear := c.LastDate[:4]
Expand Down

0 comments on commit 14b9486

Please sign in to comment.