fix: recalculate manifold markets stars

This commit is contained in:
NunoSempere 2022-02-04 11:14:17 -05:00
parent a7c09e14ae
commit ba24ef7722
4 changed files with 161698 additions and 113058 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,85 +1,92 @@
/* Imports */
import axios from "axios"
import fs from "fs"
import { Tabletojson } from "tabletojson"
import toMarkdown from "../utils/toMarkdown.js"
import { calculateStars } from "../utils/stars.js"
import { upsert } from "../utils/mongo-wrapper.js"
import axios from "axios";
import fs from "fs";
import { Tabletojson } from "tabletojson";
import toMarkdown from "../utils/toMarkdown.js";
import { calculateStars } from "../utils/stars.js";
import { upsert } from "../utils/mongo-wrapper.js";
/* Definitions */
let endpoints = ["https://goodjudgment.io/superforecasts/", "https://goodjudgment.io/economist/"]
String.prototype.replaceAll = function replaceAll(search, replace) { return this.split(search).join(replace); }
let endpoints = [
"https://goodjudgment.io/superforecasts/",
"https://goodjudgment.io/economist/",
];
String.prototype.replaceAll = function replaceAll(search, replace) {
return this.split(search).join(replace);
};
/* Support functions */
/* Body */
export async function goodjudgment() {
let results = []
let results = [];
for (let endpoint of endpoints) {
let content = await axios.get(endpoint)
.then(query => query.data)
let jsonTable = Tabletojson.convert(content, { stripHtmlFromCells: false })
jsonTable.shift() // deletes first element
jsonTable.pop() // deletes last element
if (endpoint == endpoints[1]) jsonTable.pop() // pop again\
let content = await axios.get(endpoint).then((query) => query.data);
let jsonTable = Tabletojson.convert(content, { stripHtmlFromCells: false });
jsonTable.shift(); // deletes first element
jsonTable.pop(); // deletes last element
if (endpoint == endpoints[1]) jsonTable.pop(); // pop again\
// console.log(jsonTable)
for (let table of jsonTable) {
// console.log(table)
let title = table[0]['0']
.split("\t\t\t")
.splice(3)[0]
let title = table[0]["0"].split("\t\t\t").splice(3)[0];
let description = table
.filter(row => row['0'].includes("BACKGROUND:"))
.map(row => row['0'])
.map(text => text
.split("BACKGROUND:")[1]
.split("Examples of Superforecaster")[0]
.split("AT A GLANCE")[0]
.replaceAll("\n\n", "\n")
.split("\n")
.slice(3)
.join(" ")
.replaceAll(" ", "")
.replaceAll("<br> ", "")
)[0]
.filter((row) => row["0"].includes("BACKGROUND:"))
.map((row) => row["0"])
.map((text) =>
text
.split("BACKGROUND:")[1]
.split("Examples of Superforecaster")[0]
.split("AT A GLANCE")[0]
.replaceAll("\n\n", "\n")
.split("\n")
.slice(3)
.join(" ")
.replaceAll(" ", "")
.replaceAll("<br> ", "")
)[0];
let options = table
.filter(row => '4' in row)
.map(row => ({
name: row['2']
.split("<span class=\"qTitle\">")[1]
.filter((row) => "4" in row)
.map((row) => ({
name: row["2"]
.split('<span class="qTitle">')[1]
.replace("</span>", ""),
probability: Number(row['3'].split("%")[0]) / 100,
type: "PROBABILITY"
}))
let analysis = table.filter(row => row[0]? row[0].toLowerCase().includes("commentary") : false)
// "Examples of Superforecaster Commentary" / Analysis
probability: Number(row["3"].split("%")[0]) / 100,
type: "PROBABILITY",
}));
let analysis = table.filter((row) =>
row[0] ? row[0].toLowerCase().includes("commentary") : false
);
// "Examples of Superforecaster Commentary" / Analysis
// The following is necessary twite, because we want to check if there is an empty list, and then get the first element of the first element of the list.
analysis = analysis ? analysis[0] : ""
analysis = analysis ? analysis[0] : ""
analysis = analysis ? analysis[0] : "";
analysis = analysis ? analysis[0] : "";
// console.log(analysis)
let standardObj = ({
"title": title,
"url": endpoint,
"platform": "Good Judgment",
"description": description,
"options": options,
"timestamp": new Date().toISOString(),
"qualityindicators": {
"stars": calculateStars("Good Judgment", ({})),
let standardObj = {
title: title,
url: endpoint,
platform: "Good Judgment",
description: description,
options: options,
timestamp: new Date().toISOString(),
qualityindicators: {
stars: calculateStars("Good Judgment", {}),
},
"extra": {
"superforecastercommentary": analysis || ""
}
})
results.push(standardObj)
extra: {
superforecastercommentary: analysis || "",
},
};
if (standardObj.title != undefined) {
results.push(standardObj);
}
}
}
// console.log(results.slice(0,10))
let string = JSON.stringify(results, null, 2)
let string = JSON.stringify(results, null, 2);
// fs.writeFileSync('./data/goodjudgment-questions.json', string);
// fs.writeFileSync('./goodjudgment-questions-test.json', string);
console.log(results)
await upsert(results, "goodjudgment-questions")
console.log("Done")
console.log(results);
await upsert(results, "goodjudgment-questions");
console.log("Done");
}
// goodjudgment()

View File

@ -1,80 +1,100 @@
/* Imports */
import fs from 'fs'
import axios from "axios"
import { calculateStars } from "../utils/stars.js"
import { upsert } from "../utils/mongo-wrapper.js"
import fs from "fs";
import axios from "axios";
import { calculateStars } from "../utils/stars.js";
import { upsert } from "../utils/mongo-wrapper.js";
/* Definitions */
let endpoint = 'https://us-central1-mantic-markets.cloudfunctions.net/markets'
let endpoint = "https://us-central1-mantic-markets.cloudfunctions.net/markets";
/* Support functions */
async function fetchData() {
let response = await axios({
url: endpoint,
method: 'GET',
headers: ({
'Content-Type': 'text/html',
}),
})
.then(response => response.data)
// console.log(response)
return response
let response = await axios({
url: endpoint,
method: "GET",
headers: {
"Content-Type": "text/html",
},
}).then((response) => response.data);
// console.log(response)
return response;
}
function showStatistics(results) {
console.log(`Num unresolved markets: ${results.length}`);
let sum = (arr) => arr.reduce((tally, a) => tally + a, 0);
let num2StarsOrMore = results.filter(
(result) => result.qualityindicators.stars >= 2
);
console.log(
`Manifold has ${num2StarsOrMore.length} markets with 2 stars or more`
);
console.log(
`Mean volume: ${
sum(results.map((result) => result.qualityindicators.volume7Days)) /
results.length
}; mean pool: ${
sum(results.map((result) => result.qualityindicators.pool)) /
results.length
}`
);
}
async function processPredictions(predictions) {
let results = await predictions.map(prediction => {
let probability = prediction.probability
let options = [
{
"name": "Yes",
"probability": probability,
"type": "PROBABILITY"
},
{
"name": "No",
"probability": 1 - probability,
"type": "PROBABILITY"
}
]
let result = ({
"title": prediction.question,
"url": prediction.url,
"platform": "Manifold Markets",
"description": prediction.description,
"options": options,
"timestamp": new Date().toISOString(),
"qualityindicators": {
"stars": calculateStars("Manifold Markets", ({
volume7days: prediction.volume7days,
volume24Hours: prediction.volume24Hours,
pool: prediction.pool
})),
"createdTime": prediction.createdTime,
"volume7Days": prediction.volume7Days,
"volume24Hours": prediction.volume24Hours,
"pool": prediction.pool, // normally liquidity, but I don't actually want to show it.
},
"extra": {
"isResolved": prediction.isResolved
}
})
return result
})
let unresolvedResults = results.filter(result => !result.isResolved)
console.log(unresolvedResults)
return unresolvedResults //resultsProcessed
let results = await predictions.map((prediction) => {
let probability = prediction.probability;
let options = [
{
name: "Yes",
probability: probability,
type: "PROBABILITY",
},
{
name: "No",
probability: 1 - probability,
type: "PROBABILITY",
},
];
let result = {
title: prediction.question,
url: prediction.url,
platform: "Manifold Markets",
description: prediction.description,
options: options,
timestamp: new Date().toISOString(),
qualityindicators: {
stars: calculateStars("Manifold Markets", {
volume7Days: prediction.volume7Days,
volume24Hours: prediction.volume24Hours,
pool: prediction.pool,
}),
createdTime: prediction.createdTime,
volume7Days: prediction.volume7Days,
volume24Hours: prediction.volume24Hours,
pool: prediction.pool, // normally liquidity, but I don't actually want to show it.
},
extra: {
isResolved: prediction.isResolved,
},
};
return result;
});
let unresolvedResults = results.filter((result) => !result.extra.isResolved);
// console.log(unresolvedResults);
return unresolvedResults; //resultsProcessed
}
/* Body */
export async function manifoldmarkets() {
let data = await fetchData()
let results = await processPredictions(data) // somehow needed
// console.log(results)
// let string = JSON.stringify(results, null, 2)
// fs.writeFileSync('polyprediction-questions.json', string);
await upsert(results, "manifoldmarkets-questions")
console.log("Done")
let data = await fetchData();
let results = await processPredictions(data); // somehow needed
showStatistics(results);
// console.log(results)
// let string = JSON.stringify(results, null, 2)
// fs.writeFileSync('polyprediction-questions.json', string);
await upsert(results, "manifoldmarkets-questions");
console.log("Done");
}
// manifoldmarkets()