Skip to content
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
10 changes: 7 additions & 3 deletions scripts/build-timeseries-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import {
getTechnologyDefinition,
UnknownTaxonomyError,
} from "../src/utils/timeseriesTaxonomy.ts";
import { jsonToCsv, sectorSegmentColumns } from "./timeseries-csv.ts";
import {
jsonToCsv,
publisherLabel,
sectorSegmentColumns,
} from "./timeseries-csv.ts";

const STRICT = process.env.TS_INDEX_STRICT === "1";
const DEBUG = process.env.TS_INDEX_DEBUG === "1";
Expand Down Expand Up @@ -363,7 +367,7 @@ async function main() {
.join(", ");
const optionalBlock = optionalParts ? ` (${optionalParts})` : "";
// Final string
const source = `${pub.publisher.short}, ${pub.year}, ${pub.title.full}${optionalBlock}`;
const source = `${publisherLabel(pub.publisher)}, ${pub.year}, ${pub.title.full}${optionalBlock}`;

// Look up definitions from centralized taxonomy.
// These WILL throw if unknown, which is what we want in strict mode.
Expand All @@ -378,7 +382,7 @@ async function main() {
: undefined;

const outRaw = {
publisher: parsed.publication.publisher.short,
publisher: publisherLabel(pub.publisher),
publicationName: parsed.publication.title.full,
publicationYear: parsed.publication.year,
pathwayName: parsed.pathwayName,
Expand Down
23 changes: 22 additions & 1 deletion scripts/timeseries-csv.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { describe, it, expect } from "vitest";
import { csvCell, jsonToCsv, sectorSegmentColumns } from "./timeseries-csv.ts";
import {
csvCell,
jsonToCsv,
publisherLabel,
sectorSegmentColumns,
} from "./timeseries-csv.ts";

describe("sectorSegmentColumns", () => {
it("lists the row's segments and their definitions in the same order", () => {
Expand Down Expand Up @@ -47,3 +52,19 @@ describe("CSV writing", () => {
expect(row).toBe('"Southeast Asia","A; B",1');
});
});

describe("publisherLabel", () => {
it("uses the short name when there is one", () => {
expect(
publisherLabel({ short: "IEA", full: "International Energy Agency" }),
).toBe("IEA");
});

it("falls back to the full name when there is no short one", () => {
// TransitionZero's files carry a full name only.
expect(publisherLabel({ full: "TransitionZero" })).toBe("TransitionZero");
expect(publisherLabel({ short: " ", full: "TransitionZero" })).toBe(
"TransitionZero",
);
});
});
14 changes: 14 additions & 0 deletions scripts/timeseries-csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ export function sectorSegmentColumns(
};
}

/**
* The publisher as the download names it: the short name, or the full name
* where the publication has none. Some publishers carry only a full name
* (TransitionZero), and reading `short` alone wrote an empty `publisher` and a
* `source` starting with "undefined". The prep repo's review workbook uses
* the same rule, so the two match.
*/
export function publisherLabel(publisher: {
short?: string | null;
full: string;
}): string {
return publisher.short?.trim() || publisher.full;
}

/**
* One CSV cell. Strings are always quoted; a list is joined first, so it can
* never spill its commas into the next columns.
Expand Down
Loading