lila/bin/mongodb/set-ratings.js

46 lines
948 B
JavaScript
Raw Normal View History

2020-06-06 11:50:16 -06:00
const perf = 'rapid';
const ratings = {
2021-02-06 06:26:05 -07:00
STL_Caruana: 2773,
STL_Dominguez: 2786,
STL_So: 2741,
STL_Carlsen: 2881,
2020-06-06 11:50:16 -06:00
'STL_Vachier-Lagrave': 2860,
2021-02-06 06:26:05 -07:00
STL_Grischuk: 2784,
STL_Aronian: 2778,
STL_Xiong: 2730,
2020-06-06 11:50:16 -06:00
};
for (k of Object.keys(ratings)) {
const rating = ratings[k];
const id = k.toLowerCase();
2021-02-06 06:26:05 -07:00
const user = db.user4.findOne({ _id: id });
2020-06-06 11:50:16 -06:00
if (user.perfs[perf] && user.perfs[perf].nb) {
const set = { [`perfs.${perf}.gl.r`]: rating };
2021-02-06 06:26:05 -07:00
const push = {
2020-06-06 11:50:16 -06:00
[`perfs.${perf}.re`]: {
$each: [NumberInt(rating)],
2021-02-06 06:26:05 -07:00
$position: 0,
},
2020-06-06 11:50:16 -06:00
};
2021-02-06 06:26:05 -07:00
db.user4.update({ _id: id }, { $set: set, $push: push });
} else {
db.user4.update(
{ _id: id },
{
$set: {
[`perfs.${perf}`]: {
gl: {
r: rating,
d: 150,
v: 0.06,
},
nb: NumberInt(0),
re: [],
},
2020-06-06 11:50:16 -06:00
},
}
2021-02-06 06:26:05 -07:00
);
2020-06-06 11:50:16 -06:00
}
}