1
0
Fork 0

All top & activity report apis

This commit is contained in:
Gregory Eremin 2015-03-08 21:35:25 +07:00
parent e6f934c5dc
commit 132a726744
5 changed files with 126 additions and 13 deletions

View File

@ -80,7 +80,10 @@ var OrgStats = React.createClass({
var TeamStats = React.createClass({
mixins: [Router.Navigation, Router.State],
render: function(){
var topRepos = "/api/stat/teams/top?org="+ this.getParams().org +"&team="+ this.getParams().team +"&item=repo",
var topRepos = "/api/stat/teams/top"+
"?org="+ this.getParams().org +
"&team="+ this.getParams().team +
"&item=repo",
repoURL = "/app/"+ this.getParams().org +"/repos/";
return (
<section className="content">

View File

@ -74,7 +74,7 @@ where
c.week >= :from and
c.week <= :to
group by item
order by %s desc`
order by commits desc`
const teamActivityQuery = `
select
@ -95,7 +95,75 @@ where
c.week >= :from and
c.week <= :to
group by item, week
order by week, %s desc`
order by week, commits desc`
const userTopQuery = `
select
c.repo as item,
sum(c.commits) as commits,
sum(c.additions) - sum(c.deletions) as delta
from contribs c
where
c.owner = :org and
c.week >= :from and
c.week <= :to
group by item
order by commits desc`
const userActivityQuery = `
select
c.week as week,
c.repo as item,
sum(c.commits) as commits,
sum(c.additions) - sum(c.deletions) as delta
from contribs c
where
c.owner = :org and
c.week >= :from and
c.week <= :to
group by item
order by week, commits desc`
const repoTopQuery = `
select
%s as item,
sum(c.commits) as commits,
sum(c.additions) - sum(c.deletions) as delta
from contribs c
join members m on
c.author = m.user and
c.owner = m.org
join teams t on
m.team_id = t.id
where
m.id is not null and
c.owner = :org and
c.repo = :repo and
c.week >= :from and
c.week <= :to
group by item
order by commits desc`
const repoActivityQuery = `
select
c.week as weel,
%s as item,
sum(c.commits) as commits,
sum(c.additions) - sum(c.deletions) as delta
from contribs c
join members m on
c.author = m.user and
c.owner = m.org
join teams t on
m.team_id = t.id
where
m.id is not null and
c.owner = :org and
c.repo = :repo and
c.week >= :from and
c.week <= :to
group by week, item
order by commits desc`
func StatOrgTop(p map[string]interface{}) (res []StatItem) {
defer measure("StatOrgTop", time.Now())
@ -120,3 +188,27 @@ func StatTeamActivity(p map[string]interface{}) (res []StatPoint) {
mustSelectN(&res, fmt.Sprintf(teamActivityQuery, p["item"], p["sort"]), p)
return
}
func StatUserTop(p interface{}) (res []StatItem) {
defer measure("StatUserTop", time.Now())
mustSelectN(&res, userTopQuery, p)
return
}
func StatUserActivity(p interface{}) (res []StatPoint) {
defer measure("StatUserActivity", time.Now())
mustSelectN(&res, userActivityQuery, p)
return
}
func StatRepoTop(p interface{}) (res []StatItem) {
defer measure("StatRepoTop", time.Now())
mustSelectN(&res, repoTopQuery, p)
return
}
func StatRepoActivity(p interface{}) (res []StatPoint) {
defer measure("StatRepoActivity", time.Now())
mustSelectN(&res, repoActivityQuery, p)
return
}

View File

@ -25,7 +25,6 @@ type (
From int64 `structs:"from"`
To int64 `structs:"to"`
Item string `structs:"item"`
Sort string `structs:"sort"`
}
)
@ -84,14 +83,6 @@ func parseStatRequest(r *http.Request) *statRequest {
item = "c.repo"
}
var sort string
switch val := r.FormValue("sort"); val {
case "commits", "delta":
sort = val
default:
sort = "commits"
}
return &statRequest{
Org: r.FormValue("org"),
Team: r.FormValue("team"),
@ -99,7 +90,6 @@ func parseStatRequest(r *http.Request) *statRequest {
From: from,
To: to,
Item: item,
Sort: sort,
}
}

View File

@ -28,6 +28,10 @@ func init() {
http.HandleFunc("/api/stat/orgs/activity", statOrgActivityHandler)
http.HandleFunc("/api/stat/teams/top", statTeamTopHandler)
http.HandleFunc("/api/stat/teams/activity", statTeamActivityHandler)
http.HandleFunc("/api/stat/users/top", statUserTopHandler)
http.HandleFunc("/api/stat/users/activity", statUserActivityHandler)
http.HandleFunc("/api/stat/repos/top", statRepoTopHandler)
http.HandleFunc("/api/stat/repos/activity", statRepoActivityHandler)
}
func Start() {

View File

@ -30,3 +30,27 @@ func statTeamActivityHandler(w http.ResponseWriter, r *http.Request) {
activity := db.StatTeamActivity(structs.Map(stat))
req.respondWith(activity)
}
func statUserTopHandler(w http.ResponseWriter, r *http.Request) {
req, stat := parseRequest(w, r)
top := db.StatUserTop(structs.Map(stat))
req.respondWith(top)
}
func statUserActivityHandler(w http.ResponseWriter, r *http.Request) {
req, stat := parseRequest(w, r)
activity := db.StatUserActivity(structs.Map(stat))
req.respondWith(activity)
}
func statRepoTopHandler(w http.ResponseWriter, r *http.Request) {
req, stat := parseRequest(w, r)
top := db.StatRepoTop(structs.Map(stat))
req.respondWith(top)
}
func statRepoActivityHandler(w http.ResponseWriter, r *http.Request) {
req, stat := parseRequest(w, r)
activity := db.StatRepoActivity(structs.Map(stat))
req.respondWith(activity)
}