-
Notifications
You must be signed in to change notification settings - Fork 6
/
goodjudgment.ts
129 lines (121 loc) · 3.73 KB
/
goodjudgment.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Imports */
import axios from "axios";
import { Tabletojson } from "tabletojson";
import { average } from "../../utils";
import { hash } from "../utils/hash";
import { FetchedQuestion, Platform } from "./";
/* Definitions */
const platformName = "goodjudgment";
const endpoint = "https://goodjudgment.io/superforecasts/";
/* Body */
export const goodjudgment: Platform = {
name: platformName,
label: "Good Judgment",
color: "#7d4f1b",
version: "v1",
async fetcher() {
// Proxy fuckery
// let proxy;
/*
* try {
proxy = await axios
.get("http://pubproxy.com/api/proxy")
.then((query) => query.data);
console.log(proxy);
} catch (error) {
console.log("Proxy generation failed; using backup proxy instead");
// hard-coded backup proxy
*/
// proxy = {
// ip: ...
// port: ...
// };
// // }
// let agent = tunnel.httpsOverHttp({
// proxy: {
// host: proxy.ip,
// port: proxy.port,
// },
// });
const content = await axios
.request({
url: "https://goodjudgment.io/superforecasts/",
method: "get",
headers: {
"User-Agent": "Firefox",
},
// agent,
// port: 80,
})
.then((query) => query.data);
// Processing
let results: FetchedQuestion[] = [];
let jsonTable = Tabletojson.convert(content, { stripHtmlFromCells: false });
jsonTable.shift(); // deletes first element
jsonTable.pop(); // deletes last element
for (let table of jsonTable) {
let title = table[0]["0"].split("\t\t\t").splice(3)[0];
if (title != undefined) {
title = title.replaceAll("</a>", "");
const id = `${platformName}-${hash(title)}`;
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];
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,
type: "PROBABILITY",
}));
let analysis = table.filter((row: any) =>
row[0] ? row[0].toLowerCase().includes("commentary") : false
);
// "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.
analysis = analysis ? analysis[0] : "";
analysis = analysis ? analysis[0] : "";
// not a duplicate
// console.log(analysis)
let standardObj: FetchedQuestion = {
id,
title,
url: endpoint,
description,
options,
qualityindicators: {},
extra: {
superforecastercommentary: analysis || "",
},
};
results.push(standardObj);
}
}
console.log(
"Note that failing is not unexpected; see utils/pullSuperforecastsManually.sh/js"
);
return results;
},
calculateStars(data) {
let nuno = () => 4;
let eli = () => 4;
let misha = () => 3.5;
let starsDecimal = average([nuno()]); // , eli(), misha()])
let starsInteger = Math.round(starsDecimal);
return starsInteger;
},
};