+
Skip to content

Trim start year to the first year of contribution #3

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

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载