Merge branch 'master' into user
This commit is contained in:
commit
c710b917a7
1 changed files with 20 additions and 53 deletions
73
mapreduce.go
73
mapreduce.go
|
@ -230,11 +230,6 @@ func (m *MR) GetMonthVisits(start time.Time, statsColl *mgo.Collection) ([]Visit
|
||||||
|
|
||||||
func (m *MR) GetHourDownloads(start time.Time, statsColl *mgo.Collection) ([]Visits, error) {
|
func (m *MR) GetHourDownloads(start time.Time, statsColl *mgo.Collection) ([]Visits, error) {
|
||||||
if m.isOutdated(HOURLY_DOWNLOADS_COLL, MINUTES_UPDATE_HOURLY) {
|
if m.isOutdated(HOURLY_DOWNLOADS_COLL, MINUTES_UPDATE_HOURLY) {
|
||||||
const reduce = `function(date, vals) {
|
|
||||||
var count = 0;
|
|
||||||
vals.forEach(function(v) { count += v; });
|
|
||||||
return count;
|
|
||||||
}`
|
|
||||||
var mr mgo.MapReduce
|
var mr mgo.MapReduce
|
||||||
mr.Map = `function() {
|
mr.Map = `function() {
|
||||||
if (this.section == "download") {
|
if (this.section == "download") {
|
||||||
|
@ -245,18 +240,12 @@ func (m *MR) GetHourDownloads(start time.Time, statsColl *mgo.Collection) ([]Vis
|
||||||
emit({date: date}, 1);
|
emit({date: date}, 1);
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
mr.Reduce = reduce
|
mr.Reduce = `function(date, vals) {
|
||||||
err := m.update(&mr, bson.M{"date": bson.M{"$gte": start}}, statsColl, HOURLY_DOWNLOADS_COLL+"_raw")
|
var count = 0;
|
||||||
if err != nil {
|
vals.forEach(function(v) { count += v; });
|
||||||
return nil, err
|
return count;
|
||||||
}
|
}`
|
||||||
var mr2 mgo.MapReduce
|
err := m.update(&mr, bson.M{"date": bson.M{"$gte": start}}, statsColl, HOURLY_DOWNLOADS_COLL)
|
||||||
mr2.Map = `function() {
|
|
||||||
emit(this['_id']['date'], 1);
|
|
||||||
}`
|
|
||||||
mr2.Reduce = reduce
|
|
||||||
hourly_raw := m.database.C(HOURLY_DOWNLOADS_COLL + "_raw")
|
|
||||||
err = m.update(&mr2, bson.M{}, hourly_raw, HOURLY_DOWNLOADS_COLL)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -270,32 +259,21 @@ func (m *MR) GetHourDownloads(start time.Time, statsColl *mgo.Collection) ([]Vis
|
||||||
|
|
||||||
func (m *MR) GetDayDowloads(start time.Time, statsColl *mgo.Collection) ([]Visits, error) {
|
func (m *MR) GetDayDowloads(start time.Time, statsColl *mgo.Collection) ([]Visits, error) {
|
||||||
if m.isOutdated(DAILY_DOWNLOADS_COLL, MINUTES_UPDATE_DAILY) {
|
if m.isOutdated(DAILY_DOWNLOADS_COLL, MINUTES_UPDATE_DAILY) {
|
||||||
const reduce = `function(date, vals) {
|
|
||||||
var count = 0;
|
|
||||||
vals.forEach(function(v) { count += v; });
|
|
||||||
return count;
|
|
||||||
}`
|
|
||||||
var mr mgo.MapReduce
|
var mr mgo.MapReduce
|
||||||
mr.Map = `function() {
|
mr.Map = `function() {
|
||||||
if (this.section == "download") {
|
if (this.section == "download") {
|
||||||
var date = Date.UTC(this.date.getUTCFullYear(),
|
var date = Date.UTC(this.date.getUTCFullYear(),
|
||||||
this.date.getUTCMonth(),
|
this.date.getUTCMonth(),
|
||||||
this.date.getUTCDate());
|
this.date.getUTCDate());
|
||||||
emit({date: date, session: this.session}, 1);
|
emit({date: date}, 1);
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
mr.Reduce = reduce
|
mr.Reduce = `function(date, vals) {
|
||||||
err := m.update(&mr, bson.M{"date": bson.M{"$gte": start}}, statsColl, DAILY_DOWNLOADS_COLL+"_raw")
|
var count = 0;
|
||||||
if err != nil {
|
vals.forEach(function(v) { count += v; });
|
||||||
return nil, err
|
return count;
|
||||||
}
|
}`
|
||||||
var mr2 mgo.MapReduce
|
err := m.update(&mr, bson.M{"date": bson.M{"$gte": start}}, statsColl, DAILY_DOWNLOADS_COLL)
|
||||||
mr2.Map = `function() {
|
|
||||||
emit(this['_id']['date'], 1);
|
|
||||||
}`
|
|
||||||
mr2.Reduce = reduce
|
|
||||||
daily_raw := m.database.C(DAILY_DOWNLOADS_COLL + "_raw")
|
|
||||||
err = m.update(&mr2, bson.M{}, daily_raw, DAILY_DOWNLOADS_COLL)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -309,31 +287,20 @@ func (m *MR) GetDayDowloads(start time.Time, statsColl *mgo.Collection) ([]Visit
|
||||||
|
|
||||||
func (m *MR) GetMonthDowloads(start time.Time, statsColl *mgo.Collection) ([]Visits, error) {
|
func (m *MR) GetMonthDowloads(start time.Time, statsColl *mgo.Collection) ([]Visits, error) {
|
||||||
if m.isOutdated(MONTHLY_DOWNLOADS_COLL, MINUTES_UPDATE_MONTHLY) {
|
if m.isOutdated(MONTHLY_DOWNLOADS_COLL, MINUTES_UPDATE_MONTHLY) {
|
||||||
const reduce = `function(date, vals) {
|
|
||||||
var count = 0;
|
|
||||||
vals.forEach(function(v) { count += v; });
|
|
||||||
return count;
|
|
||||||
}`
|
|
||||||
var mr mgo.MapReduce
|
var mr mgo.MapReduce
|
||||||
mr.Map = `function() {
|
mr.Map = `function() {
|
||||||
if (this.section == "download") {
|
if (this.section == "download") {
|
||||||
var date = Date.UTC(this.date.getUTCFullYear(),
|
var date = Date.UTC(this.date.getUTCFullYear(),
|
||||||
this.date.getUTCMonth());
|
this.date.getUTCMonth());
|
||||||
emit({date: date, session: this.session}, 1);
|
emit({date: date}, 1);
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
mr.Reduce = reduce
|
mr.Reduce = `function(date, vals) {
|
||||||
err := m.update(&mr, bson.M{"date": bson.M{"$gte": start}}, statsColl, MONTHLY_DOWNLOADS_COLL+"_raw")
|
var count = 0;
|
||||||
if err != nil {
|
vals.forEach(function(v) { count += v; });
|
||||||
return nil, err
|
return count;
|
||||||
}
|
}`
|
||||||
var mr2 mgo.MapReduce
|
err := m.update(&mr, bson.M{"date": bson.M{"$gte": start}}, statsColl, MONTHLY_DOWNLOADS_COLL)
|
||||||
mr2.Map = `function() {
|
|
||||||
emit(this['_id']['date'], 1);
|
|
||||||
}`
|
|
||||||
mr2.Reduce = reduce
|
|
||||||
monthly_raw := m.database.C(MONTHLY_DOWNLOADS_COLL + "_raw")
|
|
||||||
err = m.update(&mr2, bson.M{}, monthly_raw, MONTHLY_DOWNLOADS_COLL)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue