Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions docs/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,40 @@ components:
items:
type: string
description: "List of options for multiple_choice questions"
example:
- "Democratic"
- "Republican"
- "Libertarian"
- "Green"
- "Other"
all_options_ever:
type: array
items:
type: string
description: "List of all options ever for multiple_choice questions"
example:
- "Democratic"
- "Republican"
- "Libertarian"
- "Green"
- "Blue"
- "Other"
options_history:
type: array
description: "List of [iso format time, options] pairs for multiple_choice questions"
items:
type: array
items:
oneOf:
- type: string
description: "ISO 8601 timestamp when the options became active"
- type: array
items:
type: string
description: "Options list active from this timestamp onward"
example:
- ["0001-01-01T00:00:00", ["a", "b", "c", "other"]]
- ["2026-10-22T16:00:00", ["a", "b", "c", "d", "other"]]
status:
type: string
enum: [ upcoming, open, closed, resolved ]
Expand Down Expand Up @@ -1306,6 +1340,7 @@ paths:
actual_close_time: "2020-11-01T00:00:00Z"
type: "numeric"
options: null
options_history: null
status: "resolved"
resolution: "77289125.94957079"
resolution_criteria: "Resolution Criteria Copy"
Expand Down Expand Up @@ -1479,6 +1514,7 @@ paths:
actual_close_time: "2015-12-15T03:34:00Z"
type: "binary"
options: null
options_history: null
status: "resolved"
possibilities:
type: "binary"
Expand Down Expand Up @@ -1548,6 +1584,16 @@ paths:
- "Libertarian"
- "Green"
- "Other"
all_options_ever:
- "Democratic"
- "Republican"
- "Libertarian"
- "Green"
- "Blue"
- "Other"
options_history:
- ["0001-01-01T00:00:00", ["Democratic", "Republican", "Libertarian", "Other"]]
- ["2026-10-22T16:00:00", ["Democratic", "Republican", "Libertarian", "Green", "Other"]]
status: "open"
possibilities: { }
resolution: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ const ContinuousAggregationChart: FC<Props> = ({
if (historyItem) {
charts.push({
pmf: cdfToPmf(historyItem.forecast_values),
cdf: historyItem.forecast_values,
cdf: historyItem.forecast_values.map((v) => {
if (v === null) {
throw new Error("Forecast values contain null values");
}
return v;
}),
type: "community",
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const QuestionInfo: React.FC<{

const getYesProbability = (
q: QuestionWithNumericForecasts
): number | undefined => {
): number | null | undefined => {
if (q.type !== QuestionType.Binary) return undefined;
const values =
q.aggregations?.[q.default_aggregation_method]?.latest?.forecast_values;
Expand Down
14 changes: 12 additions & 2 deletions front_end/src/components/charts/continuous_area_chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,12 @@ export function getContinuousAreaChartData({
if (latest && isForecastActive(latest)) {
chartData.push({
pmf: cdfToPmf(latest.forecast_values),
cdf: latest.forecast_values,
cdf: latest.forecast_values.map((v) => {
if (v === null) {
throw new Error("Forecast values contain null values");
}
return v;
}),
type: (isClosed ? "community_closed" : "community") as ContinuousAreaType,
});
}
Expand All @@ -1141,7 +1146,12 @@ export function getContinuousAreaChartData({
} else if (!!userForecast && isForecastActive(userForecast)) {
chartData.push({
pmf: cdfToPmf(userForecast.forecast_values),
cdf: userForecast.forecast_values,
cdf: userForecast.forecast_values.map((v) => {
if (v === null) {
throw new Error("Forecast values contain null values");
}
return v;
}),
type: "user" as ContinuousAreaType,
});
}
Expand Down
4 changes: 2 additions & 2 deletions front_end/src/components/charts/histogram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import ChartContainer from "./primitives/chart_container";

type HistogramProps = {
histogramData: { x: number; y: number }[];
median: number | undefined;
mean: number | undefined;
median: number | null | undefined;
mean: number | null | undefined;
color: "blue" | "gray";
width?: number;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,12 @@ export function getContinuousAreaChartData({
if (latest && isForecastActive(latest)) {
chartData.push({
pmf: cdfToPmf(latest.forecast_values),
cdf: latest.forecast_values,
cdf: latest.forecast_values.map((v) => {
if (v === null) {
throw new Error("Forecast values contain null values");
}
return v;
}),
type: (isClosed ? "community_closed" : "community") as ContinuousAreaType,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ const ConditionalChart: FC<Props> = ({
? [
{
pmf: cdfToPmf(aggregateLatest.forecast_values),
cdf: aggregateLatest.forecast_values,
cdf: aggregateLatest.forecast_values.map((v) => {
if (v === null) {
throw new Error("Forecast values contain null values");
}
return v;
}),
type: "community" as ContinuousAreaType,
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ const ContinuousPredictionChart: FC<Props> = ({
if (showCP && latestAggLatest && isForecastActive(latestAggLatest)) {
charts.push({
pmf: cdfToPmf(latestAggLatest.forecast_values),
cdf: latestAggLatest.forecast_values,
cdf: latestAggLatest.forecast_values.map((v) => {
if (v === null) {
throw new Error("Forecast values contain null values");
}
return v;
}),
type:
question.status === QuestionStatus.CLOSED
? "community_closed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,15 +676,25 @@ const ForecastMakerConditionalContinuous: FC<Props> = ({
).cdf;
const userPreviousCdf: number[] | undefined =
overlayPreviousForecast && previousForecast
? previousForecast.forecast_values
? previousForecast.forecast_values.map((v) => {
if (v === null) {
throw new Error("Forecast values contain null values");
}
return v;
})
: undefined;
const aggregateLatest =
activeOptionData?.question.aggregations[
activeOptionData.question.default_aggregation_method
].latest;
const communityCdf: number[] | undefined =
aggregateLatest && isForecastActive(aggregateLatest)
? aggregateLatest.forecast_values
? aggregateLatest.forecast_values.map((v) => {
if (v === null) {
throw new Error("Forecast values contain null values");
}
return v;
})
: undefined;

const predictButtonIsDisabled =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ const ContinuousInputWrapper: FC<PropsWithChildren<Props>> = ({
[option]
);

const rawPreviousCdf = previousForecast?.forecast_values;
const rawPreviousCdf = previousForecast?.forecast_values.map((v) => {
if (v === null) {
throw new Error("Forecast values contain null values");
}
return v;
});
const showWithdrawnRow = option.wasWithdrawn && !option.isDirty;
const showPreviousRowByCheckbox =
!showWithdrawnRow && overlayPreviousForecast;
Expand Down Expand Up @@ -238,9 +243,14 @@ const ContinuousInputWrapper: FC<PropsWithChildren<Props>> = ({

const withdraw = () => onWithdraw();

const communityCdf: number[] | undefined =
option.question.aggregations[option.question.default_aggregation_method]
.latest?.forecast_values;
const communityCdf: number[] | undefined = option.question.aggregations[
option.question.default_aggregation_method
].latest?.forecast_values.map((v) => {
if (v === null) {
throw new Error("Forecast values contain null values");
}
return v;
});

const questionDuration =
new Date(option.question.scheduled_close_time).getTime() -
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,12 @@ const ForecastMakerGroupContinuous: FC<Props> = ({
questionId: id,
forecastEndTime: forecastExpirationToDate(forecastExpiration),
forecastData: {
continuousCdf: latest.forecast_values,
continuousCdf: latest.forecast_values.map((v) => {
if (v === null) {
throw new Error("Forecast values contain null values");
}
return v;
}),
probabilityYesPerCategory: null,
probabilityYes: null,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,12 @@ const ForecastMakerContinuous: FC<Props> = ({

const overlayPreviousCdf =
overlayPreviousForecast && previousForecast?.forecast_values
? previousForecast.forecast_values
? previousForecast.forecast_values.map((v) => {
if (v === null) {
throw new Error("Forecast values contain null values");
}
return v;
})
: undefined;

// Update states of forecast maker after new forecast is made
Expand Down Expand Up @@ -210,12 +215,24 @@ const ForecastMakerContinuous: FC<Props> = ({
const userCdf: number[] = dataset.cdf;
const userPreviousCdf: number[] | undefined =
overlayPreviousForecast && previousForecast
? previousForecast.forecast_values
? previousForecast.forecast_values.map((v) => {
if (v === null) {
throw new Error("Forecast values contain null values");
}
return v;
})
: undefined;
const latest =
question.aggregations[question.default_aggregation_method].latest;
const communityCdf: number[] | undefined =
latest && isForecastActive(latest) ? latest?.forecast_values : undefined;
latest && isForecastActive(latest)
? latest?.forecast_values.map((v) => {
if (v === null) {
throw new Error("Forecast values contain null values");
}
return v;
})
: undefined;

const handleAddComponent = () => {
setSliderDistributionComponents([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,12 @@ function generateReaffirmData({
const hasActivePrediction = latest && isForecastActive(latest);

if (hasActivePrediction) {
forecastValues = latest.forecast_values;
forecastValues = latest.forecast_values.map((v) => {
if (v === null) {
throw new Error("Forecast values contain null values");
}
return v;
});
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ const QuestionContinuousTile: FC<Props> = ({
{
questionId: question.id,
forecastData: {
continuousCdf: activeForecast.forecast_values,
continuousCdf: activeForecast.forecast_values.map((v) => {
if (v === null) {
throw new Error("Forecast values contain null values");
}
return v;
}),
probabilityYes: null,
probabilityYesPerCategory: null,
},
Expand Down
2 changes: 1 addition & 1 deletion front_end/src/components/prediction_chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Size = "compact" | "large";
type Props = {
question: QuestionWithForecasts;
status: PostStatus;
predictionOverride?: number; // override displayed CP (e.g. for graph cursor), otherwise the latest CP is used
predictionOverride?: number | null; // override displayed CP (e.g. for graph cursor), otherwise the latest CP is used
size?: Size;
className?: string;
chipClassName?: string;
Expand Down
12 changes: 6 additions & 6 deletions front_end/src/types/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ export type Forecast = {
question_id: number;
start_time: number;
end_time: number | null;
forecast_values: number[];
interval_lower_bounds: number[] | null;
centers: number[] | null;
interval_upper_bounds: number[] | null;
forecast_values: (number | null)[];
interval_lower_bounds: (number | null)[] | null;
centers: (number | null)[] | null;
interval_upper_bounds: (number | null)[] | null;
};

export type ScoreData = {
Expand Down Expand Up @@ -155,9 +155,9 @@ export type UserForecastHistory = {
export type AggregateForecast = Forecast & {
method: AggregationMethod;
forecaster_count: number;
means: number[] | null;
means: (number | null)[] | null;
histogram: number[][] | null;
forecast_values: number[] | null;
forecast_values: (number | null)[] | null;
};

export type AggregateForecastHistory = {
Expand Down
6 changes: 3 additions & 3 deletions front_end/src/utils/formatters/prediction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,9 @@ export function getUserPredictionDisplayValue({
return "...";
}

let center: number | undefined;
let lower: number | undefined = undefined;
let upper: number | undefined = undefined;
let center: number | null | undefined;
let lower: number | null | undefined = undefined;
let upper: number | null | undefined = undefined;
if (questionType === QuestionType.Binary) {
center = closestUserForecast.forecast_values[1];
} else {
Expand Down
Loading