import { QuestionFragment } from "../../fragments.generated"; type QualityIndicator = QuestionFragment["qualityIndicators"]; type IndicatorName = keyof QualityIndicator; // this duplication can probably be simplified with typescript magic, but this is good enough for now type UsedIndicatorName = | "volume" | "numForecasters" | "spread" | "sharesVolume" | "liquidity" | "tradeVolume" | "openInterest"; const qualityIndicatorLabels: { [k in UsedIndicatorName]: string } = { // numForecasts: null, // stars: null, // yesBid: "Yes bid", // yesAsk: "Yes ask", volume: "Volume", numForecasters: "Forecasters", spread: "Spread", sharesVolume: "Shares vol.", liquidity: "Liquidity", tradeVolume: "Volume", openInterest: "Interest", }; const formatNumber = (num) => { if (Number(num) < 1000) { return Number(num).toFixed(0); } else if (num < 10000) { return (Number(num) / 1000).toFixed(1) + "k"; } else { return (Number(num) / 1000).toFixed(0) + "k"; } }; /* Display functions*/ const getPercentageSymbolIfNeeded = ({ indicator, platform, }: { indicator: UsedIndicatorName; platform: string; }) => { let indicatorsWhichNeedPercentageSymbol: IndicatorName[] = ["spread"]; if (indicatorsWhichNeedPercentageSymbol.includes(indicator)) { return "%"; } else { return ""; } }; const getCurrencySymbolIfNeeded = ({ indicator, platform, }: { indicator: UsedIndicatorName; platform: string; }) => { const indicatorsWhichNeedCurrencySymbol: IndicatorName[] = [ "volume", "tradeVolume", "openInterest", "liquidity", ]; let dollarPlatforms = ["predictit", "kalshi", "polymarket"]; if (indicatorsWhichNeedCurrencySymbol.includes(indicator)) { if (dollarPlatforms.includes(platform)) { return "$"; } else { return "£"; } } else { return ""; } }; const FirstQualityIndicator: React.FC<{ question: QuestionFragment; }> = ({ question }) => { if (question.qualityIndicators.numForecasts) { return (
Forecasts:  {Number(question.qualityIndicators.numForecasts).toFixed(0)}
); } else { return null; } }; const QualityIndicatorsList: React.FC<{ question: QuestionFragment; }> = ({ question }) => { return (
{Object.entries(question.qualityIndicators).map((entry, i) => { const indicatorLabel = qualityIndicatorLabels[entry[0]]; if (!indicatorLabel || entry[1] === null) return; const indicator = entry[0] as UsedIndicatorName; // guaranteed by the previous line const value = entry[1]; return (
{indicatorLabel}:  {`${getCurrencySymbolIfNeeded({ indicator, platform: question.platform.id, })}${formatNumber(value)}${getPercentageSymbolIfNeeded({ indicator, platform: question.platform.id, })}`}
); })}
); }; // Database-like functions export function getstars(numstars: number) { let stars = "★★☆☆☆"; switch (numstars) { case 0: stars = "☆☆☆☆☆"; break; case 1: stars = "★☆☆☆☆"; break; case 2: stars = "★★☆☆☆"; break; case 3: stars = "★★★☆☆"; break; case 4: stars = "★★★★☆"; break; case 5: stars = "★★★★★"; break; default: stars = "★★☆☆☆"; } return stars; } function getStarsColor(numstars: number) { let color = "text-yellow-400"; switch (numstars) { case 0: color = "text-red-400"; break; case 1: color = "text-red-400"; break; case 2: color = "text-orange-400"; break; case 3: color = "text-yellow-400"; break; case 4: color = "text-green-400"; break; case 5: color = "text-blue-400"; break; default: color = "text-yellow-400"; } return color; } interface Props { question: QuestionFragment; expandFooterToFullWidth: boolean; } export const QuestionFooter: React.FC = ({ question, expandFooterToFullWidth, }) => { return (
{getstars(question.qualityIndicators.stars)}
{question.platform.label .replace("Good Judgment Open", "GJOpen") .replace(/ /g, "\u00a0")}
); };