tweak: Pull predictions to frontpage
This commit is contained in:
parent
1462580d44
commit
36e3d4af46
54081
data/frontpage.json
Normal file
54081
data/frontpage.json
Normal file
File diff suppressed because one or more lines are too long
110249
metaforecasts.json
110249
metaforecasts.json
File diff suppressed because one or more lines are too long
42
src/utils/downloadFrontpage.js
Normal file
42
src/utils/downloadFrontpage.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
import fs from "fs"
|
||||
|
||||
import { mongoReadWithReadCredentials } from "./mongo-wrapper.js"
|
||||
|
||||
let filename = 'frontpage.json'
|
||||
let shuffle = (array) => {
|
||||
// https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
|
||||
let currentIndex = array.length, randomIndex;
|
||||
|
||||
// While there remain elements to shuffle...
|
||||
while (currentIndex != 0) {
|
||||
|
||||
// Pick a remaining element...
|
||||
randomIndex = Math.floor(Math.random() * currentIndex);
|
||||
currentIndex--;
|
||||
|
||||
// And swap it with the current element.
|
||||
[array[currentIndex], array[randomIndex]] = [
|
||||
array[randomIndex], array[currentIndex]];
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
let main = async () => {
|
||||
let init = Date.now()
|
||||
|
||||
let json = await mongoReadWithReadCredentials("metaforecasts")
|
||||
|
||||
json = json.filter(forecast => (forecast.qualityindicators && forecast.qualityindicators.stars >= 3) && (forecast.options && forecast.options.length > 0 && forecast.platform != "AstralCodexTen"))
|
||||
json = shuffle(json)
|
||||
|
||||
let string = JSON.stringify(json, null, 2)
|
||||
fs.writeFileSync(filename, string);
|
||||
console.log(`File downloaded to ./${filename}`)
|
||||
|
||||
let end = Date.now()
|
||||
let difference = end - init
|
||||
console.log(`Took ${difference / 1000} seconds, or ${difference / (1000 * 60)} minutes.`)
|
||||
|
||||
}
|
||||
main()
|
Loading…
Reference in New Issue
Block a user