feat: Added infer
This commit is contained in:
		
							parent
							
								
									68a7feb6e6
								
							
						
					
					
						commit
						20c9c820fb
					
				|  | @ -1,8 +1,8 @@ | ||||||
| /* Imports */ | /* Imports */ | ||||||
| import fs from 'fs' | import fs from 'fs' | ||||||
| import axios from "axios" | import axios from "axios" | ||||||
| import { calculateStars } from "../utils/stars.js" | import { calculateStars } from "../../utils/stars.js" | ||||||
| import {upsert} from "../utils/mongo-wrapper.js" | import {upsert} from "../../utils/mongo-wrapper.js" | ||||||
| 
 | 
 | ||||||
| /* Definitions */ | /* Definitions */ | ||||||
| let graphQLendpoint = "https://api.thegraph.com/subgraphs/name/protofire/omen" | let graphQLendpoint = "https://api.thegraph.com/subgraphs/name/protofire/omen" | ||||||
|  |  | ||||||
|  | @ -7,11 +7,11 @@ import { calculateStars } from "../utils/stars.js" | ||||||
| import { upsert } from "../utils/mongo-wrapper.js" | import { upsert } from "../utils/mongo-wrapper.js" | ||||||
| 
 | 
 | ||||||
| /* Definitions */ | /* Definitions */ | ||||||
| let htmlEndPoint = 'https://www.cset-foretell.com/questions?page=' | let htmlEndPoint = 'https://www.infer-pub.com/questions' | ||||||
| String.prototype.replaceAll = function replaceAll(search, replace) { return this.split(search).join(replace); } | String.prototype.replaceAll = function replaceAll(search, replace) { return this.split(search).join(replace); } | ||||||
| const DEBUG_MODE = "on"// "off"
 | const DEBUG_MODE = "on"// "off"
 | ||||||
| const SLEEP_TIME_RANDOM=100//5000 // miliseconds
 | const SLEEP_TIME_RANDOM = 7000 // miliseconds
 | ||||||
| const SLEEP_TIME_EXTRA=0//1000
 | const SLEEP_TIME_EXTRA = 2000 | ||||||
| /* Support functions */ | /* Support functions */ | ||||||
| 
 | 
 | ||||||
