Skip to content

Commit

Permalink
🔨 incorporate PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Oct 24, 2024
1 parent b22a10f commit 7220fe7
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Grapher } from "@ourworldindata/grapher"
import { OwidColumnDef } from "@ourworldindata/types"
import { StatusError } from "itty-router"
import { createZip } from "littlezipper"
import { createZip, File } from "littlezipper"
import { assembleMetadata, getColumnsForMetadata } from "./metadataTools.js"
import { Env } from "./env.js"
import { GrapherIdentifier, initGrapher } from "./grapherTools.js"
import { TWITTER_OPTIONS } from "./imageOptions.js"
import { constructReadme } from "./readmeTools"
import { constructReadme } from "./readmeTools.js"

export async function fetchMetadataForGrapher(
identifier: GrapherIdentifier,
Expand Down
1 change: 1 addition & 0 deletions functions/_common/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export const extensions = {
readme: ".readme.md",
zip: ".zip",
}
export type Etag = string
3 changes: 0 additions & 3 deletions functions/_common/grapherRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { svg2png, initialize as initializeSvg2Png } from "svg2png-wasm"
import { TimeLogger } from "./timeLogger"
import { png } from "itty-router"
import { File } from "littlezipper"

import svg2png_wasm from "../../node_modules/svg2png-wasm/svg2png_wasm_bg.wasm"

Expand All @@ -19,8 +18,6 @@ declare global {
var window: any
}

export type Etag = string

export const grapherBaseUrl = "https://ourworldindata.org/grapher"

// Lots of defaults; these are mostly the same as they are in owid-grapher.
Expand Down
57 changes: 23 additions & 34 deletions functions/_common/metadataTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ import {
getCitationLong,
} from "@ourworldindata/utils"

type MetadataColumn = {
titleShort: string
titleLong: string
descriptionShort: string
descriptionKey: string[]
descriptionProcessing: string
shortUnit: string
unit: string
timespan: string
tolerance: number
type: string
conversionFactor: number
owidVariableId: number
shortName: string
lastUpdated: string
nextUpdate: string
citationShort: string
citationLong: string
fullMetadata: string
}

export const getColumnsForMetadata = (grapher: Grapher) => {
const columnsToIgnore = new Set(
[
Expand Down Expand Up @@ -40,43 +61,12 @@ export function assembleMetadata(

const metadataCols = getColumnsForMetadata(grapher)

const columns: [
string,
{
title: string
titleProducer: string
titleVariant: string
descriptionShort: string
descriptionFromProducer: string
descriptionKey: string[]
descriptionProcessing: string
shortUnit: string
unit: string
timespan: string
tolerance: number
type: string
conversionFactor: number
owidVariableId: number
catalogPath: string
sources: Partial<
Pick<
OwidOrigin,
| "attribution"
| "attributionShort"
| "description"
| "urlDownload"
| "urlMain"
>
>[]
shortName: string
},
][] = metadataCols.map((col) => {
const columns: [string, MetadataColumn][] = metadataCols.map((col) => {
console.log("mapping col", col.name)
const {
descriptionShort,
descriptionKey,
descriptionProcessing,
additionalInfo,
shortUnit,
unit,
timespan,
Expand Down Expand Up @@ -177,13 +167,12 @@ export function assembleMetadata(
conversionFactor: col.display?.conversionFactor,
owidVariableId,
shortName,
additionalInfo,
lastUpdated,
nextUpdate,
citationShort,
citationLong,
fullMetadata: `https://api.ourworldindata.org/v1/indicators/${owidVariableId}.metadata.json`,
},
} satisfies MetadataColumn,
]
})
const dateDownloaded = new Date()
Expand Down
4 changes: 2 additions & 2 deletions functions/_common/reusableHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Env } from "./env.js"
import { Etag, fetchAndRenderGrapher } from "./grapherRenderer.js"
import { Env, Etag } from "./env.js"
import { fetchAndRenderGrapher } from "./grapherRenderer.js"
import { GrapherIdentifier } from "./grapherTools.js"

export async function handleThumbnailRequest(
Expand Down
5 changes: 2 additions & 3 deletions functions/grapher/[slug].ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Env, extensions } from "../_common/env.js"
import { Etag } from "../_common/grapherRenderer.js"
import { Env, extensions, Etag } from "../_common/env.js"
import {
fetchCsvForGrapher,
fetchMetadataForGrapher,
fetchReadmeForGrapher,
fetchZipForGrapher,
} from "../_common/fetchMetadataForGrapher.js"
} from "../_common/downloadFunctions.js"
import { handleThumbnailRequest } from "../_common/reusableHandlers.js"
import {
handlePageNotFound,
Expand Down
3 changes: 1 addition & 2 deletions functions/grapher/by-uuid/[uuid].ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Env } from "../../_common/env.js"
import { extensions } from "../../_common/env.js"
import { Env, extensions } from "../../_common/env.js"
import { fetchGrapherConfig } from "../../_common/grapherTools.js"
import { IRequestStrict, Router, error, StatusError } from "itty-router"
import { handleThumbnailRequest } from "../../_common/reusableHandlers.js"
Expand Down

0 comments on commit 7220fe7

Please sign in to comment.