mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
test in-prog commit
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -16,9 +17,31 @@ type DayCount [366]int
|
||||
func main() {
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/weekly.svg", func(w http.ResponseWriter, r *http.Request) {
|
||||
freq := []int{}
|
||||
author := r.URL.Query().Get("author")
|
||||
w.Header().Add("Content-Type", "text/html")
|
||||
svg := svg.GetWeekSVG(freq)
|
||||
now := time.Now()
|
||||
year := now.Year()
|
||||
freq, err := commits.GlobalFrequencyChan(year, []string{author})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
today := now.YearDay() - 1
|
||||
fmt.Println(today)
|
||||
if today < 6 {
|
||||
curYear := year - 1
|
||||
curFreq, err := commits.GlobalFrequencyChan(curYear, []string{author})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
freq = append(curFreq, freq...)
|
||||
today += 365
|
||||
if curYear%4 == 0 {
|
||||
today++
|
||||
}
|
||||
}
|
||||
fmt.Println(freq)
|
||||
week := freq[today-6 : today+1]
|
||||
svg := svg.GetWeekSVG(week)
|
||||
svg.WriteTo(w)
|
||||
})
|
||||
r.HandleFunc("/yearly.svg", func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -28,10 +28,10 @@ func GetWeekSVG(frequencies []int) bytes.Buffer {
|
||||
for _, f := range frequencies {
|
||||
squareColors = append(squareColors, common.ColorForFrequency(f, min, max))
|
||||
}
|
||||
return drawWeekImage(squareColors)
|
||||
return drawWeekImage(squareColors, frequencies)
|
||||
}
|
||||
|
||||
func drawWeekImage(c []sc.SimpleColor) bytes.Buffer {
|
||||
func drawWeekImage(c []sc.SimpleColor, freq []int) bytes.Buffer {
|
||||
var sb bytes.Buffer
|
||||
sbw := bufio.NewWriter(&sb)
|
||||
squareLength := 10
|
||||
@@ -41,7 +41,7 @@ func drawWeekImage(c []sc.SimpleColor) bytes.Buffer {
|
||||
canvas.Start(width, height)
|
||||
canvas.Rect(0, 0, width, height, "fill:black")
|
||||
for i, s := range c {
|
||||
canvas.Square(squareLength*2*(i+1), squareLength/2, squareLength, fmt.Sprintf("fill:%s", s.ToHex()))
|
||||
canvas.Square(squareLength*2*(i+1), squareLength/2, squareLength, fmt.Sprintf("fill:%s; value:%d", s.ToHex(), freq[i]))
|
||||
}
|
||||
canvas.End()
|
||||
sbw.Flush()
|
||||
@@ -58,7 +58,6 @@ func GetYearSVG(frequencies []int) bytes.Buffer {
|
||||
}
|
||||
|
||||
func drawYearImage(c []sc.SimpleColor) bytes.Buffer {
|
||||
// TODO here, draw suqares in appropriate colors, hopefully as an svg
|
||||
var sb bytes.Buffer
|
||||
sbw := bufio.NewWriter(&sb)
|
||||
squareLength := 10
|
||||
|
||||
Reference in New Issue
Block a user