Skip to content
Snippets Groups Projects
Commit 7cb07d29 authored by Rodrigo Nascimento's avatar Rodrigo Nascimento
Browse files

Replace all MapReducedStatistics

parent 306eaab2
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@ Package.onUse(function(api) {
// Statistics
api.addFiles('lib/rocketchat.coffee', [ 'client', 'server' ]);
api.addFiles([
'server/models/MRStatistics.coffee',
'server/collections/Statistics.coffee',
'server/functions/get.coffee',
'server/functions/save.coffee',
......
@MapReducedStatistics = new Meteor.Collection 'rocketchat_mr_statistics'
......@@ -55,18 +55,18 @@ RocketChat.statistics.get = ->
statistics.avgChannelUsers = 0
statistics.avgPrivateGroupUsers = 0
if MapReducedStatistics.findOne({ _id: 1 })
statistics.maxRoomUsers = MapReducedStatistics.findOne({ _id: 1 }).value.max
if RocketChat.models.MRStatistics.findOneById(1)
statistics.maxRoomUsers = RocketChat.models.MRStatistics.findOneById(1).value.max
else
console.log 'max room user statistic not found'.red
if MapReducedStatistics.findOne({ _id: 'c' })
statistics.avgChannelUsers = MapReducedStatistics.findOne({ _id: 'c' }).value.avg
if RocketChat.models.MRStatistics.findOneById('c')
statistics.avgChannelUsers = RocketChat.models.MRStatistics.findOneById('c').value.avg
else
console.log 'channel user statistic not found'.red
if MapReducedStatistics.findOne({ _id: 'p' })
statistics.avgPrivateGroupUsers = MapReducedStatistics.findOne({ _id: 'p' }).value.avg
if RocketChat.models.MRStatistics.findOneById('p')
statistics.avgPrivateGroupUsers = RocketChat.models.MRStatistics.findOneById('p').value.avg
else
console.log 'private group user statistic not found'.red
......
RocketChat.statistics.getAverage = ->
statistics = {}
m = ->
d = this.createdAt
this.count = 1
......@@ -30,7 +30,7 @@ RocketChat.statistics.getAverage = ->
a.os.loadavg[1] += b.os.loadavg[1]
a.os.loadavg[2] += b.os.loadavg[2]
return a
f = (k, v) ->
out = {}
out.totalUsers = v.totalUsers / v.count
......@@ -54,5 +54,5 @@ RocketChat.statistics.getAverage = ->
return out
result = Statistics.mapReduce(m, r, { finalize: f, out: "rocketchat_mr_statistics" })
statistics = MapReducedStatistics.find().fetch()
return statistics
\ No newline at end of file
statistics = RocketChat.models.MRStatistics.find().fetch()
return statistics
RocketChat.models.MRStatistics = new class asd extends RocketChat.models._Base
constructor: ->
@model = new Meteor.Collection 'rocketchat_mr_statistics'
# FIND ONE
findOneById: (_id, options) ->
query =
_id: _id
return @findOne query, options
# # FIND
# findByMention: (username, options) ->
# query =
# "mentions.username": username
# return @find query, options
# # UPDATE
# setHiddenById: (_id, hidden=true) ->
# query =
# _id: _id
# update =
# $set:
# _hidden: hidden
# return @update query, update
# # INSERT
# createWithTypeRoomIdMessageAndUser: (type, roomId, message, user, extraData) ->
# record =
# t: type
# rid: roomId
# ts: new Date
# msg: message
# u:
# _id: user._id
# username: user.username
# _.extend record, extraData
# record._id = @insert record
# return record
# # REMOVE
# removeById: (_id) ->
# query =
# _id: _id
# return @remove query
@MapReducedStatistics = new Mongo.Collection 'rocketchat_mr_statistics'
@ChatReports = new Meteor.Collection 'rocketchat_reports'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment