fix: handle empty metaculus prediction

This commit is contained in:
Vyacheslav Matyukhin 2022-06-03 11:59:29 +03:00
parent 2345b81350
commit 646397d8d4
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C
2 changed files with 17 additions and 14 deletions

View File

@ -49,7 +49,8 @@ const predictableProps = {
community_prediction: { community_prediction: {
properties: { properties: {
full: { full: {
properties: { // q1/q2/q3 can be missing, e.g. https://www.metaculus.com/api2/questions/1633/
optionalProperties: {
q1: { q1: {
type: "float64", type: "float64",
}, },

View File

@ -38,19 +38,21 @@ async function apiQuestionToFetchedQuestions(
const isBinary = q.possibilities.type === "binary"; const isBinary = q.possibilities.type === "binary";
let options: FetchedQuestion["options"] = []; let options: FetchedQuestion["options"] = [];
if (isBinary) { if (isBinary) {
const probability = Number(q.community_prediction.full.q2); const probability = q.community_prediction.full.q2;
options = [ if (probability !== undefined) {
{ options = [
name: "Yes", {
probability: probability, name: "Yes",
type: "PROBABILITY", probability: probability,
}, type: "PROBABILITY",
{ },
name: "No", {
probability: 1 - probability, name: "No",
type: "PROBABILITY", probability: 1 - probability,
}, type: "PROBABILITY",
]; },
];
}
} }
return { return {
id: `${platformName}-${q.id}`, id: `${platformName}-${q.id}`,