diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 59a0a60..7460264 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,6 +37,10 @@ The fix is made in the catalog and arrives here by itself. rows, newest first. `data/questions.csv` and `data/questions.jsonl` hold every row. - Level and role are the catalog's own fields (`seniority`, `roleTitles`, `roles`). A value the catalog does not publish is left empty, never guessed. +- Platform is the catalog's `oaPlatform`: the assessment platform (HackerRank, + CodeSignal, Codility, ...) a candidate's report names. It is empty when no report + names one, and the column stays empty, rather than failing, on a catalog that does + not carry the field. ## Running it locally diff --git a/scripts/build.py b/scripts/build.py index 28c0c5f..2e70f84 100644 --- a/scripts/build.py +++ b/scripts/build.py @@ -38,11 +38,11 @@ PAGE_MAX_BYTES = 400_000 #: The columns of every CSV, in order. ``data/questions.csv`` puts COMPANY_COLUMN first. -COLUMNS = ("Title", "Format", "Difficulty", "Level", "Role", "Last Reported", "Link") +COLUMNS = ("Title", "Format", "Platform", "Difficulty", "Level", "Role", "Last Reported", "Link") COMPANY_COLUMN = "Company" #: The keys of :func:`record`, in the order of COLUMNS. -FIELDS = ("title", "format", "difficulty", "level", "role", "last_reported", "link") +FIELDS = ("title", "format", "platform", "difficulty", "level", "role", "last_reported", "link") # ── Cells ──────────────────────────────────────────────────────────────────── @@ -75,6 +75,7 @@ def record(q: Question, today: date) -> dict: return { "title": q.title, "format": FORMAT_SHORT.get(q.format, q.format), + "platform": q.platform or "", "difficulty": DIFFICULTY_SHORT.get(q.difficulty or "", q.difficulty or ""), "level": [LEVEL_SHORT[level] for level in q.levels], "role": list(role_values(q)), @@ -129,14 +130,15 @@ def build_company(name: str, rows: list[Question], today: date) -> dict[str, str f"{num(len(rows))} online assessment question{'' if len(rows) == 1 else 's'} reported at {esc(name)}, newest first. " "The same rows as data: [oa.csv](oa.csv). Back to [all companies](../../README.md).", "", - "| Title | Format | Difficulty | Level | Role | Last Reported |", - "| :-- | :-- | :-- | :-- | :-- | :-- |", + "| Title | Format | Platform | Difficulty | Level | Role | Last Reported |", + "| :-- | :-- | :-- | :-- | :-- | :-- | :-- |", ] for q in rows: r = record(q, today) cells = [ f"[{esc(r['title'])}]({r['link']})", esc(r["format"]), + esc(r["platform"]), r["difficulty"], ", ".join(r["level"]), esc(", ".join(r["role"])), @@ -182,6 +184,7 @@ def build_readme(questions: list[Question], groups: dict[str, tuple[str, list[Qu "", "- **Title**: the question title, linked to its page.", "- **Format**: Coding, SQL, OOD / LLD, System design, AI coding, or Behavioral / concept.", + "- **Platform**: the assessment platform it was given on (HackerRank, CodeSignal, Codility, ...), when a candidate's report names it. Empty when no report does.", "- **Difficulty**: Easy, Medium or Hard. Empty for formats that have no difficulty.", "- **Level**: the levels it was reported at (Intern, New grad, Mid, Senior, Staff+, Manager).", "- **Role**: the role it was reported for.", diff --git a/scripts/model.py b/scripts/model.py index 45b3a9d..35accea 100644 --- a/scripts/model.py +++ b/scripts/model.py @@ -65,6 +65,21 @@ def parse_sighting(value: str | None) -> tuple[date | None, bool]: DIFFICULTY_SHORT = {"easy": "Easy", "medium": "Medium", "hard": "Hard"} +#: Longest platform name kept; anything longer is not a display name. +PLATFORM_MAX = 40 + + +def parse_platform(value: Any) -> str | None: + """The API's ``oaPlatform``: the assessment platform a report names + (``HackerRank``, ``CodeSignal``, ...). Tolerant on purpose: the field is + newer than this repository, so a catalog that does not carry it yet (or + carries ``null``, or anything that is not a short string) reads as unknown + and the Platform column stays empty. Never guessed from the company.""" + if not isinstance(value, str): + return None + text = " ".join(value.split()) + return text if 0 < len(text) <= PLATFORM_MAX else None + @dataclass(frozen=True) class Question: @@ -79,6 +94,7 @@ class Question: levels: tuple[str, ...] roles: tuple[str, ...] role_titles: tuple[str, ...] + platform: str | None # the OA platform a report names, or None seen: date | None # the most recent report we know of seen_month_only: bool @@ -132,6 +148,7 @@ def load(snapshot: dict[str, Any]) -> Catalog: levels=tuple(level for level in LEVELS if level in (row.get("seniority") or [])), roles=tuple(row.get("roles") or []), role_titles=tuple(row.get("roleTitles") or []), + platform=parse_platform(row.get("oaPlatform")), seen=seen, seen_month_only=month_only, ) diff --git a/scripts/test_build.py b/scripts/test_build.py index b2255fd..3d03943 100644 --- a/scripts/test_build.py +++ b/scripts/test_build.py @@ -57,7 +57,8 @@ def snapshot(): return { "questions": [ # OA rows. - q("order-book", ["citadel"], seniority=["senior"], roles=["Quantitative Finance"], titles=[], reported="2026-10-01", difficulty="hard"), + q("order-book", ["citadel"], seniority=["senior"], roles=["Quantitative Finance"], titles=[], reported="2026-10-01", difficulty="hard", + oaPlatform="HackerRank"), q("dice-game", ["citadel"], seniority=["junior"], roles=["Quantitative Finance"], titles=[], reported="2026-07-02"), q("lru-cache", ["amazon", "microsoft"], seniority=["new-grad", "junior"], reported="2026-05-05", last="2026-09"), q("sql-funnel", ["amazon"], seniority=["senior"], roles=["Data & AI"], titles=["Data Scientist"], type_="sql", last="2026-08"), @@ -118,8 +119,8 @@ def test_the_flat_and_cut_layouts_are_gone(self): class CompanyFiles(unittest.TestCase): def test_csv_columns(self): rows = rows_of(render()["companies/citadel/oa.csv"]) - self.assertEqual(rows[0], ["Title", "Format", "Difficulty", "Level", "Role", "Last Reported", "Link"]) - self.assertEqual(rows[1], ["Order Book", "Coding", "Hard", "Senior", "Quantitative Finance", "2026-10", "https://trueinterview.io/questions/order-book"]) + self.assertEqual(rows[0], ["Title", "Format", "Platform", "Difficulty", "Level", "Role", "Last Reported", "Link"]) + self.assertEqual(rows[1], ["Order Book", "Coding", "HackerRank", "Hard", "Senior", "Quantitative Finance", "2026-10", "https://trueinterview.io/questions/order-book"]) def test_newest_first_in_table_and_csv(self): files = render() @@ -131,29 +132,29 @@ def test_newest_first_in_table_and_csv(self): def test_a_later_report_month_wins_over_the_first_report(self): rows = rows_of(render()["companies/amazon/oa.csv"]) - self.assertEqual(rows[1][5], "2026-09") + self.assertEqual(rows[1][6], "2026-09") def test_levels_render_in_ladder_order(self): rows = rows_of(render()["companies/amazon/oa.csv"]) - self.assertEqual(rows[1][3], "New grad; Mid") + self.assertEqual(rows[1][4], "New grad; Mid") def test_role_is_the_title_or_else_the_group_never_invented(self): files = render() - self.assertEqual(rows_of(files["companies/amazon/oa.csv"])[2][4], "Data Scientist") - self.assertEqual(rows_of(files["companies/citadel/oa.csv"])[1][4], "Quantitative Finance") + self.assertEqual(rows_of(files["companies/amazon/oa.csv"])[2][5], "Data Scientist") + self.assertEqual(rows_of(files["companies/citadel/oa.csv"])[1][5], "Quantitative Finance") snap = snapshot() snap["questions"] = [q("bare", ["acme"], roles=[], titles=[])] - self.assertEqual(rows_of(render(snap)["companies/acme/oa.csv"])[1][3:6], ["", "", ""]) + self.assertEqual(rows_of(render(snap)["companies/acme/oa.csv"])[1][4:7], ["", "", ""]) def test_missing_values_stay_empty(self): row = next(r for r in rows_of(render()["companies/amazon/oa.csv"]) if r[0] == "Tell Me Why") - self.assertEqual(row[1:4], ["Behavioral / concept", "", ""]) - self.assertIn("| Behavioral / concept | - | - |", render()["companies/amazon/README.md"]) + self.assertEqual(row[1:5], ["Behavioral / concept", "", "", ""]) + self.assertIn("| Behavioral / concept | - | - | - |", render()["companies/amazon/README.md"]) def test_future_and_undated_rows_sort_last_and_carry_no_date(self): rows = rows_of(render()["companies/stripe/oa.csv"])[1:] self.assertEqual([r[0] for r in rows], ["Rate Limiter", "Undated"]) - self.assertEqual([r[5] for r in rows], ["", ""]) + self.assertEqual([r[6] for r in rows], ["", ""]) def test_table_cells_are_escaped(self): page = render()["companies/acme-widgets/README.md"] @@ -199,7 +200,7 @@ def test_csv_is_the_company_columns_plus_company(self): rows = rows_of(render()["data/questions.csv"]) self.assertEqual(rows[0], ["Company", *build.COLUMNS]) self.assertEqual(len(rows) - 1, 10) - self.assertIn(["Amazon; Microsoft", "Lru Cache", "Coding", "Medium", "New grad; Mid", "Software Engineer", "2026-09", + self.assertIn(["Amazon; Microsoft", "Lru Cache", "Coding", "", "Medium", "New grad; Mid", "Software Engineer", "2026-09", "https://trueinterview.io/questions/lru-cache"], rows) def test_a_question_with_no_company_is_in_the_data_and_in_no_folder(self): @@ -214,6 +215,37 @@ def test_jsonl_carries_the_same_fields(self): self.assertEqual(sorted(json.loads(line)), sorted(("company", *build.FIELDS))) +class Platform(unittest.TestCase): + def test_platform_renders_in_table_csv_and_jsonl(self): + files = render() + self.assertIn("| Coding | HackerRank | Hard |", files["companies/citadel/README.md"]) + row = next(r for r in rows_of(files["data/questions.csv"]) if r[1] == "Order Book") + self.assertEqual(row[3], "HackerRank") + line = next(json.loads(x) for x in files["data/questions.jsonl"].splitlines() if "Order Book" in x) + self.assertEqual(line["platform"], "HackerRank") + + def test_a_catalog_without_the_field_still_renders_with_the_column_empty(self): + # The API ships `oaPlatform` after this repository learns to read it: the + # hourly sync must keep working on a catalog that has no such key at all. + snap = snapshot() + for row in snap["questions"]: + row.pop("oaPlatform", None) + api.check_questions(snap["questions"]) + rows = rows_of(render(snap)["companies/citadel/oa.csv"]) + self.assertEqual(rows[0][2], "Platform") + self.assertEqual({r[2] for r in rows[1:]}, {""}) + + def test_null_and_junk_values_read_as_unknown(self): + for value in (None, "", " ", 7, ["HackerRank"], "x" * 41): + self.assertIsNone(model.parse_platform(value), value) + self.assertEqual(model.parse_platform(" Code Signal "), "Code Signal") + + def test_platform_is_escaped_in_the_table(self): + snap = snapshot() + snap["questions"] = [q("weird", ["acme"], oaPlatform="Hacker|Rank")] + self.assertIn("Hacker\\|Rank", render(snap)["companies/acme/README.md"]) + + class Safety(unittest.TestCase): def test_no_body_reaches_any_file(self): for path, text in render().items():