fix: insight types

This commit is contained in:
NunoSempere 2022-10-09 12:52:01 +01:00
parent 0cddbf69b0
commit aff30ac0c4
2 changed files with 148 additions and 167 deletions

View File

@ -1,10 +1,11 @@
/* Imports */ /* Imports */
import axios from "axios"; import axios from "axios";
import { Tabletojson } from "tabletojson"; import {Tabletojson} from "tabletojson";
import { average } from "../../utils"; import {average} from "../../utils";
import { hash } from "../utils/hash"; import {hash} from "../utils/hash";
import { FetchedQuestion, Platform } from "./"; import {FetchedQuestion, Platform} from "./";
import {FullQuestionOption} from "../../common/types";
/* Definitions */ /* Definitions */
const platformName = "goodjudgment"; const platformName = "goodjudgment";
@ -41,21 +42,19 @@ export const goodjudgment: Platform = {
// }, // },
// }); // });
const content = await axios const content = await axios.request({
.request({
url: "https://goodjudgment.io/superforecasts/", url: "https://goodjudgment.io/superforecasts/",
method: "get", method: "get",
headers: { headers: {
"User-Agent": "Chrome", "User-Agent": "Chrome"
}, },
// agent, // agent,
// port: 80, // port: 80,
}) }).then((query) => query.data);
.then((query) => query.data);
// Processing // Processing
let results: FetchedQuestion[] = []; let results: FetchedQuestion[] = [];
let jsonTable = Tabletojson.convert(content, { stripHtmlFromCells: false }); let jsonTable = Tabletojson.convert(content, {stripHtmlFromCells: false});
jsonTable.shift(); // deletes first element jsonTable.shift(); // deletes first element
jsonTable.pop(); // deletes last element jsonTable.pop(); // deletes last element
@ -63,38 +62,21 @@ export const goodjudgment: Platform = {
let title = table[0]["0"].split("\t\t\t").splice(3)[0]; let title = table[0]["0"].split("\t\t\t").splice(3)[0];
if (title != undefined) { if (title != undefined) {
title = title.replaceAll("</a>", ""); title = title.replaceAll("</a>", "");
const id = `${platformName}-${hash(title)}`; const id = `${platformName}-${
const description = table hash(title)
.filter((row: any) => row["0"].includes("BACKGROUND:")) }`;
.map((row: any) => row["0"]) const description = table.filter((row : any) => row["0"].includes("BACKGROUND:")).map((row : any) => row["0"]).map((text : any) => 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];
.map((text: any) => const options = table.filter((row : any) => "4" in row).map((row : any) => ({
text name: row["2"].split('<span class="qTitle">')[1].replace("</span>", ""),
.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];
const options = table
.filter((row: any) => "4" in row)
.map((row: any) => ({
name: row["2"]
.split('<span class="qTitle">')[1]
.replace("</span>", ""),
probability: Number(row["3"].split("%")[0]) / 100, probability: Number(row["3"].split("%")[0]) / 100,
type: "PROBABILITY", type: "PROBABILITY"
})); }));
let analysis = table.filter((row: any) => let analysis = table.filter((row : any) => row[0] ? row[0].toLowerCase().includes("commentary") : false);
row[0] ? row[0].toLowerCase().includes("commentary") : false
);
// "Examples of Superforecaster Commentary" / Analysis // "Examples of Superforecaster Commentary" / Analysis
// The following is necessary twice, because we want to check if there is an empty list, and then get the first element of the first element of the list. // The following is necessary twice, 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] : ""; // not a duplicate analysis = analysis ? analysis[0] : "";
// not a duplicate
// console.log(analysis) // console.log(analysis)
let standardObj: FetchedQuestion = { let standardObj: FetchedQuestion = {
id, id,
@ -104,16 +86,14 @@ export const goodjudgment: Platform = {
options, options,
qualityindicators: {}, qualityindicators: {},
extra: { extra: {
superforecastercommentary: analysis || "", superforecastercommentary: analysis || ""
}, }
}; };
results.push(standardObj); results.push(standardObj);
} }
} }
console.log( console.log("Failing is not unexpected; see utils/pullSuperforecastsManually.sh/js");
"Failing is not unexpected; see utils/pullSuperforecastsManually.sh/js"
);
return results; return results;
}, },
@ -121,8 +101,8 @@ export const goodjudgment: Platform = {
let nuno = () => 4; let nuno = () => 4;
let eli = () => 4; let eli = () => 4;
let misha = () => 3.5; let misha = () => 3.5;
let starsDecimal = average([nuno()]); //, eli(), misha()]) let starsDecimal = average([nuno()]); // , eli(), misha()])
let starsInteger = Math.round(starsDecimal); let starsInteger = Math.round(starsDecimal);
return starsInteger; return starsInteger;
}, }
}; };

View File

@ -10,7 +10,8 @@ const getMarketEndpoint = (id : number) => `https://insightprediction.com/api/ma
/* Support functions */ /* Support functions */
async function fetchQuestionStats(bearer: string, marketId: number) { /*
async function fetchQuestionStats(bearer : string, marketId : number) {
const response = await axios({ const response = await axios({
url: getMarketEndpoint(marketId), url: getMarketEndpoint(marketId),
method: "GET", method: "GET",
@ -24,7 +25,7 @@ async function fetchQuestionStats(bearer: string, marketId: number) {
return response; return response;
} }
async function fetchPage(bearer: string, pageNum: number) { async function fetchPage(bearer : string, pageNum : number) {
const response = await axios({ const response = await axios({
url: `${marketsEnpoint}?page=${pageNum}`, // &orderBy=is_resolved&sortedBy=desc`, url: `${marketsEnpoint}?page=${pageNum}`, // &orderBy=is_resolved&sortedBy=desc`,
method: "GET", method: "GET",
@ -38,7 +39,7 @@ async function fetchPage(bearer: string, pageNum: number) {
return response; return response;
} }
async function fetchData(bearer: string) { async function fetchData(bearer : string) {
let pageNum = 1; let pageNum = 1;
let reachedEnd = false; let reachedEnd = false;
let results = []; let results = [];
@ -78,7 +79,7 @@ async function fetchData(bearer: string) {
return results return results
} }
async function processPredictions(predictions: any[]) { async function processPredictions(predictions : any[]) {
let results = await predictions.map((prediction) => { let results = await predictions.map((prediction) => {
const id = `${platformName}-${ const id = `${platformName}-${
prediction.id prediction.id
@ -110,19 +111,19 @@ async function processPredictions(predictions: any[]) {
}); });
return results; // resultsProcessed return results; // resultsProcessed
} }
*/
/* Body */ /* Body */
export const insight: Platform = { export const insight: Platform = {
name: platformName, name: platformName,
label: "Insight Prediction", label: "Insight Prediction",
color: "#ff0000", color: "#ff0000",
version: "v0", version: "v1",
async fetcher() { async fetcher() {
let bearer = process.env.INSIGHT_BEARER; let bearer = process.env.INSIGHT_BEARER;
let data = await fetchData(bearer); // let data = await fetchData(bearer);
// console.log(data); // console.log(data);
let results = []; // await processPredictions(data); // somehow needed let results: FetchedQuestion[] = []; // await processPredictions(data); // somehow needed
return results; return results;
}, },
calculateStars(data) { calculateStars(data) {