8000 add archive scores migration by lsabor · Pull Request #243 · Metaculus/metaculus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add archive scores migration #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 26, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
NEXT_PUBLIC_TURNSTILE_SITE_KEY: ${{ secrets.NEXT_PUBLIC_TURNSTILE_SITE_KEY }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
run: |
poetry run ./manage.py migrate
PLAYWRIGHT_BROWSERS_PATH=.venv scripts/run_integration_tests.sh
- name: Create trace.zip
if: always()
Expand Down
7 changes: 7 additions & 0 deletions front_end/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,9 @@
"total": "Total",
"average": "Average",
"score": "Score",
"coverage": "Coverage",
"totalScore": "Total Score",
"totalTake": "Total Take",
"weightedAverageScore": "Weighted Average Score",
"hIndex": "H-Index",
"upvotes": "Upvotes",
Expand Down Expand Up @@ -617,6 +619,11 @@
"scoringTerminology": "Scoring Terminology",
"pearScoreInfo": "Your <link>Peer Score</link> on that question. If you see no score, then either the question has yet to resolve or you haven’t predicted it (or both!).",
"totalPeerScoreInfo": "The sum of your <link>Peer Scores</link> on all questions in the tournament (but only those that close before the end of the tournament).",
"peerTakeInfo": "Your Take is the square of the sum of your peer scores or 0 if your total score is negative.",
"relativeScoreInfo": "Your <link>Relative Score</link> on that question. If you see no score, then either the question has yet to resolve or you haven’t predicted it (or both!).",
"totalRelativeScoreInfo": "The sum of your <link>Relative Scores</link> on all questions in the tournament (but only those that close before the end of the tournament).",
"relativeCoverageInfo": "The amount of the question or tournament that you covered.",
"relativeTakeInfo": "Your Take is your coverage times e to the power of your total score. (c*e^s)",
"backgroundInfo": "Background Info",
"parentBackgroundInfo": "Parent Question Background Info",
"childBackgroundInfo": "Child Question Background Info",
Expand Down
124 changes: 100 additions & 24 deletions < 8000 /span> front_end/src/app/(main)/(leaderboards)/contributions/components/project_contributions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,21 @@ import { FC } from "react";
import InfoToggle from "@/components/ui/info_toggle";
import SectionToggle from "@/components/ui/section_toggle";
import LeaderboardApi from "@/services/leaderboard";
import { Tournament } from "@/types/projects";

type Props = {
projectId: number;
project: Tournament;
userId: number;
};

const ProjectContributions: FC<Props> = async ({ projectId, userId }) => {
const ProjectContributions: FC<Props> = async ({ project, userId }) => {
const t = await getTranslations();
const contributionsDetails = await LeaderboardApi.getContributions({
type: "project",
userId,
projectId,
projectId: project.id,
});

const totalScore = contributionsDetails.contributions
.reduce((acc, contribution) => acc + (contribution.score ?? 0), 0)
.toFixed(2);

return (
<SectionToggle
title={t("myScore")}
Expand All @@ -36,6 +33,11 @@ const ProjectContributions: FC<Props> = async ({ projectId, userId }) => {
{t("Question")}
</th>
<th className="p-2 text-right text-sm font- 6DB6 bold">{t("score")}</th>
{project.score_type === "relative_legacy_tournament" && (
<th className="p-2 text-right text-sm font-bold">
{t("coverage")}
</th>
)}
</tr>
</thead>
<tbody>
Expand All @@ -53,20 +55,46 @@ const ProjectContributions: FC<Props> = async ({ projectId, userId }) => {
</Link>
</td>
<td className="px-2 py-1 text-right text-sm font-bold text-orange-800 dark:text-orange-800-dark">
{contribution.score?.toFixed(2)}
{contribution.score ? contribution.score.toFixed(2) : "-"}
</td>
{project.score_type === "relative_legacy_tournament" && (
<th className="p-2 text-right text-sm font-bold">
{contribution.coverage
? `${(contribution.coverage * 100).toFixed(0)}%`
: "0%"}
</th>
)}
</tr>
))}
</tbody>

<tfoot>
<tr>
<th className="px-2 py-1 text-right text-sm">{t("totalTake")}</th>
<td className="px-2 py-1 text-right text-sm font-bold text-orange-800 dark:text-orange-800-dark">
{contributionsDetails.leaderboard_entry.take
? `${contributionsDetails.leaderboard_entry.take.toFixed(3)}`
: "-"}
</td>
</tr>
</tfoot>
<tfoot>
<tr>
<th className="px-2 py-1 text-right text-sm">
{t("totalScore")}
</th>
<td className="px-2 py-1 text-right text-sm font-bold text-orange-800 dark:text-orange-800-dark">
{totalScore}
{contributionsDetails.leaderboard_entry.score
? `${contributionsDetails.leaderboard_entry.score.toFixed(2)}`
: "-"}
</td>
{project.score_type === "relative_legacy_tournament" && (
<th className="p-2 text-right text-sm font-bold">
{contributionsDetails.leaderboard_entry.coverage
? `${(contributionsDetails.leaderboard_entry.coverage * 100).toFixed(2)}%`
: "0%"}
</th>
)}
</tr>
</tfoot>
</table>
Expand All @@ -77,23 +105,71 @@ const ProjectContributions: FC<Props> = async ({ projectId, userId }) => {
<dl className="m-0">
<div className="m-2 flex text-sm">
<dt className="mr-2 w-20 flex-none font-bold">{t("score")}</dt>
<dd>
{t.rich("pearScoreInfo", {
link: (chunks) => (
<Link href={"/help/scores-faq/#peer-score"}>{chunks}</Link>
),
})}
</dd>
{project.score_type === "peer_tournament" ? (
<dd>
{t.rich("pearScoreInfo", {
link: (chunks) => (
<Link href={"/help/scores-faq/#peer-score"}>
{chunks}
</Link>
),
})}
</dd>
) : (
<dd>
{t.rich("relativeScoreInfo", {
link: (chunks) => (
<Link href={"/help/scores-faq/#relative-score"}>
{chunks}
</Link>
),
})}
</dd>
)}
</div>
<div className="m-2 flex text-sm">
<dt className="mr-2 w-20 flex-none font-bold">
{t("totalScore")}
</dt>
{project.score_type === "peer_tournament" ? (
<dd>
{t.rich("totalPeerScoreInfo", {
link: (chunks) => (
<Link href={"/help/scores-faq/#peer-score"}>
{chunks}
</Link>
),
})}
</dd>
) : (
<dd>
{t.rich("totalRelativeScoreInfo", {
link: (chunks) => (
<Link href={"/help/scores-faq/#relative-score"}>
{chunks}
</Link>
),
})}
</dd>
)}
</div>
{project.score_type === "relative_legacy_tournament" && (
<div className="m-2 flex text-sm">
<dt className="mr-2 w-20 flex-none font-bold">
{t("coverage")}
</dt>
<dd>{t("relativeCoverageInfo")}</dd>
</div>
)}
<div className="m-2 flex text-sm">
<dt className="mr-2 w-20 flex-none font-bold">{t("total")}</dt>
<dd>
{t.rich("totalPeerScoreInfo", {
link: (chunks) => (
<Link href={"/help/scores-faq/#peer-score"}>{chunks}</Link>
),
})}
</dd>
<dt className="mr-2 w-20 flex-none font-bold">
{t("totalTake")}
</dt>
{project.score_type === "peer_tournament" ? (
<dd>{t("peerTakeInfo")}</dd>
) : (
<dd>{t("relativeTakeInfo")}</dd>
)}
</div>
</dl>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const ProjectLeaderboardTable: FC<Props> = ({
setStep((prev) => (isNil(prev) ? prev : prev * 10));
};

const withCoverage =
leaderboardDetails.score_type === "relative_legacy_tournament";
const withTake = leaderboardDetails.entries.some(
(entry) => !isNil(entry.take)
);
Expand All @@ -57,6 +59,9 @@ const ProjectLeaderboardTable: FC<Props> = ({
{t("forecaster")}
</TableHeader>
<TableHeader className="text-right">{t("totalScore")}</TableHeader>
{withCoverage && (
<TableHeader className="text-right">{t("coverage")}</TableHeader>
)}
{withTake && (
<TableHeader className="text-right">{t("take")}</TableHeader>
)}
Expand All @@ -76,6 +81,7 @@ const ProjectLeaderboardTable: FC<Props> = ({
key={entry.user?.id ?? entry.aggregation_method}
rowEntry={entry}
userId={userId}
withCoverage={withCoverage}
withTake={withTake}
withPrize={withPrize}
prizePool={prizePool}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import MedalIcon from "../../../components/medal_icon";

type Props = {
rowEntry: LeaderboardEntry;
withCoverage: boolean;
withTake: boolean;
withPrize: boolean;
prizePool: number;
Expand All @@ -17,13 +18,23 @@ type Props = {

const TableRow: FC<Props> = ({
rowEntry,
withCoverage,
withTake,
withPrize,
userId,
prizePool,
}) => {
const { user, aggregation_method, medal, rank, score, take, percent_prize } =
rowEntry;
const {
user,
aggregation_method,
medal,
rank,
score,
coverage,
take,
percent_prize,
prize,
} = rowEntry;
const highlight = user?.id === userId;

return (
Expand All @@ -42,15 +53,24 @@ const TableRow: FC<Props> = ({
user ? `/accounts/profile/${user.id}/` : `questions/track-record/`
}
>
{user ? user.username : aggregation_method}
{user
? user.username
: aggregation_method == "recency_weighted"
? "Recency Weighted CP"
: aggregation_method}
</Link>
</Td>
<Td className="text-right" highlight={highlight}>
{score.toFixed(2)}
{score.toFixed(3)}
</Td>
{withCoverage && (
<Td className="text-right" highlight={highlight}>
{coverage ? `${(coverage * 100).toFixed(0)}%` : "-"}
</Td>
)}
{withTake && (
<Td className="text-right" highlight={highlight}>
{take?.toFixed(2)}
{take?.toFixed(3)}
</Td>
)}
{withPrize && (
Expand All @@ -59,7 +79,7 @@ const TableRow: FC<Props> = ({
{percent_prize ? `${(percent_prize * 100).toFixed(1)}%` : "-"}
</Td>
<Td className="text-right" highlight={highlight}>
{getUserPrize(prizePool, percent_prize)}
{prize && prize >= 10 ? "$" + prize.toFixed(0) : "-"}
</Td>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default async function TournamentSlug({
/>
{currentUser && (
<ProjectContributions
projectId={tournament.id}
project={tournament}
userId={currentUser.id}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ const ContinuousSlider: FC<Props> = ({
defaultValue={weights[index]}
round={true}
=> {
const newWeights = normWeights([
const newWeights = [
...weights.slice(0, index),
value,
...weights.slice(index + 1, forecast.length),
]);
];
onChange(forecast, newWeights);
}}
disabled={disabled}
Expand All @@ -110,10 +110,10 @@ const ContinuousSlider: FC<Props> = ({
...forecast.slice(0, index),
...forecast.slice(index + 1, forecast.length),
];
const newWeights = normWeights([
const newWeights = [
...weights.slice(0, index),
...weights.slice(index + 1, forecast.length),
]);
];
onChange(newForecast, newWeights);
}}
/>
Expand All @@ -126,8 +126,4 @@ const ContinuousSlider: FC<Props> = ({
);
};

function normWeights(weights: number[]) {
return weights.map((x) => x / weights.reduce((a, b) => a + b));
}

export default ContinuousSlider;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { Quartiles, QuestionWithNumericForecasts } from "@/types/question";
import {
extractPrevNumericForecastValue,
getNumericForecastDataset,
normalizeWeights,
} from "@/utils/forecasts";
import { computeQuartilesFromCDF } from "@/utils/math";

Expand Down Expand Up @@ -194,7 +193,7 @@ const ForecastMakerConditionalContinuous: FC<Props> = ({
...prevChoice.sliderForecast,
{ left: 0.4, center: 0.5, right: 0.6 },
],
weights: normalizeWeights([...prevChoice.weights, 1]),
weights: [...prevChoice.weights, 1],
isDirty: true,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { QuestionWithNumericForecasts } from "@/types/question";
import {
extractPrevNumericForecastValue,
getNumericForecastDataset,
normalizeWeights,
} from "@/utils/forecasts";
import { computeQuartilesFromCDF } from "@/utils/math";
import { extractQuestionGroupName, formatResolution } from "@/utils/questions";
Expand Down Expand Up @@ -133,7 +132,7 @@ const ForecastMakerGroupContinuous: FC<Props> = ({
...prevChoice.userForecast,
{ left: 0.4, center: 0.5, right: 0.6 },
];
const newWeights = normalizeWeights([...prevChoice.userWeights, 1]);
const newWeights = [...prevChoice.userWeights, 1];
const newUserQuartiles = getUserQuartiles(
newUserForecast,
newWeights
Expand Down
Loading
0