| async function fetchPage(page, cookie) { | async function fetchPage(page, cookie) { | ||||||
|  | @ -19,7 +19,7 @@ async function fetchPage(page, cookie) { | ||||||
|   if (page == 1) { |   if (page == 1) { | ||||||
|     cookie = cookie.split(";")[0] // Interesting that it otherwise doesn't work :(
 |     cookie = cookie.split(";")[0] // Interesting that it otherwise doesn't work :(
 | ||||||
|   } |   } | ||||||
|   let urlEndpoint = htmlEndPoint + page |   let urlEndpoint = `${htmlEndPoint}/?page=${page}` | ||||||
|   console.log(urlEndpoint) |   console.log(urlEndpoint) | ||||||
|   let response = await axios({ |   let response = await axios({ | ||||||
|     url: urlEndpoint, |     url: urlEndpoint, | ||||||
|  | @ -132,7 +132,7 @@ async function fetchStats(questionUrl, cookie) { | ||||||
|     "qualityindicators": { |     "qualityindicators": { | ||||||
|       "numforecasts": Number(numforecasts), |       "numforecasts": Number(numforecasts), | ||||||
|       "numforecasters": Number(numforecasters), |       "numforecasters": Number(numforecasters), | ||||||
|       "stars": calculateStars("CSET-foretell", { numforecasts }) |       "stars": calculateStars("Infer", { numforecasts }) | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -164,7 +164,7 @@ function sleep(ms) { | ||||||
| 
 | 
 | ||||||
| /* Body */ | /* Body */ | ||||||
| 
 | 
 | ||||||
| async function csetforetell_inner(cookie) { | async function infer_inner(cookie) { | ||||||
|   let i = 1 |   let i = 1 | ||||||
|   let response = await fetchPage(i, cookie) |   let response = await fetchPage(i, cookie) | ||||||
|   let results = [] |   let results = [] | ||||||
|  | @ -174,9 +174,9 @@ async function csetforetell_inner(cookie) { | ||||||
| 
 | 
 | ||||||
|     let htmlLines = response.split("\n") |     let htmlLines = response.split("\n") | ||||||
|     // let h4elements = htmlLines.filter(str => str.includes("<h5> <a href=") || str.includes("<h4> <a href="))
 |     // let h4elements = htmlLines.filter(str => str.includes("<h5> <a href=") || str.includes("<h4> <a href="))
 | ||||||
|     let questionHrefs = htmlLines.filter(str => str.includes("https://www.cset-foretell.com/questions/")) |     let questionHrefs = htmlLines.filter(str => str.includes("https://www.infer-pub.com/questions/")) | ||||||
|     // console.log(questionHrefs)
 |     // console.log(questionHrefs)
 | ||||||
|      | 
 | ||||||
| 
 | 
 | ||||||
|     if (process.env.DEBUG_MODE == "on" || DEBUG_MODE == "on") { |     if (process.env.DEBUG_MODE == "on" || DEBUG_MODE == "on") { | ||||||
|       //console.log(response)
 |       //console.log(response)
 | ||||||
|  | @ -201,7 +201,7 @@ async function csetforetell_inner(cookie) { | ||||||
|         let question = ({ |         let question = ({ | ||||||
|           "title": title, |           "title": title, | ||||||
|           "url": url, |           "url": url, | ||||||
|           "platform": "CSET-foretell", |           "platform": "Infer", | ||||||
|           ...moreinfo |           ...moreinfo | ||||||
|         }) |         }) | ||||||
|         if (i % 30 == 0 && !(process.env.DEBUG_MODE == "on" || DEBUG_MODE == "on")) { |         if (i % 30 == 0 && !(process.env.DEBUG_MODE == "on" || DEBUG_MODE == "on")) { | ||||||
|  | @ -223,7 +223,7 @@ async function csetforetell_inner(cookie) { | ||||||
|     i++ |     i++ | ||||||
|     //i=Number(i)+1
 |     //i=Number(i)+1
 | ||||||
| 
 | 
 | ||||||
|     console.log("Sleeping for ~5secs so as to not be as noticeable to the cset-foretell servers") |     console.log("Sleeping for ~5secs so as to not be as noticeable to the infer servers") | ||||||
|     await sleep(Math.random() * SLEEP_TIME_RANDOM + SLEEP_TIME_EXTRA) // don't be as noticeable
 |     await sleep(Math.random() * SLEEP_TIME_RANDOM + SLEEP_TIME_EXTRA) // don't be as noticeable
 | ||||||
| 
 | 
 | ||||||
|     try { |     try { | ||||||
|  | @ -234,10 +234,10 @@ async function csetforetell_inner(cookie) { | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   // let string = JSON.stringify(results,null,  2)
 |   // let string = JSON.stringify(results,null,  2)
 | ||||||
|   // fs.writeFileSync('./data/csetforetell-questions.json', string);
 |   // fs.writeFileSync('./data/infer-questions.json', string);
 | ||||||
|   // console.log(results)
 |   // console.log(results)
 | ||||||
|   if (results.length > 0) { |   if (results.length > 0) { | ||||||
|     await upsert(results, "csetforetell-questions") |     await upsert(results, "infer-questions") | ||||||
|   } else { |   } else { | ||||||
|     console.log("Not updating results, as process was not signed in") |     console.log("Not updating results, as process was not signed in") | ||||||
|   } |   } | ||||||
|  | @ -249,6 +249,6 @@ async function csetforetell_inner(cookie) { | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| export async function infer() { | export async function infer() { | ||||||
|   let cookie = process.env.CSETFORETELL_COOKIE || getCookie("csetforetell") |   let cookie = process.env.INFER_COOKIE || getCookie("infer") | ||||||
|   await applyIfCookieExists(cookie, csetforetell_inner) |   await applyIfCookieExists(cookie, infer_inner) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -10,8 +10,7 @@ import {upsert} from "../utils/mongo-wrapper.js" | ||||||
| /* Definitions */ | /* Definitions */ | ||||||
| const SHEET_ID = "1xcgYF7Q0D95TPHLLSgwhWBHFrWZUGJn7yTyAhDR4vi0" // spreadsheet key is the long id in the sheets URL
 | const SHEET_ID = "1xcgYF7Q0D95TPHLLSgwhWBHFrWZUGJn7yTyAhDR4vi0" // spreadsheet key is the long id in the sheets URL
 | ||||||
| const endpoint = `https://docs.google.com/spreadsheets/d/${SHEET_ID}/edit#gid=0` | const endpoint = `https://docs.google.com/spreadsheets/d/${SHEET_ID}/edit#gid=0` | ||||||
| // https://docs.google.com/spreadsheets/d/1xcgYF7Q0D95TPHLLSgwhWBHFrWZUGJn7yTyAhDR4vi0/edit#gid=0&range=C4
 | // https://docs.google.com/spreadsheets/d/1xcgYF7Q0D95TPHLLSgwhWBHFrWZUGJn7yTyAhDR4vi0/edit#gid=0
 | ||||||
| 
 |  | ||||||
| /* Support functions */ | /* Support functions */ | ||||||
| 
 | 
 | ||||||
| const formatRow = row => { | const formatRow = row => { | ||||||
|  | @ -106,7 +105,7 @@ async function processPredictions(predictions){ | ||||||
| export async function wildeford_inner(google_api_key) { | export async function wildeford_inner(google_api_key) { | ||||||
|   let predictions = await fetchGoogleDoc(google_api_key) |   let predictions = await fetchGoogleDoc(google_api_key) | ||||||
|   let results = await processPredictions(predictions) // somehow needed
 |   let results = await processPredictions(predictions) // somehow needed
 | ||||||
|   // console.log(results)
 |   // console.log(results.sort((a,b) => (a.title > b.title)))
 | ||||||
|   // let string = JSON.stringify(results, null, 2)
 |   // let string = JSON.stringify(results, null, 2)
 | ||||||
|   // fs.writeFileSync('polyprediction-questions.json', string);
 |   // fs.writeFileSync('polyprediction-questions.json', string);
 | ||||||
|   await upsert(results, "wildeford-questions") |   await upsert(results, "wildeford-questions") | ||||||
|  |  | ||||||
|  | @ -110,6 +110,8 @@ let processResults = (html) => { | ||||||
|         "stars": calculateStars("WilliamHill", ({})) |         "stars": calculateStars("WilliamHill", ({})) | ||||||
|       } |       } | ||||||
|     }) |     }) | ||||||
|  |     results = results.filter(result => result.title.length > 4 && result.title != "2024 or later")  | ||||||
|  |       // removes some predictions because hard to parse.
 | ||||||
|     results.push(obj) |     results.push(obj) | ||||||
|   } |   } | ||||||
|    |    | ||||||
|  | @ -128,7 +130,7 @@ export async function williamhill() { | ||||||
|   // let string = JSON.stringify(results, null, 2)
 |   // let string = JSON.stringify(results, null, 2)
 | ||||||
|   // fs.writeFileSync('./data/williamhill-questions.json', string);
 |   // fs.writeFileSync('./data/williamhill-questions.json', string);
 | ||||||
|   await upsert(results, "williamhill-questions") |   await upsert(results, "williamhill-questions") | ||||||
| 
 |   console.log(results.sort((a,b) => (a.title > b.title))) | ||||||
|   console.log("Done") |   console.log("Done") | ||||||
| } | } | ||||||
| //williamhill()
 | //williamhill()
 | ||||||
|  |  | ||||||
|  | @ -1,39 +1,13 @@ | ||||||
| import { mongoRead, upsert } from "./mongo-wrapper.js"; | import { mongoRead, upsert } from "./mongo-wrapper.js"; | ||||||
| import { platformNames } from "./platforms.js" | import { platformNames } from "./platforms.js" | ||||||
| /* Merge everything */ | /* Merge everything */ | ||||||
| // let sets = ["astralcodexten", "betfair", "coupcast", "csetforetell", "elicit", /* "estimize" ,*/ "fantasyscotus", "foretold", "givewellopenphil", "goodjudgment","goodjudmentopen", "hypermind", "kalshi", "ladbrokes", "manifoldmarkets", "metaculus", "omen", "polymarket", "predictit", "rootclaim", "smarkets", "wildeford", "williamhill", "xrisk"]
 |  | ||||||
| let sets = [ |  | ||||||
|   "betfair", |  | ||||||
|   "coupcast", |  | ||||||
|   "csetforetell", |  | ||||||
|   "elicit", |  | ||||||
|   /* "estimize" ,*/ "fantasyscotus", |  | ||||||
|   "foretold", |  | ||||||
|   "givewellopenphil", |  | ||||||
|   "goodjudgment", |  | ||||||
|   "goodjudmentopen", |  | ||||||
|   "hypermind", |  | ||||||
|   "kalshi", |  | ||||||
|   "ladbrokes", |  | ||||||
|   "manifoldmarkets", |  | ||||||
|   "metaculus", |  | ||||||
|   "omen", |  | ||||||
|   "polymarket", |  | ||||||
|   "predictit", |  | ||||||
|   "rootclaim", |  | ||||||
|   "smarkets", |  | ||||||
|   "wildeford", |  | ||||||
|   "williamhill", |  | ||||||
|   "xrisk", |  | ||||||
| ]; |  | ||||||
| 
 |  | ||||||
| let suffix = "-questions"; | let suffix = "-questions"; | ||||||
| 
 | 
 | ||||||
| export async function mergeEverythingInner() { | export async function mergeEverythingInner() { | ||||||
|   let merged = []; |   let merged = []; | ||||||
|   for (let set of sets) { |   for (let platformName of platformNames) { | ||||||
|     let json = await mongoRead(set + suffix); |     let json = await mongoRead(platformName + suffix); | ||||||
|     console.log(`${set} has ${json.length} questions\n`); |     console.log(`${platformName} has ${json.length} questions\n`); | ||||||
|     merged = merged.concat(json); |     merged = merged.concat(json); | ||||||
|   } |   } | ||||||
|   let mergedprocessed = merged.map((element) => ({ |   let mergedprocessed = merged.map((element) => ({ | ||||||
|  |  | ||||||
|  | @ -32,6 +32,7 @@ export const platformNames = [ | ||||||
|   "givewellopenphil", |   "givewellopenphil", | ||||||
|   "goodjudgment", |   "goodjudgment", | ||||||
|   "goodjudmentopen", |   "goodjudmentopen", | ||||||
|  |   "infer", | ||||||
|   "kalshi", |   "kalshi", | ||||||
|   "ladbrokes", |   "ladbrokes", | ||||||
|   "manifoldmarkets", |   "manifoldmarkets", | ||||||
|  |  | ||||||
|  | @ -133,6 +133,15 @@ function calculateStarsHypermind(data) { | ||||||
|   return starsInteger; |   return starsInteger; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | function calculateStarsInfer(data) { | ||||||
|  |   let nuno = (data) => 2; | ||||||
|  |   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 calculateStarsKalshi(data) { | function calculateStarsKalshi(data) { | ||||||
|   let nuno = (data) => |   let nuno = (data) => | ||||||
|     data.interest > 500 && data.shares_volume > 10000 |     data.interest > 500 && data.shares_volume > 10000 | ||||||
|  | @ -295,6 +304,9 @@ export function calculateStars(platform, data) { | ||||||
|     case "Hypermind": |     case "Hypermind": | ||||||
|       stars = calculateStarsHypermind(data); |       stars = calculateStarsHypermind(data); | ||||||
|       break; |       break; | ||||||
|  |     case "Infer": | ||||||
|  |       stars = calculateStarsInfer(data);   | ||||||
|  |       break; | ||||||
|     case "Kalshi": |     case "Kalshi": | ||||||
|       stars = calculateStarsKalshi(data); |       stars = calculateStarsKalshi(data); | ||||||
|       break; |       break; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user