fix: platform names, dashboards, cleanups

This commit is contained in:
Vyacheslav Matyukhin 2022-04-02 02:25:12 +03:00
parent 1461002070
commit 1b6ff8d440
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C
10 changed files with 92 additions and 108 deletions

View File

@ -5,7 +5,8 @@ import { calculateStars } from "../utils/stars";
import { Platform } from "./"; import { Platform } from "./";
/* Definitions */ /* Definitions */
let endpoint = "https://example.com/"; const platformName = "example";
const endpoint = "https://example.com/";
/* Support functions */ /* Support functions */
@ -23,7 +24,7 @@ async function fetchData() {
async function processPredictions(predictions) { async function processPredictions(predictions) {
let results = await predictions.map((prediction) => { let results = await predictions.map((prediction) => {
let id = `example-${prediction.id}`; let id = `${platformName}-${prediction.id}`;
let probability = prediction.probability; let probability = prediction.probability;
let options = [ let options = [
{ {
@ -40,12 +41,12 @@ async function processPredictions(predictions) {
let result = { let result = {
title: prediction.title, title: prediction.title,
url: `https://example.com`, url: `https://example.com`,
platform: "Example", platform: platformName,
description: prediction.description, description: prediction.description,
options: options, options: options,
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
qualityindicators: { qualityindicators: {
stars: calculateStars("Example", { stars: calculateStars(platformName, {
/* some: somex, factors: factors */ /* some: somex, factors: factors */
}), }),
other: prediction.otherx, other: prediction.otherx,
@ -60,7 +61,7 @@ async function processPredictions(predictions) {
/* Body */ /* Body */
export const example: Platform = { export const example: Platform = {
name: "example", name: platformName,
label: "Example platform", label: "Example platform",
color: "#ff0000", color: "#ff0000",
async fetcher() { async fetcher() {

View File

@ -84,7 +84,7 @@ async function processPredictions(data) {
/* if(Math.floor(Math.random() * 10) % 20 ==0){ /* if(Math.floor(Math.random() * 10) % 20 ==0){
console.log(JSON.stringify(prediction, null, 4)) console.log(JSON.stringify(prediction, null, 4))
} */ } */
let id = `betfair-${prediction.marketId}`; let id = `${platformName}-${prediction.marketId}`;
let normalizationFactor = prediction.options let normalizationFactor = prediction.options
.filter((option) => option.status == "ACTIVE" && option.totalMatched > 0) .filter((option) => option.status == "ACTIVE" && option.totalMatched > 0)
.map((option) => option.lastPriceTraded) .map((option) => option.lastPriceTraded)

View File

@ -79,6 +79,7 @@ export const givewellopenphil: Platform = {
const data = JSON.parse(rawdata); const data = JSON.parse(rawdata);
const dataWithDate = data.map((datum: any) => ({ const dataWithDate = data.map((datum: any) => ({
...datum, ...datum,
platform: platformName,
timestamp: "2021-02-23", timestamp: "2021-02-23",
})); }));
return dataWithDate; return dataWithDate;

View File

@ -3,6 +3,7 @@ import axios from "axios";
import { Tabletojson } from "tabletojson"; import { Tabletojson } from "tabletojson";
import { applyIfSecretExists } from "../utils/getSecrets"; import { applyIfSecretExists } from "../utils/getSecrets";
import { measureTime } from "../utils/measureTime";
import { calculateStars } from "../utils/stars"; import { calculateStars } from "../utils/stars";
import toMarkdown from "../utils/toMarkdown"; import toMarkdown from "../utils/toMarkdown";
import { Forecast, Platform } from "./"; import { Forecast, Platform } from "./";
@ -180,11 +181,12 @@ function sleep(ms) {
/* Body */ /* Body */
async function infer_inner(cookie) { async function infer_inner(cookie: string) {
let i = 1; let i = 1;
let response = await fetchPage(i, cookie); let response = await fetchPage(i, cookie);
let results: Forecast[] = []; let results: Forecast[] = [];
let init = Date.now();
await measureTime(async () => {
// console.log("Downloading... This might take a couple of minutes. Results will be shown.") // console.log("Downloading... This might take a couple of minutes. Results will be shown.")
while (!isEnd(response) && isSignedIn(response)) { while (!isEnd(response) && isSignedIn(response)) {
let htmlLines = response.split("\n"); let htmlLines = response.split("\n");
@ -195,18 +197,11 @@ async function infer_inner(cookie) {
// 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("questionHrefs: "); console.log("questionHrefs: ");
console.log(questionHrefs); console.log(questionHrefs);
} }
//console.log("")
//console.log("")
//console.log(h4elements)
for (let questionHref of questionHrefs) { for (let questionHref of questionHrefs) {
//console.log(h4element)
let elementSplit = questionHref.split('"><span>'); let elementSplit = questionHref.split('"><span>');
let url = elementSplit[0].split('<a href="')[1]; let url = elementSplit[0].split('<a href="')[1];
let title = elementSplit[1] let title = elementSplit[1]
@ -220,11 +215,11 @@ async function infer_inner(cookie) {
let questionNumRegex = new RegExp("questions/([0-9]+)"); let questionNumRegex = new RegExp("questions/([0-9]+)");
let questionNum = url.match(questionNumRegex)[1]; //.split("questions/")[1].split("-")[0]; let questionNum = url.match(questionNumRegex)[1]; //.split("questions/")[1].split("-")[0];
let id = `${platformName}-${questionNum}`; let id = `${platformName}-${questionNum}`;
let question = { let question: Forecast = {
id: id, id: id,
title: title, title: title,
url: url, url: url,
platform: "Infer", platform: platformName,
...moreinfo, ...moreinfo,
}; };
if ( if (
@ -248,7 +243,6 @@ async function infer_inner(cookie) {
} }
i++; i++;
//i=Number(i)+1
console.log( console.log(
"Sleeping for ~5secs so as to not be as noticeable to the infer servers" "Sleeping for ~5secs so as to not be as noticeable to the infer servers"
@ -264,12 +258,7 @@ async function infer_inner(cookie) {
); );
} }
} }
});
let end = Date.now();
let difference = end - init;
console.log(
`Took ${difference / 1000} seconds, or ${difference / (1000 * 60)} minutes.`
);
if (results.length === 0) { if (results.length === 0) {
console.log("Not updating results, as process was not signed in"); console.log("Not updating results, as process was not signed in");

View File

@ -2,7 +2,7 @@
import axios from "axios"; import axios from "axios";
import { calculateStars } from "../utils/stars"; import { calculateStars } from "../utils/stars";
import { Platform } from "./"; import { Forecast, Platform } from "./";
/* Definitions */ /* Definitions */
const platformName = "manifold"; const platformName = "manifold";
@ -23,7 +23,7 @@ async function fetchData() {
return response; return response;
} }
function showStatistics(results) { function showStatistics(results: Forecast[]) {
console.log(`Num unresolved markets: ${results.length}`); console.log(`Num unresolved markets: ${results.length}`);
let sum = (arr) => arr.reduce((tally, a) => tally + a, 0); let sum = (arr) => arr.reduce((tally, a) => tally + a, 0);
let num2StarsOrMore = results.filter( let num2StarsOrMore = results.filter(
@ -44,8 +44,8 @@ function showStatistics(results) {
} }
async function processPredictions(predictions) { async function processPredictions(predictions) {
let results = await predictions.map((prediction) => { let results: Forecast[] = await predictions.map((prediction) => {
let id = `manifold-${prediction.id}`; // oops, doesn't match platform name let id = `${platformName}-${prediction.id}`; // oops, doesn't match platform name
let probability = prediction.probability; let probability = prediction.probability;
let options = [ let options = [
{ {
@ -59,11 +59,11 @@ async function processPredictions(predictions) {
type: "PROBABILITY", type: "PROBABILITY",
}, },
]; ];
let result = { const result: Forecast = {
id: id, id: id,
title: prediction.question, title: prediction.question,
url: prediction.url, url: prediction.url,
platform: "Manifold Markets", platform: platformName,
description: prediction.description, description: prediction.description,
options: options, options: options,
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
@ -84,9 +84,11 @@ async function processPredictions(predictions) {
}; };
return result; return result;
}); });
let unresolvedResults = results.filter((result) => !result.extra.isResolved);
// console.log(unresolvedResults); const unresolvedResults = results.filter(
return unresolvedResults; //resultsProcessed (result) => !result.extra.isResolved
);
return unresolvedResults;
} }
export const manifold: Platform = { export const manifold: Platform = {

View File

@ -50,7 +50,7 @@ async function fetchMetaculusQuestions(next) {
return data; return data;
} }
function sleep(ms) { function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms)); return new Promise((resolve) => setTimeout(resolve, ms));
} }

View File

@ -1,7 +1,7 @@
import axios from "axios"; import axios from "axios";
import { calculateStars } from "../utils/stars"; import { calculateStars } from "../utils/stars";
import { Platform } from "./"; import { Forecast, Platform } from "./";
/* Definitions */ /* Definitions */
const platformName = "smarkets"; const platformName = "smarkets";
@ -159,7 +159,7 @@ export const smarkets: Platform = {
name = name+ (contractName=="Yes"?'':` (${contracts["contracts"][0].name})`) name = name+ (contractName=="Yes"?'':` (${contracts["contracts"][0].name})`)
} }
*/ */
let result = { let result: Forecast = {
id: id, id: id,
title: name, title: name,
url: "https://smarkets.com/event/" + market.event_id + market.slug, url: "https://smarkets.com/event/" + market.event_id + market.slug,

View File

@ -1,10 +1,10 @@
export async function applyIfSecretExists<T>( export async function applyIfSecretExists<T>(
cookie, cookie: string,
fun: (...args: any[]) => T fun: (cookie: string) => T
) { ) {
if (cookie) { if (cookie) {
return await fun(cookie); return await fun(cookie);
} else if (!cookie) { } else {
console.log( console.log(
`Cannot proceed with ${fun.name} because cookie does not exist` `Cannot proceed with ${fun.name} because cookie does not exist`
); );

View File

@ -93,7 +93,7 @@ export default function Home({
let isGraubardEasterEgg = (name) => (name == "Clay Graubard" ? true : false); let isGraubardEasterEgg = (name) => (name == "Clay Graubard" ? true : false);
return ( return (
<Layout key="index" page={"dashboard"}> <Layout page="dashboard">
{/* Display forecasts */} {/* Display forecasts */}
<div className="mt-7 mb-7"> <div className="mt-7 mb-7">
<h1 <h1

View File

@ -2,7 +2,7 @@ import axios from "axios";
export async function getDashboardForecastsByDashboardId({ dashboardId }) { export async function getDashboardForecastsByDashboardId({ dashboardId }) {
console.log("getDashboardForecastsByDashboardId: "); console.log("getDashboardForecastsByDashboardId: ");
let dashboardForecastCompatibleWithFuse = []; let dashboardContents = [];
let dashboardItem = null; let dashboardItem = null;
try { try {
let { data } = await axios({ let { data } = await axios({
@ -13,22 +13,13 @@ export async function getDashboardForecastsByDashboardId({ dashboardId }) {
}, },
}); });
console.log(data); console.log(data);
let dashboardContents = data.dashboardContents; dashboardContents = data.dashboardContents;
dashboardItem = data.dashboardItem; dashboardItem = data.dashboardItem;
// let { dashboardContents, dashboardItem } = data
if (!!dashboardContents && !!dashboardContents.map) {
dashboardForecastCompatibleWithFuse = dashboardContents.map((result) => ({
item: result,
score: 0,
}));
} else {
console.log("Error in getDashboardForecastsByDashboardId");
}
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} finally { } finally {
return { return {
dashboardForecasts: dashboardForecastCompatibleWithFuse, dashboardForecasts: dashboardContents,
dashboardItem, dashboardItem,
}; };
} }