mirror of
https://github.com/taigrr/gico.git
synced 2026-04-02 03:09:07 -07:00
add stats endpoint
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@@ -29,6 +30,26 @@ func main() {
|
|||||||
svg := svg.GetWeekSVG(week)
|
svg := svg.GetWeekSVG(week)
|
||||||
svg.WriteTo(w)
|
svg.WriteTo(w)
|
||||||
})
|
})
|
||||||
|
r.HandleFunc("/stats.json", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
year := time.Now().Year()
|
||||||
|
yst := r.URL.Query().Get("year")
|
||||||
|
author := r.URL.Query().Get("author")
|
||||||
|
y, err := strconv.Atoi(yst)
|
||||||
|
if err == nil {
|
||||||
|
year = y
|
||||||
|
}
|
||||||
|
repoPaths, err := commits.GetMRRepos()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
freq, err := repoPaths.FrequencyChan(year, []string{author})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
b, _ := json.Marshal(freq)
|
||||||
|
w.Header().Add("Content-Type", "application/json")
|
||||||
|
w.Write(b)
|
||||||
|
})
|
||||||
r.HandleFunc("/yearly.svg", func(w http.ResponseWriter, r *http.Request) {
|
r.HandleFunc("/yearly.svg", func(w http.ResponseWriter, r *http.Request) {
|
||||||
year := time.Now().Year()
|
year := time.Now().Year()
|
||||||
yst := r.URL.Query().Get("year")
|
yst := r.URL.Query().Get("year")
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func CacheGraph(year int, authors, repoPaths []string, freq types.Freq) {
|
|||||||
}
|
}
|
||||||
hashCache[year][a][r] = types.ExpFreq{YearFreq: freq, Created: time.Now()}
|
hashCache[year][a][r] = types.ExpFreq{YearFreq: freq, Created: time.Now()}
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(time.Minute * 15)
|
time.Sleep(time.Hour * 1)
|
||||||
mapTex.Lock()
|
mapTex.Lock()
|
||||||
defer mapTex.Unlock()
|
defer mapTex.Unlock()
|
||||||
delete(hashCache[year][a], r)
|
delete(hashCache[year][a], r)
|
||||||
|
|||||||
Reference in New Issue
Block a user