Skip to content

Instantly share code, notes, and snippets.

@svasva
Created August 24, 2013 16:38
Show Gist options
  • Save svasva/6329109 to your computer and use it in GitHub Desktop.
Save svasva/6329109 to your computer and use it in GitHub Desktop.
setHrates = function (curr) {
console.log(curr.name, hRates);
setHashrate = function(userId, name, wrkName, hashrate) {
var id, sel, _ref;
sel = {
userId: userId,
wrkName: wrkName,
currId: curr._id
};
if (id = (_ref = Hashrates.findOne(sel, {
fields: {
_id: 1
}
})) != null ? _ref._id : void 0) {
return Hashrates.update(id, {
$set: {
hashrate: hashrate,
name: name
}
});
} else {
return Hashrates.insert({
currId: curr._id,
userId: userId,
wrkName: wrkName,
hashrate: hashrate,
name: name
});
}
};
userNames = {};
userHrates = {};
for (name in hRates) {
hashrate = hRates[name];
_ref = name.split('.'), userId = _ref[0], wrkName = _ref[1];
userNames[userId] || (userNames[userId] = h.getNick(Meteor.users.findOne(userId)));
userHrates[userId] || (userHrates[userId] = 0);
userHrates[userId] += hashrate;
setHashrate(userId, userNames[userId], wrkName, hashrate);
}
for (userId in userHrates) {
hashrate = userHrates[userId];
setHashrate(userId, userNames[userId], '__total__', hashrate);
}
sel = {
currId: curr._id,
userId: {
$nin: _.keys(userHrates)
}
};
return 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