import { QuestionFragment } from "../../search/queries.generated"; type QualityIndicator = QuestionFragment["qualityIndicators"]; type IndicatorName = keyof QualityIndicator; const formatQualityIndicator = (indicator: IndicatorName) => { let result: string | null = null; switch (indicator) { case "numForecasts": result = null; break; case "stars": result = null; break; case "volume": result = "Volume"; break; case "numForecasters": result = "Forecasters"; break; // case "yesBid": // result = null; // "Yes bid" // break; // case "yesAsk": // result = null; // "Yes ask" // break; case "spread": result = "Spread"; break; case "sharesVolume": result = "Shares vol."; break; case "openInterest": result = "Interest"; break; // case "resolution_data": // result = null; // break; case "liquidity": result = "Liquidity"; break; case "tradeVolume": result = "Volume"; break; } return result; }; 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"; } }; const formatQualityIndicators = (qualityIndicators: QualityIndicator) => { let newQualityIndicators: { [k: string]: string | number } = {}; for (const key of Object.keys(qualityIndicators)) { const newKey = formatQualityIndicator(key as IndicatorName); if (newKey && qualityIndicators[key] !== null) { newQualityIndicators[newKey] = qualityIndicators[key]; } } return newQualityIndicators; }; /* Display functions*/ const getPercentageSymbolIfNeeded = ({ indicator, platform, }: { indicator: string; platform: string; }) => { let indicatorsWhichNeedPercentageSymbol = ["Spread"]; if (indicatorsWhichNeedPercentageSymbol.includes(indicator)) { return "%"; } else { return ""; } }; const getCurrencySymbolIfNeeded = ({ indicator, platform, }: { indicator: string; platform: string; }) => { let indicatorsWhichNeedCurrencySymbol = ["Volume", "Interest", "Liquidity"]; let dollarPlatforms = ["predictit", "kalshi", "polymarket"]; if (indicatorsWhichNeedCurrencySymbol.includes(indicator)) { if (dollarPlatforms.includes(platform)) { return "$"; } else { return "£"; } } else { return ""; } }; const showFirstQualityIndicator: React.FC<{ question: QuestionFragment; showTimeStamp: boolean; }> = ({ question, showTimeStamp }) => { const lastUpdated = new Date(question.timestamp * 1000); if (!!question.qualityIndicators.numForecasts) { return (
{/*{` ${numforecasts == 1 ? "Forecast" : "Forecasts:"}`} */} Forecasts:  {Number(question.qualityIndicators.numForecasts).toFixed(0)}
); } else if (showTimeStamp) { return ( {`Last updated: ${ lastUpdated ? lastUpdated.toISOString().slice(0, 10) : "unknown" }`} ); } else { return null; } }; const displayQualityIndicators: React.FC<{ question: QuestionFragment; showTimeStamp: boolean; }> = ({ question, showTimeStamp }) => { const { qualityIndicators } = question; return (
{showFirstQualityIndicator({ question, showTimeStamp, })} {Object.entries(formatQualityIndicators(question.qualityIndicators)).map( (entry, i) => { return (
${entry[0]}:  {`${getCurrencySymbolIfNeeded({ indicator: entry[0], platform: question.platform.id, })}${formatNumber(entry[1])}${getPercentageSymbolIfNeeded({ indicator: entry[0], 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; showTimeStamp: boolean; expandFooterToFullWidth: boolean; } export const QuestionFooter: React.FC = ({ question, showTimeStamp, expandFooterToFullWidth, }) => { let debuggingWithBackground = false; return (
{getstars(question.qualityIndicators.stars)}
{question.platform.label .replace("Good Judgment Open", "GJOpen") .replace(/ /g, "\u00a0")}
{displayQualityIndicators({ question, showTimeStamp, })}
); };