Created
August 25, 2013 10:50
-
-
Save svasva/6333226 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Workers.fetchHashrates = (curr) -> | |
Meteor._mining.getWorkerHashrates curr.miningTable, curr.hashrateInterval, curr.shareDiff, (hRates) -> | |
console.log curr.name, hRates | |
setHashrate = (userId, name, wrkName, hashrate) -> | |
sel = | |
userId: userId | |
wrkName: wrkName | |
currId: curr._id | |
if id = Hashrates.findOne(sel, {fields: {_id: 1}})?._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 stat in hRates | |
[userId, wrkName] = stat.username.split('.') | |
userNames[userId] ||= h.getNick(Meteor.users.findOne(userId)) | |
userHrates[userId] ||= 0 | |
userHrates[userId] += stat.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