2022-03-29 15:10:28 +00:00
/* Imports */
import axios from "axios" ;
import { Tabletojson } from "tabletojson" ;
2022-05-09 21:15:18 +00:00
import { average } from "../../utils" ;
2022-03-29 15:10:28 +00:00
import { hash } from "../utils/hash" ;
2022-04-23 19:44:38 +00:00
import { FetchedQuestion , Platform } from "./" ;
2022-03-29 15:10:28 +00:00
/* Definitions */
2022-04-01 20:24:35 +00:00
const platformName = "goodjudgment" ;
2022-05-09 19:27:51 +00:00
const endpoint = "https://goodjudgment.io/superforecasts/" ;
2022-03-29 15:10:28 +00:00
/* Body */
export const goodjudgment : Platform = {
2022-04-01 20:24:35 +00:00
name : platformName ,
label : "Good Judgment" ,
color : "#7d4f1b" ,
2022-05-12 13:58:56 +00:00
version : "v1" ,
2022-03-29 15:10:28 +00:00
async fetcher() {
// Proxy fuckery
2022-05-10 21:45:02 +00:00
// let proxy;
2022-03-29 15:10:28 +00:00
/ *
* 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
* /
2022-05-10 21:45:02 +00:00
// proxy = {
// ip: process.env.BACKUP_PROXY_IP,
// port: process.env.BACKUP_PROXY_PORT,
// };
// // }
// let agent = tunnel.httpsOverHttp({
// proxy: {
// host: proxy.ip,
// port: proxy.port,
// },
// });
2022-03-29 15:10:28 +00:00
2022-05-10 21:45:02 +00:00
const content = await axios
2022-03-29 15:10:28 +00:00
. request ( {
url : "https://goodjudgment.io/superforecasts/" ,
method : "get" ,
headers : {
"User-Agent" : "Chrome" ,
} ,
// agent,
// port: 80,
} )
. then ( ( query ) = > query . data ) ;
// Processing
2022-04-23 19:44:38 +00:00
let results : FetchedQuestion [ ] = [ ] ;
2022-03-29 15:10:28 +00:00
let jsonTable = Tabletojson . convert ( content , { stripHtmlFromCells : false } ) ;
jsonTable . shift ( ) ; // deletes first element
jsonTable . pop ( ) ; // deletes last element
2022-05-10 21:45:02 +00:00
2022-03-29 15:10:28 +00:00
for ( let table of jsonTable ) {
let title = table [ 0 ] [ "0" ] . split ( "\t\t\t" ) . splice ( 3 ) [ 0 ] ;
if ( title != undefined ) {
title = title . replaceAll ( "</a>" , "" ) ;
2022-05-10 21:45:02 +00:00
const id = ` ${ platformName } - ${ hash ( title ) } ` ;
const description = table
. filter ( ( row : any ) = > row [ "0" ] . includes ( "BACKGROUND:" ) )
. map ( ( row : any ) = > row [ "0" ] )
. map ( ( text : any ) = >
2022-03-29 15:10:28 +00:00
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 ] ;
2022-05-10 21:45:02 +00:00
const options = table
. filter ( ( row : any ) = > "4" in row )
. map ( ( row : any ) = > ( {
2022-03-29 15:10:28 +00:00
name : row [ "2" ]
. split ( '<span class="qTitle">' ) [ 1 ]
. replace ( "</span>" , "" ) ,
probability : Number ( row [ "3" ] . split ( "%" ) [ 0 ] ) / 100 ,
type : "PROBABILITY" ,
} ) ) ;
2022-05-10 21:45:02 +00:00
let analysis = table . filter ( ( row : any ) = >
2022-03-29 15:10:28 +00:00
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)
2022-04-23 19:44:38 +00:00
let standardObj : FetchedQuestion = {
id ,
title ,
2022-03-29 15:10:28 +00:00
url : endpoint ,
2022-04-23 19:44:38 +00:00
description ,
options ,
2022-05-09 21:15:18 +00:00
qualityindicators : { } ,
2022-03-29 15:10:28 +00:00
extra : {
superforecastercommentary : analysis || "" ,
} ,
} ;
results . push ( standardObj ) ;
}
}
console . log (
"Failing is not unexpected; see utils/pullSuperforecastsManually.sh/js"
) ;
return results ;
} ,
2022-05-09 21:15:18 +00:00
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 ;
} ,
2022-03-29 15:10:28 +00:00
} ;