fix: recalculate manifold markets stars
This commit is contained in:
		
							parent
							
								
									a7c09e14ae
								
							
						
					
					
						commit
						ba24ef7722
					
				
							
								
								
									
										103596
									
								
								data/frontpage.json
									
									
									
									
									
								
							
							
						
						
									
										103596
									
								
								data/frontpage.json
									
									
									
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										170887
									
								
								data/metaforecasts.json
									
									
									
									
									
								
							
							
						
						
									
										170887
									
								
								data/metaforecasts.json
									
									
									
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							|  | @ -1,85 +1,92 @@ | ||||||
| /* Imports */ | /* Imports */ | ||||||
| import axios from "axios" | import axios from "axios"; | ||||||
| import fs from "fs" | import fs from "fs"; | ||||||
| import { Tabletojson } from "tabletojson" | import { Tabletojson } from "tabletojson"; | ||||||
| import toMarkdown from "../utils/toMarkdown.js" | import toMarkdown from "../utils/toMarkdown.js"; | ||||||
| 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 endpoints = ["https://goodjudgment.io/superforecasts/", "https://goodjudgment.io/economist/"] | let endpoints = [ | ||||||
| String.prototype.replaceAll = function replaceAll(search, replace) { return this.split(search).join(replace); } |   "https://goodjudgment.io/superforecasts/", | ||||||
|  |   "https://goodjudgment.io/economist/", | ||||||
|  | ]; | ||||||
|  | String.prototype.replaceAll = function replaceAll(search, replace) { | ||||||
|  |   return this.split(search).join(replace); | ||||||
|  | }; | ||||||
| 
 | 
 | ||||||
| /* Support functions */ | /* Support functions */ | ||||||
| 
 | 
 | ||||||
