adjustments to elicit script

stars, ordering of description and platform, formatting
This commit is contained in:
Eli Lifland 2021-04-14 13:56:24 -04:00
parent f092c800ab
commit 2c5aad61d1

View File

@ -1,50 +1,57 @@
/* Imports */ /* Imports */
import fs from "fs" import fs from "fs";
import { mongoReadWithReadCredentials } from "../mongo-wrapper.js" import { mongoReadWithReadCredentials } from "../mongo-wrapper.js";
/* Definitions */ /* Definitions */
let locationData = "./data/" let locationData = "./data/";
/* Body */ /* Body */
// let rawdata = fs.readFileSync("./data/merged-questions.json") // run from topmost folder, not from src // let rawdata = fs.readFileSync("./data/merged-questions.json") // run from topmost folder, not from src
async function main(){ async function main() {
let data = await mongoReadWithReadCredentials("metaforecasts") //JSON.parse(rawdata) let data = await mongoReadWithReadCredentials("metaforecasts"); //JSON.parse(rawdata)
let processDescription = (description) => { let processDescription = (description) => {
if(description == null || description == undefined || description == ""){ if (description == null || description == undefined || description == "") {
return "" return "";
}else{ } else {
description = description==null?"":description description =
.replaceAll("] (", "](") description == null
.replaceAll(") )", "))") ? ""
.replaceAll("( [", "([") : description
.replaceAll(") ,", "),") .replaceAll("] (", "](")
.replaceAll("\n", " ") .replaceAll(") )", "))")
if(description.length > 1000){ .replaceAll("( [", "([")
return(description.slice(0,1000)+"...") .replaceAll(") ,", "),")
}else{ .replaceAll("\n", " ");
return(description) if (description.length > 1000) {
return description.slice(0, 1000) + "...";
} else {
return description;
} }
} }
} };
let results = [] let results = [];
for(let datum of data){ for (let datum of data) {
// do something // do something
let description = processDescription(datum["description"]) let description = processDescription(datum["description"]);
let forecasts = datum["qualityindicators"] ? datum["qualityindicators"].numforecasts : "unknown" let forecasts = datum["qualityindicators"]
let stars = datum["qualityindicators"] ? datum["qualityindicators"].stars : 2 ? datum["qualityindicators"].numforecasts
results.push("Title: "+datum["title"]) : "unknown";
results.push("URL: "+datum["url"]) let stars = datum["qualityindicators"]
results.push("Platform: "+datum["platform"]) ? datum["qualityindicators"].stars
results.push("Description: "+description) : 2;
results.push("Number of forecasts: "+ forecasts) results.push("Title: " + datum["title"]);
results.push("Stars: "+forecasts) results.push("URL: " + datum["url"]);
results.push("\n") results.push("Description: " + description);
results.push("Platform: " + datum["platform"]);
results.push("Number of forecasts: " + forecasts);
results.push("Stars: " + stars);
results.push("\n");
} }
let string = results.join("\n") let string = results.join("\n");
string = string.replaceAll("\n\n", "\n") string = string.replaceAll("\n\n", "\n");
fs.writeFileSync("elicit-output.txt", string) fs.writeFileSync("elicit-output.txt", string);
} }
main() main();