2015-03-06 16:29:26 +00:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
2015-03-08 11:17:56 +00:00
|
|
|
"fmt"
|
2015-03-06 16:29:26 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
|
|
|
StatItem struct {
|
2015-03-08 11:17:56 +00:00
|
|
|
Item string `json:"item"`
|
|
|
|
Commits int `json:"commits"`
|
|
|
|
Delta int `json:"delta"`
|
2015-03-06 16:29:26 +00:00
|
|
|
}
|
|
|
|
StatPoint struct {
|
|
|
|
StatItem
|
2015-03-08 11:17:56 +00:00
|
|
|
Week uint64 `json:"week"`
|
2015-03-06 16:29:26 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2015-03-08 11:17:56 +00:00
|
|
|
const orgTopQuery = `
|
2015-03-06 16:29:26 +00:00
|
|
|
select
|
2015-03-08 11:17:56 +00:00
|
|
|
%s as item,
|
|
|
|
sum(c.commits) as commits,
|
|
|
|
sum(c.additions) - sum(c.deletions) as delta
|
2015-03-06 16:29:26 +00:00
|
|
|
from contribs c
|
|
|
|
join members m on
|
|
|
|
c.author = m.user and
|
|
|
|
c.owner = m.org
|
2015-03-08 11:17:56 +00:00
|
|
|
join teams t on
|
|
|
|
m.team_id = t.id
|
2015-03-06 16:29:26 +00:00
|
|
|
where
|
|
|
|
m.id is not null and
|
2015-03-08 11:17:56 +00:00
|
|
|
c.owner = :org and
|
|
|
|
c.week >= :from and
|
|
|
|
c.week <= :to
|
2015-03-06 16:29:26 +00:00
|
|
|
group by item
|
2015-03-08 11:17:56 +00:00
|
|
|
order by %s desc`
|
2015-03-06 16:29:26 +00:00
|
|
|
|
2015-03-08 11:17:56 +00:00
|
|
|
const orgActivityQuery = `
|
2015-03-06 16:29:26 +00:00
|
|
|
select
|
2015-03-08 11:17:56 +00:00
|
|
|
%s as item,
|
|
|
|
sum(c.commits) as commits,
|
|
|
|
sum(c.additions) - sum(c.deletions) as delta,
|
|
|
|
c.week as week
|
2015-03-06 16:29:26 +00:00
|
|
|
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
|
2015-03-08 11:17:56 +00:00
|
|
|
c.owner = :org and
|
|
|
|
c.week >= :from and
|
|
|
|
c.week <= :to
|
|
|
|
group by item, week
|
|
|
|
order by week, %s desc`
|
2015-03-06 16:29:26 +00:00
|
|
|
|
2015-03-08 11:17:56 +00:00
|
|
|
const teamTopQuery = `
|
2015-03-06 16:29:26 +00:00
|
|
|
select
|
2015-03-08 11:17:56 +00:00
|
|
|
%s as item,
|
|
|
|
sum(c.commits) as commits,
|
|
|
|
sum(c.additions) - sum(c.deletions) as delta
|
2015-03-06 16:29:26 +00:00
|
|
|
from contribs c
|
|
|
|
join members m on
|
|
|
|
c.author = m.user and
|
|
|
|
c.owner = m.org
|
|
|
|
join teams t on
|
2015-03-08 11:17:56 +00:00
|
|
|
m.team_id = t.id and
|
|
|
|
t.name = :team
|
2015-03-06 16:29:26 +00:00
|
|
|
where
|
|
|
|
m.id is not null and
|
2015-03-08 11:17:56 +00:00
|
|
|
c.owner = :org and
|
|
|
|
c.week >= :from and
|
|
|
|
c.week <= :to
|
|
|
|
group by item
|
2015-03-08 14:35:25 +00:00
|
|
|
order by commits desc`
|
2015-03-06 16:29:26 +00:00
|
|
|
|
2015-03-08 11:17:56 +00:00
|
|
|
const teamActivityQuery = `
|
2015-03-06 16:29:26 +00:00
|
|
|
select
|
2015-03-08 11:17:56 +00:00
|
|
|
%s as item,
|
|
|
|
sum(c.commits) as commits,
|
|
|
|
sum(c.additions) - sum(c.deletions) as delta,
|
|
|
|
c.week as week
|
2015-03-06 16:29:26 +00:00
|
|
|
from contribs c
|
|
|
|
join members m on
|
|
|
|
c.author = m.user and
|
|
|
|
c.owner = m.org
|
2015-03-08 11:17:56 +00:00
|
|
|
join teams t on
|
|
|
|
m.team_id = t.id and
|
|
|
|
t.name = :team
|
2015-03-06 16:29:26 +00:00
|
|
|
where
|
|
|
|
m.id is not null and
|
2015-03-08 11:17:56 +00:00
|
|
|
c.owner = :org and
|
|
|
|
c.week >= :from and
|
|
|
|
c.week <= :to
|
|
|
|
group by item, week
|
2015-03-08 14:35:25 +00:00
|
|
|
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`
|
2015-03-06 16:29:26 +00:00
|
|
|
|
2015-03-08 11:17:56 +00:00
|
|
|
func StatOrgTop(p map[string]interface{}) (res []StatItem) {
|
|
|
|
defer measure("StatOrgTop", time.Now())
|
|
|
|
mustSelectN(&res, fmt.Sprintf(orgTopQuery, p["item"], p["sort"]), p)
|
2015-03-06 16:29:26 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-03-08 11:17:56 +00:00
|
|
|
func StatOrgActivity(p map[string]interface{}) (res []StatPoint) {
|
|
|
|
defer measure("StatOrgActivity", time.Now())
|
|
|
|
mustSelectN(&res, fmt.Sprintf(orgActivityQuery, p["item"], p["sort"]), p)
|
2015-03-06 16:29:26 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-03-08 11:17:56 +00:00
|
|
|
func StatTeamTop(p map[string]interface{}) (res []StatItem) {
|
|
|
|
defer measure("StatTeamTop", time.Now())
|
|
|
|
mustSelectN(&res, fmt.Sprintf(teamTopQuery, p["item"], p["sort"]), p)
|
2015-03-06 16:29:26 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-03-08 11:17:56 +00:00
|
|
|
func StatTeamActivity(p map[string]interface{}) (res []StatPoint) {
|
|
|
|
defer measure("StatTeamActivity", time.Now())
|
|
|
|
mustSelectN(&res, fmt.Sprintf(teamActivityQuery, p["item"], p["sort"]), p)
|
2015-03-06 16:29:26 +00:00
|
|
|
return
|
|
|
|
}
|
2015-03-08 14:35:25 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|