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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,6 +90,7 @@ const QuestionForecastMaker: FC<Props> = ({
<QuestionResolutionText question={question} />
</>
)}
<ScoreDisplay question={question} />
</ForecastMakerContainer>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Props> = ({ 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 (
<>
<div className="mb-4 grid grid-cols-4 gap-4">
{user_scores?.baseline_score != null && (
<div className="box border border-gray-300 p-2 text-center">
<span>My Baseline Score</span>
<div>{user_scores.baseline_score.toFixed(1)}</div>
</div>
)}
{user_scores?.peer_score != null && (
<div className="box border border-gray-300 p-2 text-center">
<span>My Peer Score</span>
<div>{user_scores.peer_score.toFixed(1)}</div>
</div>
)}
{cp_scores?.baseline_score != null && (
<div className="box border border-gray-300 p-2 text-center">
<span>Community Baseline Score</span>
<div>{cp_scores.baseline_score.toFixed(1)}</div>
</div>
)}
{cp_scores?.peer_score != null && (
<div className="box border border-gray-300 p-2 text-center">
<span>Community Peer Score</span>
<div>{cp_scores.peer_score.toFixed(1)}</div>
</div>
)}
</div>
<SectionToggle title="Additional Scores" defaultOpen={false}>
<div className="mb-4 mt-4 grid grid-cols-4 gap-4">
{user_scores?.spot_baseline_score != null && (
<div className="box border border-gray-300 p-2 text-center">
<span>My Spot Baseline Score</span>
<div>{user_scores.spot_baseline_score.toFixed(1)}</div>
</div>
)}
{user_scores?.spot_peer_score != null && (
<div className="box border border-gray-300 p-2 text-center">
<span>My Spot Peer Score</span>
<div>{user_scores.spot_peer_score.toFixed(1)}</div>
</div>
)}
{user_scores?.relative_legacy_score != null && (
<div className="box border border-gray-300 p-2 text-center">
<span>My Relative Legacy Score</span>
<div>{user_scores.relative_legacy_score.toFixed(2)}</div>
</div>
)}
{user_scores?.relative_legacy_arvhived_score != null && (
<div className="box border border-gray-300 p-2 text-center">
<span>My Relative Legacy Archived Score</span>
<div>{user_scores.relative_legacy_arvhived_score.toFixed(2)}</div>
</div>
)}
{user_scores?.coverage != null && (
<div className="box border border-gray-300 p-2 text-center">
<span>My Coverage</span>
<div>{(user_scores.coverage * 100).toFixed(1)}%</div>
</div>
)}
{user_scores?.weighted_coverage != null && (
<div className="box border border-gray-300 p-2 text-center">
<span>My Weighted Coverage</span>
<div>{(user_scores.weighted_coverage * 100).toFixed(1)}%</div>
</div>
)}
</div>
</SectionToggle>
</>
);
};

export default ScoreDisplay;
13 changes: 13 additions & 0 deletions front_end/src/types/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,25 @@ 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
};

export type UserForecastHistory = {
history: UserForecast[];
latest?: UserForecast;
score_data?: ScoreData;
};

export type AggregateForecast = Forecast & {
Expand All @@ -84,6 +96,7 @@ export type AggregateForecast = Forecast & {
export type AggregateForecastHistory = {
history: AggregateForecast[];
latest?: AggregateForecast;
score_data?: ScoreData;
};

export type Aggregations = {
Expand Down
56 changes: 49 additions & 7 deletions questions/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -355,20 +359,37 @@ 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
and not current_user.is_anonymous
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(
Expand All @@ -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

Expand Down