Skip to content

Instantly share code, notes, and snippets.

@svasva
Created August 24, 2013 10:30
Show Gist options
  • Save svasva/6327345 to your computer and use it in GitHub Desktop.
Save svasva/6327345 to your computer and use it in GitHub Desktop.
@Workers.fetchHashrates = (curr) ->
hRates = Meteor._mining.getWorkerHashrates(curr.miningTable, curr.hashrateInterval, curr.shareDiff)
setHashrate = (userId, name, wrkName, hashrate) ->
sel =
userId: userId
wrkName: wrkName
currId: curr._id
id = Hashrates.findOne(sel)
if id
Hashrates.update id, $set: {hashrate: hashrate, name: name}
else
Hashrates.insert
currId: curr._id
userId: userId
wrkName: wrkName
hashrate: hashrate
name: name
userNames = {}
userHrates = {}
for name, hashrate of hRates
[userId, wrkName] = name.split('.')
unless userNames[userId]
userNames[userId] = h.getNick(Meteor.users.findOne(userId))
userHrates[userId] ||= 0
userHrates[userId] += hashrate
setHashrate(userId, userNames[userId], wrkName, hashrate)
for userId, hashrate of userHrates
setHashrate(userId, userNames[userId], '__total__', hashrate)
sel =
currId: curr._id
userId: {$nin: _.keys(userHrates)}
Hashrates.update sel, {$set: {hashrate: 0}}, {multi: true}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment