Browse Source

roi: last updated

raylu 20 hours ago
parent
commit
4c24ef6201
2 changed files with 12 additions and 5 deletions
  1. 10 4
      ts/roi.ts
  2. 2 1
      www/roi.html

+ 10 - 4
ts/roi.ts

@@ -1,8 +1,10 @@
 import {setupPopover} from './popover';
 
-const profits: Promise<Profit[]> = (async function () {
-	const response = await fetch('roi.json');
-	return await response.json();
+const roi: Promise<{lastModified: Date, profits: Profit[]}> = (async function () {
+	const response = await fetch('https://prun.raylu.net/roi.json');
+	const lastModified = new Date(response.headers.get('last-modified')!);
+	const profits = await response.json();
+	return {lastModified, profits};
 })();
 
 const lowVolume = document.querySelector('#low-volume') as HTMLInputElement;
@@ -13,7 +15,9 @@ async function render() {
 	const formatWhole = new Intl.NumberFormat(undefined, {maximumFractionDigits: 0}).format;
 	const tbody = document.querySelector('tbody')!;
 	tbody.innerHTML = '';
-	for (const p of await profits) {
+
+	const {lastModified, profits} = await roi;
+	for (const p of profits) {
 		const volumeRatio = p.output_per_day / p.average_traded_7d;
 		if (!lowVolume.checked && volumeRatio > 0.05) {
 			continue;
@@ -38,6 +42,8 @@ async function render() {
 		output.dataset.tooltip = p.recipe;
 		tbody.appendChild(tr);
 	}
+	document.getElementById('last-updated')!.textContent =
+		`last updated: ${lastModified.toLocaleString(undefined, {dateStyle: 'full', timeStyle: 'long', hour12: false})}`;
 }
 
 function color(n: number, low: number, high: number): string {

+ 2 - 1
www/roi.html

@@ -29,7 +29,8 @@
 		</table>
 	</main>
 	<footer>
-		prices and traded volume are IC1/HRT from refined-price's 7-day volume-weighted average
+		<time id="last-updated"></time>
+		<br>prices and traded volume are IC1/HRT from refined-price's 7-day volume-weighted average
 		<br>FRM and ORC use 112.12% fertility (promitor's)
 	</footer>
 	<div id="popover" popover="hint"></div>