Updated stat queries for new db schema
This commit is contained in:
parent
22fca9f4e1
commit
f96c88a1fa
@ -17,7 +17,7 @@ var Menu = React.createClass({
|
|||||||
return (
|
return (
|
||||||
<li key={'team-'+ team.name} className="nav team">
|
<li key={'team-'+ team.name} className="nav team">
|
||||||
<ReactRouter.Link to="team"
|
<ReactRouter.Link to="team"
|
||||||
params={{org: team.owner, team: team.name}}
|
params={{org: this.getParams().org, team: team.name}}
|
||||||
query={this.getQuery()}>
|
query={this.getQuery()}>
|
||||||
{team.name}
|
{team.name}
|
||||||
</ReactRouter.Link>
|
</ReactRouter.Link>
|
||||||
|
293
db/stat.go
293
db/stat.go
@ -17,194 +17,187 @@ type (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const orgTopQuery = `
|
const joinContribFT = `
|
||||||
select
|
join team_members tm on
|
||||||
%s as item,
|
c.user_id = tm.user_id and
|
||||||
sum(c.commits) as commits,
|
c.org_id = tm.org_id
|
||||||
sum(c.additions) - sum(c.deletions) as delta
|
join orgs o on
|
||||||
from contribs c
|
c.org_id = o.id
|
||||||
join members m on
|
|
||||||
c.author = m.user and
|
|
||||||
c.owner = m.org
|
|
||||||
join teams t on
|
join teams t on
|
||||||
m.team_id = t.id
|
tm.team_id = t.id
|
||||||
where
|
join users u on
|
||||||
c.owner = :org and
|
c.user_id = u.id
|
||||||
c.week >= :from and
|
join repos r on
|
||||||
c.week <= :to
|
c.repo_id = r.id`
|
||||||
group by item
|
|
||||||
order by commits desc`
|
|
||||||
|
|
||||||
const orgActivityQuery = `
|
|
||||||
select
|
|
||||||
%s as item,
|
|
||||||
sum(c.commits) as commits,
|
|
||||||
sum(c.additions) - sum(c.deletions) as delta,
|
|
||||||
c.week as week
|
|
||||||
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
|
|
||||||
c.owner = :org and
|
|
||||||
c.week >= :from and
|
|
||||||
c.week <= :to
|
|
||||||
group by item, week
|
|
||||||
order by week, commits desc`
|
|
||||||
|
|
||||||
const teamTopQuery = `
|
|
||||||
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 and
|
|
||||||
t.name = :team
|
|
||||||
where
|
|
||||||
c.owner = :org and
|
|
||||||
c.week >= :from and
|
|
||||||
c.week <= :to
|
|
||||||
group by item
|
|
||||||
order by commits desc`
|
|
||||||
|
|
||||||
const teamActivityQuery = `
|
|
||||||
select
|
|
||||||
%s as item,
|
|
||||||
sum(c.commits) as commits,
|
|
||||||
sum(c.additions) - sum(c.deletions) as delta,
|
|
||||||
c.week as week
|
|
||||||
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 and
|
|
||||||
t.name = :team
|
|
||||||
where
|
|
||||||
c.owner = :org and
|
|
||||||
c.week >= :from and
|
|
||||||
c.week <= :to
|
|
||||||
group by item, week
|
|
||||||
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.author = :user 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.author = :user 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
|
|
||||||
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 week,
|
|
||||||
%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
|
|
||||||
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) {
|
func StatOrgTop(p map[string]interface{}) (res []StatItem) {
|
||||||
defer measure("StatOrgTop", time.Now())
|
defer measure("StatOrgTop", time.Now())
|
||||||
mustSelectN(&res, fmt.Sprintf(orgTopQuery, p["item"]), p)
|
mustSelectN(&res, fmt.Sprintf(`
|
||||||
|
select
|
||||||
|
%s as item,
|
||||||
|
sum(c.commits) as commits,
|
||||||
|
sum(c.additions) - sum(c.deletions) as delta
|
||||||
|
from contribs c
|
||||||
|
`+joinContribFT+`
|
||||||
|
where
|
||||||
|
o.login = :org and
|
||||||
|
c.week >= :from and
|
||||||
|
c.week <= :to
|
||||||
|
group by item
|
||||||
|
order by commits desc
|
||||||
|
`, p["item"]), p)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func StatOrgActivity(p map[string]interface{}) (res []StatPoint) {
|
func StatOrgActivity(p map[string]interface{}) (res []StatPoint) {
|
||||||
defer measure("StatOrgActivity", time.Now())
|
defer measure("StatOrgActivity", time.Now())
|
||||||
mustSelectN(&res, fmt.Sprintf(orgActivityQuery, p["item"]), p)
|
mustSelectN(&res, fmt.Sprintf(`
|
||||||
|
select
|
||||||
|
%s as item,
|
||||||
|
sum(c.commits) as commits,
|
||||||
|
sum(c.additions) - sum(c.deletions) as delta,
|
||||||
|
c.week as week
|
||||||
|
from contribs c
|
||||||
|
`+joinContribFT+`
|
||||||
|
where
|
||||||
|
o.login = :org and
|
||||||
|
c.week >= :from and
|
||||||
|
c.week <= :to
|
||||||
|
group by item, week
|
||||||
|
order by week, commits desc
|
||||||
|
`, p["item"]), p)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func StatTeamTop(p map[string]interface{}) (res []StatItem) {
|
func StatTeamTop(p map[string]interface{}) (res []StatItem) {
|
||||||
defer measure("StatTeamTop", time.Now())
|
defer measure("StatTeamTop", time.Now())
|
||||||
mustSelectN(&res, fmt.Sprintf(teamTopQuery, p["item"]), p)
|
mustSelectN(&res, fmt.Sprintf(`
|
||||||
|
select
|
||||||
|
%s as item,
|
||||||
|
sum(c.commits) as commits,
|
||||||
|
sum(c.additions) - sum(c.deletions) as delta
|
||||||
|
from contribs c
|
||||||
|
`+joinContribFT+`
|
||||||
|
where
|
||||||
|
o.login = :org and
|
||||||
|
t.name = :team and
|
||||||
|
c.week >= :from and
|
||||||
|
c.week <= :to
|
||||||
|
group by item
|
||||||
|
order by commits desc
|
||||||
|
`, p["item"]), p)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func StatTeamActivity(p map[string]interface{}) (res []StatPoint) {
|
func StatTeamActivity(p map[string]interface{}) (res []StatPoint) {
|
||||||
defer measure("StatTeamActivity", time.Now())
|
defer measure("StatTeamActivity", time.Now())
|
||||||
mustSelectN(&res, fmt.Sprintf(teamActivityQuery, p["item"]), p)
|
mustSelectN(&res, fmt.Sprintf(`
|
||||||
|
select
|
||||||
|
%s as item,
|
||||||
|
sum(c.commits) as commits,
|
||||||
|
sum(c.additions) - sum(c.deletions) as delta,
|
||||||
|
c.week as week
|
||||||
|
from contribs c
|
||||||
|
`+joinContribFT+`
|
||||||
|
where
|
||||||
|
o.login = :org and
|
||||||
|
t.name = :team and
|
||||||
|
c.week >= :from and
|
||||||
|
c.week <= :to
|
||||||
|
group by item, week
|
||||||
|
order by week, commits desc
|
||||||
|
`, p["item"]), p)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func StatUserTop(p map[string]interface{}) (res []StatItem) {
|
func StatUserTop(p map[string]interface{}) (res []StatItem) {
|
||||||
defer measure("StatUserTop", time.Now())
|
defer measure("StatUserTop", time.Now())
|
||||||
mustSelectN(&res, userTopQuery, p)
|
mustSelectN(&res, `
|
||||||
|
select
|
||||||
|
r.name as item,
|
||||||
|
sum(c.commits) as commits,
|
||||||
|
sum(c.additions) - sum(c.deletions) as delta
|
||||||
|
from contribs c
|
||||||
|
join orgs o on
|
||||||
|
c.org_id = o.id
|
||||||
|
join users u on
|
||||||
|
c.user_id = u.id
|
||||||
|
join repos r on
|
||||||
|
c.repo_id = r.id
|
||||||
|
where
|
||||||
|
o.login = :org and
|
||||||
|
u.login = :user and
|
||||||
|
c.week >= :from and
|
||||||
|
c.week <= :to
|
||||||
|
group by item
|
||||||
|
order by commits desc
|
||||||
|
`, p)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func StatUserActivity(p map[string]interface{}) (res []StatPoint) {
|
func StatUserActivity(p map[string]interface{}) (res []StatPoint) {
|
||||||
defer measure("StatUserActivity", time.Now())
|
defer measure("StatUserActivity", time.Now())
|
||||||
mustSelectN(&res, userActivityQuery, p)
|
mustSelectN(&res, `
|
||||||
|
select
|
||||||
|
c.week as week,
|
||||||
|
r.name as item,
|
||||||
|
sum(c.commits) as commits,
|
||||||
|
sum(c.additions) - sum(c.deletions) as delta
|
||||||
|
from contribs c
|
||||||
|
join orgs o on
|
||||||
|
c.org_id = o.id
|
||||||
|
join users u on
|
||||||
|
c.user_id = u.id
|
||||||
|
join repos r on
|
||||||
|
c.repo_id = r.id
|
||||||
|
where
|
||||||
|
o.login = :org and
|
||||||
|
u.login = :user and
|
||||||
|
c.week >= :from and
|
||||||
|
c.week <= :to
|
||||||
|
group by item
|
||||||
|
order by week, commits desc
|
||||||
|
`, p)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func StatRepoTop(p map[string]interface{}) (res []StatItem) {
|
func StatRepoTop(p map[string]interface{}) (res []StatItem) {
|
||||||
defer measure("StatRepoTop", time.Now())
|
defer measure("StatRepoTop", time.Now())
|
||||||
mustSelectN(&res, fmt.Sprintf(repoTopQuery, p["item"]), p)
|
mustSelectN(&res, fmt.Sprintf(`
|
||||||
|
select
|
||||||
|
%s as item,
|
||||||
|
sum(c.commits) as commits,
|
||||||
|
sum(c.additions) - sum(c.deletions) as delta
|
||||||
|
from contribs c
|
||||||
|
`+joinContribFT+`
|
||||||
|
where
|
||||||
|
o.login = :org and
|
||||||
|
r.name = :repo and
|
||||||
|
c.week >= :from and
|
||||||
|
c.week <= :to
|
||||||
|
group by item
|
||||||
|
order by commits desc
|
||||||
|
`, p["item"]), p)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func StatRepoActivity(p map[string]interface{}) (res []StatPoint) {
|
func StatRepoActivity(p map[string]interface{}) (res []StatPoint) {
|
||||||
defer measure("StatRepoActivity", time.Now())
|
defer measure("StatRepoActivity", time.Now())
|
||||||
mustSelectN(&res, fmt.Sprintf(repoActivityQuery, p["item"]), p)
|
mustSelectN(&res, fmt.Sprintf(`
|
||||||
|
select
|
||||||
|
c.week as week,
|
||||||
|
%s as item,
|
||||||
|
sum(c.commits) as commits,
|
||||||
|
sum(c.additions) - sum(c.deletions) as delta
|
||||||
|
from contribs c
|
||||||
|
`+joinContribFT+`
|
||||||
|
where
|
||||||
|
o.login = :org and
|
||||||
|
r.name = :repo and
|
||||||
|
c.week >= :from and
|
||||||
|
c.week <= :to
|
||||||
|
group by week, item
|
||||||
|
order by commits desc
|
||||||
|
`, p["item"]), p)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -81,11 +81,11 @@ func parseStatRequest(r *http.Request) *statRequest {
|
|||||||
var item string
|
var item string
|
||||||
switch val := r.FormValue("item"); val {
|
switch val := r.FormValue("item"); val {
|
||||||
case "author", "user":
|
case "author", "user":
|
||||||
item = "c.author"
|
item = "u.login"
|
||||||
case "team":
|
case "team":
|
||||||
item = "t.name"
|
item = "t.name"
|
||||||
default:
|
default:
|
||||||
item = "c.repo"
|
item = "r.name"
|
||||||
}
|
}
|
||||||
|
|
||||||
return &statRequest{
|
return &statRequest{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user