-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read results from GCP directly (#13)
* Read results from GCP directly This way we don't need to mess with checking latest.json into GitHub and dealing with the headaches that come along with that approach. Also make provider names clickable. Fixes #10 * format * display options
- Loading branch information
Showing
3 changed files
with
65 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,39 @@ | ||
export async function fetchLocalJsonFile(url: string) { | ||
try { | ||
const response = await fetch(url, { cache: "no-cache" }); | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
export async function fetchLatestJsonFile(region: string, medium: string) { | ||
// Today's benchmark might not have run yet, so we'll try the previous benchmark as well. | ||
const today = new Date(); | ||
const yesterday = new Date(); | ||
yesterday.setDate(today.getDate() - 1); | ||
const p1 = fetchJsonFile(region, medium, today); | ||
const p2 = fetchJsonFile(region, medium, yesterday); | ||
const [f1, f2] = await Promise.all([p1, p2]); | ||
return f1 ?? f2; | ||
} | ||
|
||
export async function fetchJsonFile( | ||
region: string, | ||
medium: string, | ||
date: Date, | ||
) { | ||
let dateStr = date.toISOString().slice(0, 10); | ||
const url = `https://storage.googleapis.com/thefastest-data/${region}/${medium}/${dateStr}.json`; | ||
return await fetchWithPostproc(url, postproc); | ||
} | ||
|
||
const json = await response.json(); | ||
json.forEach(postproc); | ||
return json; | ||
} catch (error) { | ||
console.error("Error fetching JSON file:", error); | ||
function postproc(item: any) { | ||
if (item.model.includes("/")) { | ||
[item.provider, item.model] = item.model.split("/"); | ||
} | ||
} | ||
|
||
function postproc(obj: any) { | ||
obj.results.forEach((item: any) => { | ||
if (item.model.includes("/")) { | ||
[item.provider, item.model] = item.model.split("/"); | ||
} | ||
}); | ||
export async function fetchWithPostproc( | ||
url: string, | ||
postproc: (item: any) => void, | ||
) { | ||
const response = await fetch(url); | ||
if (!response.ok) { | ||
return null; | ||
} | ||
const json = await response.json(); | ||
json.results.forEach(postproc); | ||
return json; | ||
} |