From ea5843673ce8f416f5f3b0ba40602f0612167238 Mon Sep 17 00:00:00 2001 From: lsabor Date: Wed, 28 Aug 2024 12:46:01 -0700 Subject: [PATCH 1/3] add score box info to binary, mc, and continuous questions --- .../forecast_maker_question/index.tsx | 4 + .../resolution/score_display.tsx | 89 +++++++++++++++++++ front_end/src/types/question.ts | 13 +++ posts/views.py | 2 +- questions/serializers.py | 56 ++++++++++-- 5 files changed, 156 insertions(+), 8 deletions(-) create mode 100644 front_end/src/app/(main)/questions/[id]/components/forecast_maker/resolution/score_display.tsx diff --git a/front_end/src/app/(main)/questions/[id]/components/forecast_maker/forecast_maker_question/index.tsx b/front_end/src/app/(main)/questions/[id]/components/forecast_maker/forecast_maker_question/index.tsx index c92f1a891c..75387d0f2f 100644 --- a/front_end/src/app/(main)/questions/[id]/components/forecast_maker/forecast_maker_question/index.tsx +++ b/front_end/src/app/(main)/questions/[id]/components/forecast_maker/forecast_maker_question/index.tsx @@ -10,6 +10,7 @@ import ForecastMakerBinary from "./forecast_maker_binary"; import ForecastMakerContinuous from "./forecast_maker_continuous"; import ForecastMakerMultipleChoice from "./forecast_maker_multiple_choice"; import ForecastMakerContainer from "../container"; +import ScoreDisplay from "../resolution/score_display"; type Props = { postId: number; @@ -54,6 +55,7 @@ const QuestionForecastMaker: FC = ({ canResolve={canResolve} /> + )} {question.type === QuestionType.Binary && ( @@ -71,6 +73,7 @@ const QuestionForecastMaker: FC = ({ canResolve={canResolve} /> + )} {question.type === QuestionType.MultipleChoice && ( @@ -87,6 +90,7 @@ const QuestionForecastMaker: FC = ({ canResolve={canResolve} /> + )} diff --git a/front_end/src/app/(main)/questions/[id]/components/forecast_maker/resolution/score_display.tsx b/front_end/src/app/(main)/questions/[id]/components/forecast_maker/resolution/score_display.tsx new file mode 100644 index 0000000000..47394e68ee --- /dev/null +++ b/front_end/src/app/(main)/questions/[id]/components/forecast_maker/resolution/score_display.tsx @@ -0,0 +1,89 @@ +import { QuestionWithForecasts } from "@/types/question"; +import { FC } from "react"; +import SectionToggle from "@/components/ui/section_toggle"; + +type Props = { + question: QuestionWithForecasts; +}; + +const ScoreDisplay: FC = ({ question }) => { + const cp_scores = question.aggregations.recency_weighted.score_data; + const user_scores = question.my_forecasts?.score_data; + if (!cp_scores && !user_scores) return null; + + console.log("cp_scores", cp_scores); + console.log("user_scores", user_scores); + + return ( + <> +
+ {user_scores?.baseline_score != null && ( +
+ My Baseline Score +
{user_scores.baseline_score.toFixed(1)}
+
+ )} + {user_scores?.peer_score != null && ( +
+ My Peer Score +
{user_scores.peer_score.toFixed(1)}
+
+ )} + {cp_scores?.baseline_score != null && ( +
+ Community Baseline Score +
{cp_scores.baseline_score.toFixed(1)}
+
+ )} + {cp_scores?.peer_score != null && ( +
+ Community Peer Score +
{cp_scores.peer_score.toFixed(1)}
+
+ )} +
+ +
+ {user_scores?.spot_baseline_score != null && ( +
+ My Spot Baseline Score +
{user_scores.spot_baseline_score.toFixed(1)}
+
+ )} + {user_scores?.spot_peer_score != null && ( +
+ My Spot Peer Score +
{user_scores.spot_peer_score.toFixed(1)}
+
+ )} + {user_scores?.relative_legacy_score != null && ( +
+ My Relative Legacy Score +
{user_scores.relative_legacy_score.toFixed(2)}
+
+ )} + {user_scores?.relative_legacy_arvhived_score != null && ( +
+ My Relative Legacy Archived Score +
{user_scores.relative_legacy_arvhived_score.toFixed(2)}
+
+ )} + {user_scores?.coverage != null && ( +
+ My Coverage +
{(user_scores.coverage * 100).toFixed(1)}%
+
+ )} + {user_scores?.weighted_coverage != null && ( +
+ My Weighted Coverage +
{(user_scores.weighted_coverage * 100).toFixed(1)}%
+
+ )} +
+
+ + ); +}; + +export default ScoreDisplay; diff --git a/front_end/src/types/question.ts b/front_end/src/types/question.ts index dedde6d22d..c564c6fe1c 100644 --- a/front_end/src/types/question.ts +++ b/front_end/src/types/question.ts @@ -65,6 +65,17 @@ export type Forecast = { interval_upper_bounds: number[] | null; }; +export type ScoreData = { + baseline_score?: number | null; + peer_score?: number | null; + spot_baseline_score?: number | null; + spot_peer_score?: number | null; + relative_legacy_score?: number | null; + relative_legacy_arvhived_score?: number | null; + coverage?: number | null; + weighted_coverage?: number | null; +}; + export type UserForecast = Forecast & { slider_values: any | null; // TODO: solidify this }; @@ -72,6 +83,7 @@ export type UserForecast = Forecast & { export type UserForecastHistory = { history: UserForecast[]; latest?: UserForecast; + score_data?: ScoreData; }; export type AggregateForecast = Forecast & { @@ -84,6 +96,7 @@ export type AggregateForecast = Forecast & { export type AggregateForecastHistory = { history: AggregateForecast[]; latest?: AggregateForecast; + score_data?: ScoreData; }; export type Aggregations = { diff --git a/posts/views.py b/posts/views.py index b53e2048f9..266a32dceb 100644 --- a/posts/views.py +++ b/posts/views.py @@ -469,6 +469,6 @@ def post_related_articles_api_view(request: Request, pk): ObjectPermission.can_view(permission, raise_exception=True) # Retrieve cached articles - articles = get_post_get_similar_articles(post) + articles = [] # get_post_get_similar_articles(post) return Response(PostRelatedArticleSerializer(articles, many=True).data) diff --git a/questions/serializers.py b/questions/serializers.py index cf7f5cff17..1b0c17b8e5 100644 --- a/questions/serializers.py +++ b/questions/serializers.py @@ -329,10 +329,14 @@ def serialize_question( for aggregate in aggregate_forecasts: aggregate_forecasts_by_method[aggregate.method].append(aggregate) serialized_data["aggregations"] = { - "recency_weighted": {"history": [], "latest": None}, - "unweighted": {"history": [], "latest": None}, - "single_aggregation": {"history": [], "latest": None}, - "metaculus_prediction": {"history": [], "latest": None}, + "recency_weighted": {"history": [], "latest": None, "score_data": dict()}, + "unweighted": {"history": [], "latest": None, "score_data": dict()}, + "single_aggregation": {"history": [], "latest": None, "score_data": dict()}, + "metaculus_prediction": { + "history": [], + "latest": None, + "score_data": dict(), + }, } for method, forecasts in aggregate_forecasts_by_method.items(): scores = question.scores.filter(aggregation_method=method) @@ -355,13 +359,29 @@ def serialize_question( else None ) for score in scores: - serialized_data["aggregations"][method][ + serialized_data["aggregations"][method]["score_data"][ score.score_type + "_score" ] = score.score + if score.score_type == "peer": + serialized_data["aggregations"][method]["score_data"][ + "coverage" + ] = score.coverage + if score.score_type == "relative_legacy": + serialized_data["aggregations"][method]["score_data"][ + "weighted_coverage" + ] = score.coverage for score in archived_scores: - serialized_data["aggregations"][method][ + serialized_data["aggregations"][method]["score_data"][ score.score_type + "_archived_score" ] = score.score + if score.score_type == "peer": + serialized_data["aggregations"][method]["score_data"][ + "coverage" + ] = score.coverage + if score.score_type == "relative_legacy": + serialized_data["aggregations"][method]["score_data"][ + "weighted_coverage" + ] = score.coverage if ( current_user @@ -369,6 +389,7 @@ def serialize_question( and hasattr(question, "request_user_forecasts") ): scores = question.scores.filter(user=current_user) + archived_scores = question.archived_scores.filter(user=current_user) user_forecasts = question.request_user_forecasts serialized_data["my_forecasts"] = { "history": MyForecastSerializer( @@ -383,11 +404,32 @@ def serialize_question( if user_forecasts else None ), + "score_data": dict(), } for score in scores: - serialized_data["my_forecasts"][ + serialized_data["my_forecasts"]["score_data"][ score.score_type + "_score" ] = score.score + if score.score_type == "peer": + serialized_data["my_forecasts"]["score_data"][ + "coverage" + ] = score.coverage + if score.score_type == "relative_legacy": + serialized_data["my_forecasts"]["score_data"][ + "weighted_coverage" + ] = score.coverage + for score in archived_scores: + serialized_data["my_forecasts"]["score_data"][ + score.score_type + "_archived_score" + ] = score.score + if score.score_type == "peer": + serialized_data["my_forecasts"]["score_data"][ + "coverage" + ] = score.coverage + if score.score_type == "relative_legacy": + serialized_data["my_forecasts"]["score_data"][ + "weighted_coverage" + ] = score.coverage serialized_data["resolution"] = question.resolution From 39cfe3bbab6fd522220558a8e77da3eea0d5c5fa Mon Sep 17 00:00:00 2001 From: lsabor Date: Wed, 28 Aug 2024 12:46:42 -0700 Subject: [PATCH 2/3] uncomment temp thing --- posts/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posts/views.py b/posts/views.py index 266a32dceb..b53e2048f9 100644 --- a/posts/views.py +++ b/posts/views.py @@ -469,6 +469,6 @@ def post_related_articles_api_view(request: Request, pk): ObjectPermission.can_view(permission, raise_exception=True) # Retrieve cached articles - articles = [] # get_post_get_similar_articles(post) + articles = get_post_get_similar_articles(post) return Response(PostRelatedArticleSerializer(articles, many=True).data) From 9ee034777ab60a9291615b0ba6b968645fcb3a6f Mon Sep 17 00:00:00 2001 From: lsabor Date: Wed, 28 Aug 2024 12:49:57 -0700 Subject: [PATCH 3/3] simplify score display refs --- .../forecast_maker/forecast_maker_question/index.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/front_end/src/app/(main)/questions/[id]/components/forecast_maker/forecast_maker_question/index.tsx b/front_end/src/app/(main)/questions/[id]/components/forecast_maker/forecast_maker_question/index.tsx index 75387d0f2f..29ae913f97 100644 --- a/front_end/src/app/(main)/questions/[id]/components/forecast_maker/forecast_maker_question/index.tsx +++ b/front_end/src/app/(main)/questions/[id]/components/forecast_maker/forecast_maker_question/index.tsx @@ -55,7 +55,6 @@ const QuestionForecastMaker: FC = ({ canResolve={canResolve} /> - )} {question.type === QuestionType.Binary && ( @@ -73,7 +72,6 @@ const QuestionForecastMaker: FC = ({ canResolve={canResolve} /> - )} {question.type === QuestionType.MultipleChoice && ( @@ -90,9 +88,9 @@ const QuestionForecastMaker: FC = ({ canResolve={canResolve} /> - )} + ); };