1
0
Fork 0
empact/db/stat.go

133 lines
2.6 KiB
Go
Raw Normal View History

2015-03-06 16:29:26 +00:00
package db
import (
"time"
)
type (
StatItem struct {
Item string `json:"item"`
Value int `json:"value"`
}
StatPoint struct {
StatItem
Timestamp uint64 `json:"ts"`
}
)
const orgReposTopQuery = `
select
c.repo as item,
sum(c.commits) as value
from contribs c
join members m on
c.author = m.user and
c.owner = m.org
where
m.id is not null and
c.owner = ? and
c.week >= ? and
c.week <= ?
group by item
order by value desc`
const orgReposActivityQuery = `
select
c.week as ts,
c.repo as item,
sum(c.commits) as value
from contribs c
join members m on
c.author = m.user and
c.owner = m.org
where
m.id is not null and
c.owner = ? and
c.week >= ? and
c.week <= ?
group by ts, item
order by ts, item`
const orgTeamsTopQuery = `
select
t.name as item,
sum(c.commits) value
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 = ? and
c.week >= ? and
c.week <= ?
group by item
order by value desc`
const orgTeamsActivityQuery = `
select
c.week as ts,
t.name as item,
sum(c.commits) as value
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 = ? and
c.week >= ? and
c.week <= ?
group by ts, item
order by ts, item`
const orgUsersTopQuery = `
select
c.author as item,
sum(c.commits) value
from contribs c
join members m on
c.author = m.user and
c.owner = m.org
where
m.id is not null and
c.owner = ? and
c.week >= ? and
c.week <= ?
group by item
order by value desc`
2015-03-07 14:56:02 +00:00
func StatOrgReposTop(org string, from, to int64) (res []StatItem) {
2015-03-06 16:29:26 +00:00
defer measure("StatOrgReposTop", time.Now())
2015-03-07 14:56:02 +00:00
mustSelect(&res, orgReposTopQuery, org, from, to)
2015-03-06 16:29:26 +00:00
return
}
2015-03-07 14:56:02 +00:00
func StatOrgReposActivity(org string, from, to int64) (res []StatPoint) {
2015-03-06 16:29:26 +00:00
defer measure("StatOrgReposActivity", time.Now())
2015-03-07 14:56:02 +00:00
mustSelect(&res, orgReposActivityQuery, org, from, to)
2015-03-06 16:29:26 +00:00
return
}
2015-03-07 14:56:02 +00:00
func StatOrgTeamsTop(org string, from, to int64) (res []StatItem) {
2015-03-06 16:29:26 +00:00
defer measure("StatOrgTeamsTop", time.Now())
2015-03-07 14:56:02 +00:00
mustSelect(&res, orgTeamsTopQuery, org, from, to)
2015-03-06 16:29:26 +00:00
return
}
2015-03-07 14:56:02 +00:00
func StatOrgTeamsActivity(org string, from, to int64) (res []StatPoint) {
2015-03-06 16:29:26 +00:00
defer measure("StatOrgTeamsActivity", time.Now())
2015-03-07 14:56:02 +00:00
mustSelect(&res, orgTeamsActivityQuery, org, from, to)
2015-03-06 16:29:26 +00:00
return
}
2015-03-07 14:56:02 +00:00
func StatOrgUsersTop(org string, from, to int64) (res []StatItem) {
2015-03-06 16:29:26 +00:00
defer measure("StatOrgUsersTop", time.Now())
2015-03-07 14:56:02 +00:00
mustSelect(&res, orgUsersTopQuery, org, from, to)
2015-03-06 16:29:26 +00:00
return
}