Skip to content
Merged
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
3 changes: 3 additions & 0 deletions front_end/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"metaculusPredictionLabel": "Metaculus Prediction",
"userPredictionLabel": "User Prediction",
"myPrediction": "My Prediction",
"myPredictionPrevious": "My Prediction (previous)",
"myPredictionValue": "My Prediction: <forecast>{forecastValue}</forecast>",
"myCoverageLabel": "My Coverage",
"predictionLabel": "Prediction",
Expand All @@ -85,6 +86,8 @@
"secondQuartile": "median",
"thirdQuartile": "upper 75%",
"you": "you",
"youPrevious": "you (previous)",
"overlayPreviousForecast": "Overlay Previous Forecast",
"resolutionDescriptionBinary": "Did this actually happen?",
"resolutionDescriptionMultipleChoice": "Which of these actually happened?",
"resolutionDescriptionContinuous": "What was the final result?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { cdfToPmf } from "@/utils/math";

type Props = {
question: QuestionWithNumericForecasts;
overlayPreviousForecast?: boolean;
dataset: {
cdf: number[];
pmf: number[];
Expand All @@ -28,6 +29,7 @@ type Props = {

const ContinuousPredictionChart: FC<Props> = ({
question,
overlayPreviousForecast,
dataset,
graphType,
readOnly = false,
Expand Down Expand Up @@ -59,6 +61,13 @@ const ContinuousPredictionChart: FC<Props> = ({
: graphType === "pmf"
? (hoverState.yData.user * 200).toFixed(3)
: getForecastPctDisplayValue(hoverState.yData.user),
yUserPreviousLabel: readOnly
? null
: !hoverState.yData.user_previous
? null
: graphType === "pmf"
? (hoverState.yData.user_previous * 200).toFixed(3)
: getForecastPctDisplayValue(hoverState.yData.user_previous),
yCommunityLabel: !hoverState.yData.community
? null
: graphType === "pmf"
Expand Down Expand Up @@ -86,6 +95,14 @@ const ContinuousPredictionChart: FC<Props> = ({
});
}

if (overlayPreviousForecast && question.my_forecasts?.latest) {
charts.push({
pmf: cdfToPmf(question.my_forecasts.latest.forecast_values),
cdf: question.my_forecasts.latest.forecast_values,
type: "user_previous",
});
}

if (!readOnly || !!question.my_forecasts?.latest) {
charts.push({
pmf: dataset.pmf,
Expand All @@ -102,6 +119,7 @@ const ContinuousPredictionChart: FC<Props> = ({
readOnly,
showCP,
question.my_forecasts?.latest,
overlayPreviousForecast,
]);

return (
Expand Down Expand Up @@ -136,6 +154,16 @@ const ContinuousPredictionChart: FC<Props> = ({
{")"}
</span>
)}
{cursorDisplayData.yUserPreviousLabel !== null && (
<span>
<span className="font-bold text-gray-900 dark:text-gray-900-dark">
{cursorDisplayData.yUserPreviousLabel}
</span>
{" ("}
{t("youPrevious")}
{")"}
</span>
)}
{showCP && cursorDisplayData.yCommunityLabel && (
<span>
<span className="font-bold text-gray-900 dark:text-gray-900-dark">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { QuestionWithNumericForecasts } from "@/types/question";

import ContinuousPredictionChart from "./continuous_prediction_chart";
import { useHideCP } from "../cp_provider";
import Checkbox from "@/components/ui/checkbox";

type Props = {
forecast: MultiSliderValue[];
Expand All @@ -24,6 +25,8 @@ type Props = {
pmf: number[];
};
onChange: (forecast: MultiSliderValue[], weights: number[]) => void;
overlayPreviousForecast: boolean;
setOverlayPreviousForecast: (value: boolean) => void;
question: QuestionWithNumericForecasts;
disabled?: boolean;
};
Expand All @@ -33,30 +36,47 @@ const ContinuousSlider: FC<Props> = ({
weights,
dataset,
onChange,
overlayPreviousForecast,
setOverlayPreviousForecast,
question,
disabled = false,
}) => {
const { user } = useAuth();
const { hideCP } = useHideCP();
const t = useTranslations();
const [graphType, setGraphType] = useState<ContinuousAreaGraphType>("pmf");
const previousForecast = question.my_forecasts?.latest;

return (
<div>
<InlineSelect<ContinuousAreaGraphType>
options={[
{ label: t("pdfLabel"), value: "pmf" },
{ label: t("cdfLabel"), value: "cdf" },
]}
defaultValue={graphType}
className="appearance-none border-none !p-0 text-sm"
onChange={(e) =>
setGraphType(e.target.value as ContinuousAreaGraphType)
}
/>
<div className="mb-2 flex items-center">
<InlineSelect<ContinuousAreaGraphType>
options={[
{ label: t("pdfLabel"), value: "pmf" },
{ label: t("cdfLabel"), value: "cdf" },
]}
defaultValue={graphType}
className="appearance-none border-none !p-0 text-sm"
onChange={(e) =>
setGraphType(e.target.value as ContinuousAreaGraphType)
}
/>
{previousForecast && (
<div className="ml-auto flex items-center">
<Checkbox
checked={overlayPreviousForecast}
onChange={(checked) => setOverlayPreviousForecast(checked)}
className={"text-sm"}
label={t("overlayPreviousForecast")}
></Checkbox>
</div>
)}
</div>

<ContinuousPredictionChart
dataset={dataset}
graphType={graphType}
overlayPreviousForecast={overlayPreviousForecast}
question={question}
readOnly={disabled}
showCP={!user || !hideCP || !!question.resolution}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ const ForecastMakerConditionalContinuous: FC<Props> = ({
}
};

const previousForecast = activeOptionData?.question.my_forecasts?.latest;
const [overlayPreviousForecast, setOverlayPreviousForecast] =
useState<boolean>(
!!previousForecast?.forecast_values && !previousForecast.slider_values
);

const userCdf: number[] | undefined =
activeOptionData &&
getNumericForecastDataset(
Expand All @@ -323,6 +329,10 @@ const ForecastMakerConditionalContinuous: FC<Props> = ({
activeOptionData.question.open_lower_bound!,
activeOptionData.question.open_upper_bound!
).cdf;
const userPreviousCdf: number[] | undefined =
overlayPreviousForecast && previousForecast
? previousForecast.forecast_values
: undefined;
const communityCdf: number[] | undefined =
activeOptionData?.question.aggregations.recency_weighted.latest
?.forecast_values;
Expand Down Expand Up @@ -361,6 +371,8 @@ const ForecastMakerConditionalContinuous: FC<Props> = ({
question={option.question}
forecast={option.sliderForecast}
weights={option.weights}
overlayPreviousForecast={overlayPreviousForecast}
setOverlayPreviousForecast={setOverlayPreviousForecast}
dataset={getNumericForecastDataset(
option.sliderForecast,
option.weights,
Expand Down Expand Up @@ -450,6 +462,19 @@ const ForecastMakerConditionalContinuous: FC<Props> = ({
aboveUpper: 1 - communityCdf![communityCdf!.length - 1],
}
}
userPreviousBounds={
userPreviousCdf
? {
belowLower: userPreviousCdf[0],
aboveUpper: 1 - userPreviousCdf[userPreviousCdf.length - 1],
}
: undefined
}
userPreviousQuartiles={
userPreviousCdf
? computeQuartilesFromCDF(userPreviousCdf)
: undefined
}
communityQuartiles={
communityCdf && computeQuartilesFromCDF(communityCdf)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ const ForecastMakerGroupContinuous: FC<Props> = ({
}
}, [postId, questionsToSubmit]);

const previousForecast = activeGroupOption?.question.my_forecasts?.latest;
const [overlayPreviousForecast, setOverlayPreviousForecast] =
useState<boolean>(
!!previousForecast?.forecast_values && !previousForecast.slider_values
);

const userCdf: number[] | undefined =
activeGroupOption &&
getNumericForecastDataset(
Expand All @@ -275,6 +281,10 @@ const ForecastMakerGroupContinuous: FC<Props> = ({
activeGroupOption?.question.open_lower_bound!,
activeGroupOption?.question.open_upper_bound!
).cdf;
const userPreviousCdf: number[] | undefined =
overlayPreviousForecast && previousForecast
? previousForecast.forecast_values
: undefined;
const communityCdf: number[] | undefined =
activeGroupOption?.question.aggregations.recency_weighted.latest
?.forecast_values;
Expand Down Expand Up @@ -312,6 +322,8 @@ const ForecastMakerGroupContinuous: FC<Props> = ({
<ContinuousSlider
question={option.question}
forecast={normalizedUserForecast}
overlayPreviousForecast={overlayPreviousForecast}
setOverlayPreviousForecast={setOverlayPreviousForecast}
weights={option.userWeights}
dataset={dataset}
onChange={(forecast, weight) =>
Expand Down Expand Up @@ -387,6 +399,19 @@ const ForecastMakerGroupContinuous: FC<Props> = ({
}
}
userQuartiles={activeGroupOption.userQuartiles ?? undefined}
userPreviousBounds={
userPreviousCdf
? {
belowLower: userPreviousCdf[0],
aboveUpper: 1 - userPreviousCdf[userPreviousCdf.length - 1],
}
: undefined
}
userPreviousQuartiles={
userPreviousCdf
? computeQuartilesFromCDF(userPreviousCdf)
: undefined
}
communityBounds={
communityCdf && {
belowLower: communityCdf[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ const ForecastMakerContinuous: FC<Props> = ({
const [weights, setWeights] = useState<number[]>(
prevForecastValue?.weights ?? [1]
);
const previousForecast = question.my_forecasts?.latest;
const [overlayPreviousForecast, setOverlayPreviousForecast] =
useState<boolean>(
!!previousForecast?.forecast_values && !previousForecast.slider_values
);

const dataset = useMemo(
() =>
Expand All @@ -81,6 +86,10 @@ const ForecastMakerContinuous: FC<Props> = ({
);

const userCdf: number[] = dataset.cdf;
const userPreviousCdf: number[] | undefined =
overlayPreviousForecast && previousForecast
? previousForecast.forecast_values
: undefined;
const communityCdf: number[] | undefined =
question.aggregations.recency_weighted.latest?.forecast_values;

Expand Down Expand Up @@ -131,6 +140,8 @@ const ForecastMakerContinuous: FC<Props> = ({
setWeights(weight);
setIsDirty(true);
}}
overlayPreviousForecast={overlayPreviousForecast}
setOverlayPreviousForecast={setOverlayPreviousForecast}
question={question}
disabled={!canPredict}
/>
Expand Down Expand Up @@ -176,6 +187,17 @@ const ForecastMakerContinuous: FC<Props> = ({
aboveUpper: 1 - userCdf[userCdf.length - 1],
}}
userQuartiles={userCdf ? computeQuartilesFromCDF(userCdf) : undefined}
userPreviousBounds={
userPreviousCdf
? {
belowLower: userPreviousCdf[0],
aboveUpper: 1 - userPreviousCdf[userPreviousCdf.length - 1],
}
: undefined
}
userPreviousQuartiles={
userPreviousCdf ? computeQuartilesFromCDF(userPreviousCdf) : undefined
}
communityBounds={
communityCdf
? {
Expand Down
Loading