| /* Body */ | /* Body */ | ||||||
| export async function goodjudgment() { | export async function goodjudgment() { | ||||||
|   let results = [] |   let results = []; | ||||||
|   for (let endpoint of endpoints) { |   for (let endpoint of endpoints) { | ||||||
|     let content = await axios.get(endpoint) |     let content = await axios.get(endpoint).then((query) => query.data); | ||||||
|       .then(query => query.data) |     let jsonTable = Tabletojson.convert(content, { stripHtmlFromCells: false }); | ||||||
|     let jsonTable = Tabletojson.convert(content, { stripHtmlFromCells: false }) |     jsonTable.shift(); // deletes first element
 | ||||||
|     jsonTable.shift() // deletes first element
 |     jsonTable.pop(); // deletes last element
 | ||||||
|     jsonTable.pop() // deletes last element
 |     if (endpoint == endpoints[1]) jsonTable.pop(); // pop again\
 | ||||||
|     if (endpoint == endpoints[1]) jsonTable.pop() // pop again\
 |  | ||||||
|     // console.log(jsonTable)
 |     // console.log(jsonTable)
 | ||||||
|     for (let table of jsonTable) { |     for (let table of jsonTable) { | ||||||
|       // console.log(table)
 |       // console.log(table)
 | ||||||
|       let title = table[0]['0'] |       let title = table[0]["0"].split("\t\t\t").splice(3)[0]; | ||||||
|         .split("\t\t\t") |  | ||||||
|         .splice(3)[0] |  | ||||||
|       let description = table |       let description = table | ||||||
|         .filter(row => row['0'].includes("BACKGROUND:")) |         .filter((row) => row["0"].includes("BACKGROUND:")) | ||||||
|         .map(row => row['0']) |         .map((row) => row["0"]) | ||||||
|         .map(text => text |         .map((text) => | ||||||
|           .split("BACKGROUND:")[1] |           text | ||||||
|           .split("Examples of Superforecaster")[0] |             .split("BACKGROUND:")[1] | ||||||
|           .split("AT A GLANCE")[0] |             .split("Examples of Superforecaster")[0] | ||||||
|           .replaceAll("\n\n", "\n") |             .split("AT A GLANCE")[0] | ||||||
|           .split("\n") |             .replaceAll("\n\n", "\n") | ||||||
|           .slice(3) |             .split("\n") | ||||||
|           .join(" ") |             .slice(3) | ||||||
|           .replaceAll("      ", "") |             .join(" ") | ||||||
|           .replaceAll("<br> ", "") |             .replaceAll("      ", "") | ||||||
|         )[0] |             .replaceAll("<br> ", "") | ||||||
|  |         )[0]; | ||||||
|       let options = table |       let options = table | ||||||
|         .filter(row => '4' in row) |         .filter((row) => "4" in row) | ||||||
|         .map(row => ({ |         .map((row) => ({ | ||||||
|           name: row['2'] |           name: row["2"] | ||||||
|             .split("<span class=\"qTitle\">")[1] |             .split('<span class="qTitle">')[1] | ||||||
|             .replace("</span>", ""), |             .replace("</span>", ""), | ||||||
|           probability: Number(row['3'].split("%")[0]) / 100, |           probability: Number(row["3"].split("%")[0]) / 100, | ||||||
|           type: "PROBABILITY" |           type: "PROBABILITY", | ||||||
|         })) |         })); | ||||||
|       let analysis = table.filter(row => row[0]? row[0].toLowerCase().includes("commentary") : false) |       let analysis = table.filter((row) => | ||||||
|         // "Examples of Superforecaster Commentary" / Analysis
 |         row[0] ? row[0].toLowerCase().includes("commentary") : false | ||||||
|  |       ); | ||||||
|  |       // "Examples of Superforecaster Commentary" / Analysis
 | ||||||
|       // The following is necessary twite, because we want to check if there is an empty list, and then get the first element of the first element of the list.
 |       // The following is necessary twite, 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] : ""; | ||||||
|       analysis = analysis ? analysis[0] : ""  |       analysis = analysis ? analysis[0] : ""; | ||||||
|       // console.log(analysis)
 |       // console.log(analysis)
 | ||||||
|       let standardObj = ({ |       let standardObj = { | ||||||
|         "title": title, |         title: title, | ||||||
|         "url": endpoint, |         url: endpoint, | ||||||
|         "platform": "Good Judgment", |         platform: "Good Judgment", | ||||||
|         "description": description, |         description: description, | ||||||
|         "options": options, |         options: options, | ||||||
|         "timestamp": new Date().toISOString(), |         timestamp: new Date().toISOString(), | ||||||
|         "qualityindicators": { |         qualityindicators: { | ||||||
|           "stars": calculateStars("Good Judgment", ({})), |           stars: calculateStars("Good Judgment", {}), | ||||||
|         }, |         }, | ||||||
|         "extra": { |         extra: { | ||||||
|           "superforecastercommentary": analysis || "" |           superforecastercommentary: analysis || "", | ||||||
|         } |         }, | ||||||
|       }) |       }; | ||||||
|       results.push(standardObj) |       if (standardObj.title != undefined) { | ||||||
|  |         results.push(standardObj); | ||||||
|  |       } | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   // console.log(results.slice(0,10))
 |   // console.log(results.slice(0,10))
 | ||||||
|   let string = JSON.stringify(results, null, 2) |   let string = JSON.stringify(results, null, 2); | ||||||
|   // fs.writeFileSync('./data/goodjudgment-questions.json', string);
 |   // fs.writeFileSync('./data/goodjudgment-questions.json', string);
 | ||||||
|   // fs.writeFileSync('./goodjudgment-questions-test.json', string);
 |   // fs.writeFileSync('./goodjudgment-questions-test.json', string);
 | ||||||
|   console.log(results) |   console.log(results); | ||||||
|   await upsert(results, "goodjudgment-questions") |   await upsert(results, "goodjudgment-questions"); | ||||||
|   console.log("Done") |   console.log("Done"); | ||||||
| } | } | ||||||
| // goodjudgment()
 | // goodjudgment()
 | ||||||
|  |  | ||||||
|  | @ -1,80 +1,100 @@ | ||||||
| /* 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 endpoint = 'https://us-central1-mantic-markets.cloudfunctions.net/markets' | let endpoint = "https://us-central1-mantic-markets.cloudfunctions.net/markets"; | ||||||
| 
 | 
 | ||||||
| /* Support functions */ | /* Support functions */ | ||||||
| 
 | 
 | ||||||
| async function fetchData() { | async function fetchData() { | ||||||
|     let response = await axios({ |   let response = await axios({ | ||||||
|         url: endpoint, |     url: endpoint, | ||||||
|         method: 'GET', |     method: "GET", | ||||||
|         headers: ({ |     headers: { | ||||||
|             'Content-Type': 'text/html', |       "Content-Type": "text/html", | ||||||
|         }), |     }, | ||||||
|     }) |   }).then((response) => response.data); | ||||||
|         .then(response => response.data) |   // console.log(response)
 | ||||||
|     // console.log(response)
 |   return response; | ||||||
|     return response | } | ||||||
|  | 
 | ||||||
|  | function showStatistics(results) { | ||||||
|  |   console.log(`Num unresolved markets: ${results.length}`); | ||||||
|  |   let sum = (arr) => arr.reduce((tally, a) => tally + a, 0); | ||||||
|  |   let num2StarsOrMore = results.filter( | ||||||
|  |     (result) => result.qualityindicators.stars >= 2 | ||||||
|  |   ); | ||||||
|  |   console.log( | ||||||
|  |     `Manifold has ${num2StarsOrMore.length} markets with 2 stars or more` | ||||||
|  |   ); | ||||||
|  |   console.log( | ||||||
|  |     `Mean volume: ${ | ||||||
|  |       sum(results.map((result) => result.qualityindicators.volume7Days)) / | ||||||
|  |       results.length | ||||||
|  |     }; mean pool: ${ | ||||||
|  |       sum(results.map((result) => result.qualityindicators.pool)) / | ||||||
|  |       results.length | ||||||
|  |     }` | ||||||
|  |   ); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function processPredictions(predictions) { | async function processPredictions(predictions) { | ||||||
|     let results = await predictions.map(prediction => { |   let results = await predictions.map((prediction) => { | ||||||
|         let probability = prediction.probability |     let probability = prediction.probability; | ||||||
|         let options = [ |     let options = [ | ||||||
|             { |       { | ||||||
|                 "name": "Yes", |         name: "Yes", | ||||||
|                 "probability": probability, |         probability: probability, | ||||||
|                 "type": "PROBABILITY" |         type: "PROBABILITY", | ||||||
|             }, |       }, | ||||||
|             { |       { | ||||||
|                 "name": "No", |         name: "No", | ||||||
|                 "probability": 1 - probability, |         probability: 1 - probability, | ||||||
|                 "type": "PROBABILITY" |         type: "PROBABILITY", | ||||||
|             } |       }, | ||||||
|         ] |     ]; | ||||||
|         let result = ({ |     let result = { | ||||||
|             "title": prediction.question, |       title: prediction.question, | ||||||
|             "url": prediction.url, |       url: prediction.url, | ||||||
|             "platform": "Manifold Markets", |       platform: "Manifold Markets", | ||||||
|             "description": prediction.description, |       description: prediction.description, | ||||||
|             "options": options, |       options: options, | ||||||
|             "timestamp": new Date().toISOString(), |       timestamp: new Date().toISOString(), | ||||||
|             "qualityindicators": { |       qualityindicators: { | ||||||
|                 "stars": calculateStars("Manifold Markets", ({ |         stars: calculateStars("Manifold Markets", { | ||||||
|                     volume7days: prediction.volume7days, |           volume7Days: prediction.volume7Days, | ||||||
|                     volume24Hours: prediction.volume24Hours, |           volume24Hours: prediction.volume24Hours, | ||||||
|                     pool: prediction.pool  |           pool: prediction.pool, | ||||||
|                 })), |         }), | ||||||
|                 "createdTime": prediction.createdTime, |         createdTime: prediction.createdTime, | ||||||
|                 "volume7Days": prediction.volume7Days, |         volume7Days: prediction.volume7Days, | ||||||
|                 "volume24Hours": prediction.volume24Hours, |         volume24Hours: prediction.volume24Hours, | ||||||
|                 "pool": prediction.pool, // normally liquidity, but I don't actually want to show it.
 |         pool: prediction.pool, // normally liquidity, but I don't actually want to show it.
 | ||||||
|             }, |       }, | ||||||
|             "extra": { |       extra: { | ||||||
|                 "isResolved": prediction.isResolved |         isResolved: prediction.isResolved, | ||||||
|             } |       }, | ||||||
|         }) |     }; | ||||||
|         return result |     return result; | ||||||
|     }) |   }); | ||||||
|     let unresolvedResults = results.filter(result => !result.isResolved) |   let unresolvedResults = results.filter((result) => !result.extra.isResolved); | ||||||
|     console.log(unresolvedResults) |   // console.log(unresolvedResults);
 | ||||||
|     return unresolvedResults //resultsProcessed
 |   return unresolvedResults; //resultsProcessed
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* Body */ | /* Body */ | ||||||
| 
 | 
 | ||||||
| export async function manifoldmarkets() { | export async function manifoldmarkets() { | ||||||
|     let data = await fetchData() |   let data = await fetchData(); | ||||||
|     let results = await processPredictions(data) // somehow needed
 |   let results = await processPredictions(data); // somehow needed
 | ||||||
|     // console.log(results)
 |   showStatistics(results); | ||||||
|     // let string = JSON.stringify(results, null, 2)
 |   // console.log(results)
 | ||||||
|     // fs.writeFileSync('polyprediction-questions.json', string);
 |   // let string = JSON.stringify(results, null, 2)
 | ||||||
|     await upsert(results, "manifoldmarkets-questions") |   // fs.writeFileSync('polyprediction-questions.json', string);
 | ||||||
|     console.log("Done") |   await upsert(results, "manifoldmarkets-questions"); | ||||||
|  |   console.log("Done"); | ||||||
| } | } | ||||||
| // manifoldmarkets()
 | // manifoldmarkets()
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user