Skip to content

Commit c734f33

Browse files
committed
add support for None in forecast values
support null values on frontend fix flake8 complaints
1 parent 926c1a9 commit c734f33

File tree

23 files changed

+300
-128
lines changed

23 files changed

+300
-128
lines changed

front_end/src/app/(main)/aggregation-explorer/components/continuous_aggregations_chart.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ const ContinuousAggregationChart: FC<Props> = ({
8484
if (historyItem) {
8585
charts.push({
8686
pmf: cdfToPmf(historyItem.forecast_values),
87-
cdf: historyItem.forecast_values,
87+
cdf: historyItem.forecast_values.map((v) => {
88+
if (v === null) {
89+
throw new Error("Forecast values contain null values");
90+
}
91+
return v;
92+
}),
8893
type: "community",
8994
});
9095
}

front_end/src/app/(main)/questions/[id]/components/question_view/consumer_question_view/prediction/single_question_prediction/binary_question_prediction.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const QuestionInfo: React.FC<{
8181

8282
const getYesProbability = (
8383
q: QuestionWithNumericForecasts
84-
): number | undefined => {
84+
): number | null | undefined => {
8585
if (q.type !== QuestionType.Binary) return undefined;
8686
const values =
8787
q.aggregations?.[q.default_aggregation_method]?.latest?.forecast_values;

front_end/src/components/charts/continuous_area_chart.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,12 @@ export function getContinuousAreaChartData({
11271127
if (latest && isForecastActive(latest)) {
11281128
chartData.push({
11291129
pmf: cdfToPmf(latest.forecast_values),
1130-
cdf: latest.forecast_values,
1130+
cdf: latest.forecast_values.map((v) => {
1131+
if (v === null) {
1132+
throw new Error("Forecast values contain null values");
1133+
}
1134+
return v;
1135+
}),
11311136
type: (isClosed ? "community_closed" : "community") as ContinuousAreaType,
11321137
});
11331138
}
@@ -1141,7 +1146,12 @@ export function getContinuousAreaChartData({
11411146
} else if (!!userForecast && isForecastActive(userForecast)) {
11421147
chartData.push({
11431148
pmf: cdfToPmf(userForecast.forecast_values),
1144-
cdf: userForecast.forecast_values,
1149+
cdf: userForecast.forecast_values.map((v) => {
1150+
if (v === null) {
1151+
throw new Error("Forecast values contain null values");
1152+
}
1153+
return v;
1154+
}),
11451155
type: "user" as ContinuousAreaType,
11461156
});
11471157
}

front_end/src/components/charts/histogram.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import ChartContainer from "./primitives/chart_container";
2121

2222
type HistogramProps = {
2323
histogramData: { x: number; y: number }[];
24-
median: number | undefined;
25-
mean: number | undefined;
24+
median: number | null | undefined;
25+
mean: number | null | undefined;
2626
color: "blue" | "gray";
2727
width?: number;
2828
};

front_end/src/components/charts/minified_continuous_area_chart.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,12 @@ export function getContinuousAreaChartData({
607607
if (latest && isForecastActive(latest)) {
608608
chartData.push({
609609
pmf: cdfToPmf(latest.forecast_values),
610-
cdf: latest.forecast_values,
610+
cdf: latest.forecast_values.map((v) => {
611+
if (v === null) {
612+
throw new Error("Forecast values contain null values");
613+
}
614+
return v;
615+
}),
611616
type: (isClosed ? "community_closed" : "community") as ContinuousAreaType,
612617
});
613618
}

front_end/src/components/conditional_tile/conditional_chart.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ const ConditionalChart: FC<Props> = ({
146146
? [
147147
{
148148
pmf: cdfToPmf(aggregateLatest.forecast_values),
149-
cdf: aggregateLatest.forecast_values,
149+
cdf: aggregateLatest.forecast_values.map((v) => {
150+
if (v === null) {
151+
throw new Error("Forecast values contain null values");
152+
}
153+
return v;
154+
}),
150155
type: "community" as ContinuousAreaType,
151156
},
152157
]

front_end/src/components/forecast_maker/continuous_input/continuous_prediction_chart.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ const ContinuousPredictionChart: FC<Props> = ({
133133
if (showCP && latestAggLatest && isForecastActive(latestAggLatest)) {
134134
charts.push({
135135
pmf: cdfToPmf(latestAggLatest.forecast_values),
136-
cdf: latestAggLatest.forecast_values,
136+
cdf: latestAggLatest.forecast_values.map((v) => {
137+
if (v === null) {
138+
throw new Error("Forecast values contain null values");
139+
}
140+
return v;
141+
}),
137142
type:
138143
question.status === QuestionStatus.CLOSED
139144
? "community_closed"

front_end/src/components/forecast_maker/forecast_maker_conditional/forecast_maker_conditional_continuous.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,15 +676,25 @@ const ForecastMakerConditionalContinuous: FC<Props> = ({
676676
).cdf;
677677
const userPreviousCdf: number[] | undefined =
678678
overlayPreviousForecast && previousForecast
679-
? previousForecast.forecast_values
679+
? previousForecast.forecast_values.map((v) => {
680+
if (v === null) {
681+
throw new Error("Forecast values contain null values");
682+
}
683+
return v;
684+
})
680685
: undefined;
681686
const aggregateLatest =
682687
activeOptionData?.question.aggregations[
683688
activeOptionData.question.default_aggregation_method
684689
].latest;
685690
const communityCdf: number[] | undefined =
686691
aggregateLatest && isForecastActive(aggregateLatest)
687-
? aggregateLatest.forecast_values
692+
? aggregateLatest.forecast_values.map((v) => {
693+
if (v === null) {
694+
throw new Error("Forecast values contain null values");
695+
}
696+
return v;
697+
})
688698
: undefined;
689699

690700
const predictButtonIsDisabled =

front_end/src/components/forecast_maker/forecast_maker_group/continuous_input_wrapper.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,12 @@ const ContinuousInputWrapper: FC<PropsWithChildren<Props>> = ({
194194
[option]
195195
);
196196

197-
const rawPreviousCdf = previousForecast?.forecast_values;
197+
const rawPreviousCdf = previousForecast?.forecast_values.map((v) => {
198+
if (v === null) {
199+
throw new Error("Forecast values contain null values");
200+
}
201+
return v;
202+
});
198203
const showWithdrawnRow = option.wasWithdrawn && !option.isDirty;
199204
const showPreviousRowByCheckbox =
200205
!showWithdrawnRow && overlayPreviousForecast;
@@ -238,9 +243,14 @@ const ContinuousInputWrapper: FC<PropsWithChildren<Props>> = ({
238243

239244
const withdraw = () => onWithdraw();
240245

241-
const communityCdf: number[] | undefined =
242-
option.question.aggregations[option.question.default_aggregation_method]
243-
.latest?.forecast_values;
246+
const communityCdf: number[] | undefined = option.question.aggregations[
247+
option.question.default_aggregation_method
248+
].latest?.forecast_values.map((v) => {
249+
if (v === null) {
250+
throw new Error("Forecast values contain null values");
251+
}
252+
return v;
253+
});
244254

245255
const questionDuration =
246256
new Date(option.question.scheduled_close_time).getTime() -

front_end/src/components/forecast_maker/forecast_maker_group/forecast_maker_group_continuous.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,12 @@ const ForecastMakerGroupContinuous: FC<Props> = ({
598598
questionId: id,
599599
forecastEndTime: forecastExpirationToDate(forecastExpiration),
600600
forecastData: {
601-
continuousCdf: latest.forecast_values,
601+
continuousCdf: latest.forecast_values.map((v) => {
602+
if (v === null) {
603+
throw new Error("Forecast values contain null values");
604+
}
605+
return v;
606+
}),
602607
probabilityYesPerCategory: null,
603608
probabilityYes: null,
604609
},

0 commit comments

Comments
 (0)