Skip to content

Commit

Permalink
re-enable prerender, import metaculus key, access new api object
Browse files Browse the repository at this point in the history
  • Loading branch information
ideopunk committed Apr 27, 2024
1 parent fb19811 commit 37a7c7d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
3 changes: 0 additions & 3 deletions src/lib/funcs/leaf.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import * as d3 from 'd3';
import { curveStep } from 'd3';
import titleCase from './titleCase';
import { colorizer, familyNames } from './treeUtilities';

const roundLeaf = [
{ x: -2, y: 0 },
Expand Down
1 change: 0 additions & 1 deletion src/lib/funcs/treeify.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as d3 from 'd3';
import { curveStep } from 'd3';
import { catastropheLeaf, extinctionLeaf, goodLeaf } from './leaf';
import titleCase from './titleCase';
import { colorizer, familyNames } from './treeUtilities';
Expand Down
1 change: 1 addition & 0 deletions src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const prerender = true;
13 changes: 9 additions & 4 deletions src/routes/+page.server.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { METACULUS_KEY } from '$env/static/private';

async function metaculusFetch(question: number): Promise<number> {
if (process.env.NODE_ENV === 'production') {
const res = await fetch(`https://www.metaculus.com/api2/questions/${question}`);
console.log('fetching metaculus');

const res = await fetch(`https://www.metaculus.com/api2/questions/${question}`, {
headers: { Authorization: `Token ${METACULUS_KEY}` }
});
const bod = await res.json();
const avg =
bod.prediction_timeseries[bod.prediction_timeseries.length - 1].community_prediction;
return avg;

const latestAVG = bod.simplified_history.community_prediction.at(-1).raw;
return latestAVG;
} else {
return 0.3;
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
</p>
<p>
But we are not doomed. Like gardeners, we can prune the branches of our future. We can reduce
our existential risks until every path leads to survival or even flourishing.
our existential risks until every path leads to survival or flourishing.
</p>
<p>
This tree is built from the prediction platform Metaculus's <ExternalLink
Expand Down

0 comments on commit 37a7c7d

Please sign in to comment.