From 13481b8b0bac265466bcb3e4282634ad1cb3ae6b Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sun, 27 Jun 2021 19:22:54 +0200 Subject: [PATCH] Added Rootclaim to backend --- src/index.js | 5 ++- src/platforms/rootclaim-fetch.js | 67 ++++++++++++++++++++++++++++++++ src/utils/doEverything.js | 5 ++- src/utils/mergeEverything.js | 2 +- src/utils/stars.js | 12 ++++++ 5 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 src/platforms/rootclaim-fetch.js diff --git a/src/index.js b/src/index.js index 3137add..ec4d406 100644 --- a/src/index.js +++ b/src/index.js @@ -14,9 +14,10 @@ import {goodjudgmentopen} from "./platforms/goodjudmentopen-fetch.js" import {hypermind} from "./platforms/hypermind-fetch.js" import {ladbrokes} from "./platforms/ladbrokes-fetch.js" import {metaculus} from "./platforms/metaculus-fetch.js" +import {omen} from "./platforms/omen-fetch.js" import {polymarket} from "./platforms/polymarket-fetch.js" import {predictit} from "./platforms/predictit-fetch.js" -import {omen} from "./platforms/omen-fetch.js" +import {rootclaim} from "./platforms/rootclaim-fetch.js" import {smarkets} from "./platforms/smarkets-fetch.js" import {williamhill} from "./platforms/williamhill-fetch.js" @@ -26,7 +27,7 @@ import {rebuildNetlifySiteWithNewData} from "./utils/rebuildNetliftySiteWithNewD import {doEverything, tryCatchTryAgain} from "./utils/doEverything.js" /* Support functions */ -let functions = [astralcodexten, coupcast, csetforetell, elicit, /* estimize, */ fantasyscotus, foretold, goodjudgment, goodjudgmentopen, hypermind, ladbrokes, metaculus, polymarket, predictit, omen, smarkets, williamhill, mergeEverything, addToHistory, rebuildNetlifySiteWithNewData, doEverything] +let functions = [astralcodexten, coupcast, csetforetell, elicit, /* estimize, */ fantasyscotus, foretold, goodjudgment, goodjudgmentopen, hypermind, ladbrokes, metaculus, omen, polymarket, predictit, rootclaim, smarkets, williamhill, mergeEverything, addToHistory, rebuildNetlifySiteWithNewData, doEverything] let functionNames = functions.map(fun => fun.name) let whattodoMessage = functionNames diff --git a/src/platforms/rootclaim-fetch.js b/src/platforms/rootclaim-fetch.js new file mode 100644 index 0000000..e8888be --- /dev/null +++ b/src/platforms/rootclaim-fetch.js @@ -0,0 +1,67 @@ +/* Imports */ +import fs from 'fs' +import axios from "axios" +import { calculateStars } from "../utils/stars.js" +import {upsert} from "../utils/mongo-wrapper.js" + +/* Definitions */ +let jsonEndpoint = "https://www.rootclaim.com/main_page_stories?number=100&offset=0"//"https://subgraph-matic.poly.market/subgraphs/name/TokenUnion/polymarket"//"https://subgraph-backup.poly.market/subgraphs/name/TokenUnion/polymarket"//'https://subgraph-matic.poly.market/subgraphs/name/TokenUnion/polymarket3' + +/* Support functions +async function fetchAllContractInfo(){ // for info which the polymarket graphql API + let data = fs.readFileSync("./data/polymarket-contract-list.json") + let response = JSON.parse(data) + return response +} + */ +async function fetchAllRootclaims() { // for info which the polymarket graphql API + let response = await axios.get(jsonEndpoint) + .then(response => response.data) + if(response.length != (response[0]+1)){ + console.log(response.length) + console.log(response[0]) + //throw Error("Rootclaim's backend has changed.") + } + response.shift() + return response +} + +async function fetchAndProcessData() { + let claims = await fetchAllRootclaims() + let results = [] + for (let claim of claims) { + let options = [] + for (let scenario in claim.scenarios) { + options.push({ + "name": scenario.name, + "probability": scenario.net_prob / 100, + "type": "PROBABILITY" + }) + } + let obj = ({ + "title": claim.question, + "url": "https://www.rootclaim.com/analysis/"+claim.slug, + "platform": "Rootclaim", + "description": claim.background, + "options": options, + "timestamp": new Date().toISOString(), + "qualityindicators": { + "numforecasts": 1, + "stars": calculateStars("Rootclaim", ({})) + } + }) + results.push(obj) + } + return results +} + +/* Body */ +export async function rootclaim() { + let results = await fetchAndProcessData() + // console.log(results) + // let string = JSON.stringify(results, null, 2) + // fs.writeFileSync('rootclaim-questions.json', string); + await upsert(results, "rootclaim-questions") + console.log("Done") +} +//rootclaim() diff --git a/src/utils/doEverything.js b/src/utils/doEverything.js index a2343a6..4a280d9 100644 --- a/src/utils/doEverything.js +++ b/src/utils/doEverything.js @@ -10,9 +10,10 @@ import {goodjudgmentopen} from "../platforms/goodjudmentopen-fetch.js" import {hypermind} from "../platforms/hypermind-fetch.js" import {ladbrokes} from "../platforms/ladbrokes-fetch.js" import {metaculus} from "../platforms/metaculus-fetch.js" +import {omen} from "../platforms/omen-fetch.js" import {polymarket} from "../platforms/polymarket-fetch.js" import {predictit} from "../platforms/predictit-fetch.js" -import {omen} from "../platforms/omen-fetch.js" +import {rootclaim} from "../platforms/rootclaim-fetch.js" import {smarkets} from "../platforms/smarkets-fetch.js" import {williamhill} from "../platforms/williamhill-fetch.js" import {mergeEverything} from "./mergeEverything.js" @@ -36,7 +37,7 @@ export async function tryCatchTryAgain (fun) { } } export async function doEverything(){ - let functions = [coupcast, csetforetell, elicit, /* estimize, */ fantasyscotus, foretold, /* goodjudgment, */ goodjudgmentopen, hypermind, ladbrokes, metaculus, polymarket, predictit, omen, smarkets, williamhill, mergeEverything, /*addToHistory,*/rebuildNetlifySiteWithNewData] + let functions = [coupcast, csetforetell, elicit, /* estimize, */ fantasyscotus, foretold, /* goodjudgment, */ goodjudgmentopen, hypermind, ladbrokes, metaculus, omen, polymarket, predictit, rootclaim, smarkets, williamhill, mergeEverything, /*addToHistory,*/rebuildNetlifySiteWithNewData] // Removed Good Judgment from the fetcher, doing it using cron instead because cloudflare blocks the utility on heroku. console.log("") diff --git a/src/utils/mergeEverything.js b/src/utils/mergeEverything.js index 496c261..3fe5c87 100644 --- a/src/utils/mergeEverything.js +++ b/src/utils/mergeEverything.js @@ -1,7 +1,7 @@ import { mongoRead, upsert } from "./mongo-wrapper.js" /* Merge everything */ -let sets = ["astralcodexten","coupcast", "csetforetell", "elicit", "estimize", "fantasyscotus", "foretold", "givewellopenphil", "goodjudgment","goodjudmentopen", "hypermind", "ladbrokes", "metaculus", "polymarket", "predictit", "omen", "smarkets", "williamhill", "xrisk"] +let sets = ["astralcodexten","coupcast", "csetforetell", "elicit", "estimize", "fantasyscotus", "foretold", "givewellopenphil", "goodjudgment","goodjudmentopen", "hypermind", "ladbrokes", "metaculus", "omen", "polymarket", "predictit", "rootclaim", "smarkets", "williamhill", "xrisk"] let suffix = "-questions" export async function mergeEverything(){ diff --git a/src/utils/stars.js b/src/utils/stars.js index 34dba03..211e284 100644 --- a/src/utils/stars.js +++ b/src/utils/stars.js @@ -167,6 +167,15 @@ function calculateStarsPredictIt(data) { return starsInteger } +function calculateStarsRootclaim(data) { + let nuno = data => 4 + let eli = (data) => null + let misha = (data) => null + let starsDecimal = average([nuno(data)/*, eli(data), misha(data)*/]) + let starsInteger = Math.round(starsDecimal) + return starsInteger +} + function calculateStarsSmarkets(data) { let nuno = data => 2 let eli = (data) => null @@ -233,6 +242,9 @@ export function calculateStars(platform, data) { case "PredictIt": stars = calculateStarsPredictIt(data) break; + case "Rootclaim": + stars = calculateStarsRootclaim(data) + break; case "Smarkets": stars = calculateStarsSmarkets(data) break;