feat: xrisk and givewellopenphil backend platforms

This commit is contained in:
Vyacheslav Matyukhin 2022-03-30 19:53:22 +03:00
parent 49d8140784
commit f9e8f320a0
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C
5 changed files with 45 additions and 40 deletions

View File

@ -1,20 +0,0 @@
import fs from "fs";
import { databaseUpsert } from "../database/database-wrapper";
/* This is necessary for estimize, the database of x-risk estimates, and for the OpenPhil/GiveWell predictions. Unlike the others, I'm not fetching them constantly, but only once. */
let pushManualFiles = ["givewellopenphil"]; // ["estimize", "givewellopenphil", "xrisk"]
let suffixFiles = "-questions.json";
let main = async () => {
for (let file of pushManualFiles) {
let fileRaw = fs.readFileSync(`./input/${file + suffixFiles}`, {
encoding: "utf-8",
});
let fileContents = JSON.parse(fileRaw);
console.log(fileContents);
await databaseUpsert({ contents: fileContents, group: file });
}
};
main();

View File

@ -4,9 +4,10 @@ import fs from "fs";
import { databaseUpsert } from "../database/database-wrapper";
import { calculateStars } from "../utils/stars";
import { Platform } from "./";
/* Support functions */
async function fetchPage(url) {
async function fetchPage(url: string) {
let response = await axios({
url: url,
method: "GET",
@ -14,7 +15,6 @@ async function fetchPage(url) {
"Content-Type": "text/html",
},
}).then((res) => res.data);
//console.log(response)
return response;
}
@ -64,17 +64,20 @@ async function main1() {
group: "givewell-questions-unprocessed",
});
}
// main1()
async function main2() {
let rawdata = fs.readFileSync("./input/givewellopenphil-questions.json", {
encoding: "utf-8",
});
let data = JSON.parse(rawdata);
let dataWithDate = data.map((datum) => ({
...datum,
timestamp: "2021-02-23",
}));
await databaseUpsert({ group: "givewellopenphil", contents: dataWithDate });
}
main2();
export const givewellopenphil: Platform = {
name: "givewellopenphil",
async fetcher() {
// main1()
return; // not necessary to refill the DB every time
const rawdata = fs.readFileSync("./input/givewellopenphil-questions.json", {
encoding: "utf-8",
});
const data = JSON.parse(rawdata);
const dataWithDate = data.map((datum: any) => ({
...datum,
timestamp: "2021-02-23",
}));
return dataWithDate;
},
};

View File

@ -2,6 +2,7 @@ import { databaseUpsert } from "../database/database-wrapper";
import { betfair } from "./betfair";
import { fantasyscotus } from "./fantasyscotus";
import { foretold } from "./foretold";
import { givewellopenphil } from "./givewellopenphil";
import { goodjudgment } from "./goodjudgment";
import { goodjudmentopen } from "./goodjudmentopen";
import { infer } from "./infer";
@ -13,6 +14,7 @@ import { predictit } from "./predictit";
import { rootclaim } from "./rootclaim";
import { smarkets } from "./smarkets";
import { wildeford } from "./wildeford";
import { xrisk } from "./xrisk";
export interface Forecast {
id: string;
@ -31,7 +33,7 @@ export type PlatformFetcher = () => Promise<Forecast[] | null>;
export interface Platform {
name: string;
fetcher: PlatformFetcher;
fetcher?: PlatformFetcher;
}
// draft for the future callback-based streaming/chunking API:
@ -53,6 +55,7 @@ export const platforms: Platform[] = [
betfair,
fantasyscotus,
foretold,
givewellopenphil,
goodjudgment,
goodjudmentopen,
infer,
@ -64,9 +67,14 @@ export const platforms: Platform[] = [
rootclaim,
smarkets,
wildeford,
xrisk,
];
export const processPlatform = async (platform: Platform) => {
if (!platform.fetcher) {
console.log(`Platform ${platform.name} doesn't have a fetcher, skipping`);
return;
}
let results = await platform.fetcher();
if (results && results.length) {
await databaseUpsert({ contents: results, group: platform.name });

View File

@ -0,0 +1,15 @@
import fs from "fs";
import { Platform } from "./";
export const xrisk: Platform = {
name: "xrisk",
async fetcher() {
return; // not necessary to refill the DB every time
let fileRaw = fs.readFileSync("./input/xrisk-questions.json", {
encoding: "utf-8",
});
const results = JSON.parse(fileRaw);
return results;
},
};

View File

@ -5,10 +5,9 @@ import fs from "fs";
let locationData = "../../data/";
/* Body */
let rawdata = fs.readFileSync(
"/home/nuno/Documents/core/software/fresh/js/metaforecasts/metaforecasts-mongo/src/input/xrisk-questions.json",
{ encoding: "utf-8" }
);
let rawdata = fs.readFileSync("./input/xrisk-questions.json", {
encoding: "utf-8",
});
let data = JSON.parse(rawdata);
let results = [];