from dataclasses import dataclass def fields(raw_class): from dataclasses import fields as dataclass_fields from dataclasses import is_dataclass if is_dataclass(raw_class): df = dataclass_fields(raw_class) if df: return [getattr(raw_class, field.name) for field in df] return [v for k, v in raw_class.__dict__.items() if k[:2] != "__" and k[-2:] != "__" and not callable(v)] @dataclass class ColumnContent: name: str type: str displayed_by_default: bool hidden: bool = False never_hidden: bool = False @dataclass(frozen=True) class TeamColumn: team_name = ColumnContent("Team Name", "str", True, never_hidden=True) best_f1 = ColumnContent("Best F1 Score ⬆️", "number", True) best_accuracy = ColumnContent("Best Accuracy ⬆️", "number", True) best_precision = ColumnContent("Best Precision ⬆️", "number", True) best_recall = ColumnContent("Best Recall ⬆️", "number", True) best_tp = ColumnContent("Best TP ⬆️", "number", True) best_fp = ColumnContent("Best FP ⬇️", "number", True) best_fn = ColumnContent("Best FN ⬇️", "number", True) best_tn = ColumnContent("Best TN ⬆️", "number", True) best_submission_date = ColumnContent("Submission Date", "str", True) @dataclass(frozen=True) class SubmissionQueueColumn: team_name = ColumnContent("Team Name", "str", True) submission_date = ColumnContent("Submission Date", "str", True) f1 = ColumnContent("F1 Score ⬆️", "number", True) accuracy = ColumnContent("Accuracy ⬆️", "number", True) precision = ColumnContent("Precision ⬆️", "number", True) recall = ColumnContent("Recall ⬆️", "number", True) tp = ColumnContent("TP ⬆️", "number", True) fp = ColumnContent("FP ⬇️", "number", True) fn = ColumnContent("FN ⬇️", "number", True) tn = ColumnContent("TN ⬆️", "number", True) status = ColumnContent("Status", "str", True) COLS = [c.name for c in fields(TeamColumn) if hasattr(c, "hidden") and not c.hidden] SUBMISSION_COLS = [c.name for c in fields(SubmissionQueueColumn) if hasattr(c, "name")] SUBMISSION_TYPES = [c.type for c in fields(SubmissionQueueColumn) if hasattr(c, "type")]