Skip to content

Commit

Permalink
Improve the predictions of the Creation Date tool (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
z44d authored Aug 23, 2024
1 parent 940d15a commit f0b67d0
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 58 deletions.
1 change: 0 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"tailwind-merge": "https://esm.sh/[email protected]",
"esbuild/": "https://deno.land/x/[email protected]/",
"esbuild_deno_loader/": "https://deno.land/x/[email protected]/",
"ml-regression-polynomial": "https://esm.sh/[email protected]",
"time_ago/": "https://deno.land/x/time_ago@v1/"
},
"compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" }
Expand Down
13 changes: 8 additions & 5 deletions islands/CreationDate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { predictCreationDate } from "../lib/creation_date.ts";
const hash = getHashSignal();
const getId = () => decodeURIComponent(hash.value.slice(1));

const data = signal<Date | null>(null);
const data = signal<[string, Date] | null>(null);

export function CreationDate() {
const id = getId();
Expand Down Expand Up @@ -45,11 +45,14 @@ export function CreationDate() {
<div class="flex flex-col">
<Kv
k="Creation Date"
v={`${data.value.toDateString()} (${timeAgo(data.value)})`}
v={`${
data.value[0] == ">"
? "After "
: data.value[0] == "<"
? "Before "
: "Approximately "
}${data.value[1].toDateString()} (${timeAgo(data.value[1])})`}
/>
<div class="opacity-50 text-xs pt-0.5">
Note: This is an estimate.
</div>
</div>
)}
</div>
Expand Down
199 changes: 147 additions & 52 deletions lib/creation_date.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,153 @@
import { PolynomialRegression } from "ml-regression-polynomial";

const entries = [
[1247_000_000, 1587375629],
[1111_000_000, 1582941722],
[1097_000_000, 1582423322],
[1000_000_000, 1571097600],
[989_000_000, 1579917722],
[915_000_000, 1582596122],
[909_000_000, 1568858522],
[850_000_000, 1557878400],
[755_000_000, 1548028800],
[782_000_000, 1546300800],
[728_000_000, 1543708800],
[617_000_000, 1529625600],
[539_000_000, 1515179434],
[495_000_000, 1512846634],
[400_000_000, 1499904000],
[392_000_000, 1509926400],
[370_000_000, 1492214400],
[257_000_000, 1481767322],
[234_000_000, 1464825600],
[200_000_000, 1451606400],
[150_000_000, 1434326400],
[100_000_000, 1429125034],
[55_000_000, 1408129834],
[10_000_000, 1413331200],
[7_679_610, 1389744000],
[2_768_409, 1383264000],
[1_000_000, 1380326400],
[100_000, 1375729834],
[1_000, 1373051434],
[1, 1373051434],
[1000000, 1380326400], // 2013
[2768409, 1383264000],
[7679610, 1388448000],
[11538514, 1391212000], // 2014
[15835244, 1392940000],
[23646077, 1393459000],
[38015510, 1393632000],
[44634663, 1399334000],
[46145305, 1400198000],
[54845238, 1411257000],
[63263518, 1414454000],
[101260938, 1425600000], // 2015
[101323197, 1426204000],
[103151531, 1433376000],
[103258382, 1432771000],
[109393468, 1439078000],
[111220210, 1429574000],
[112594714, 1439683000],
[116812045, 1437696000],
[122600695, 1437782000],
[124872445, 1439856000],
[125828524, 1444003000],
[130029930, 1441324000],
[133909606, 1444176000],
[143445125, 1448928000],
[148670295, 1452211000], // 2016
[152079341, 1453420000],
[157242073, 1446768000],
[171295414, 1457481000],
[181783990, 1460246000],
[222021233, 1465344000],
[225034354, 1466208000],
[278941742, 1473465000],
[285253072, 1476835000],
[294851037, 1479600000],
[297621225, 1481846000],
[328594461, 1482969000],
[337808429, 1487707000], // 2017
[341546272, 1487782000],
[352940995, 1487894000],
[369669043, 1490918000],
[400169472, 1501459000],
[616816630, 1529625600], // 2018
[681896077, 1532821500],
[727572658, 1543708800],
[796147074, 1541371800],
[925078064, 1563290000], // 2019
[928636984, 1581513420], // 2020
[1054883348, 1585674420],
[1057704545, 1580393640],
[1145856008, 1586342040],
[1227964864, 1596127860],
[1382531194, 1600188120],
[1658586909, 1613148540], // 2021
[1660971491, 1613329440],
[1692464211, 1615402500],
[1719536397, 1619293500],
[1721844091, 1620224820],
[1772991138, 1617540360],
[1807942741, 1625520300],
[1893429550, 1622040000],
[1972424006, 1631669400],
[1974255900, 1634000000],
[2030606431, 1631992680],
[2041327411, 1631989620],
[2078711279, 1634321820],
[2104178931, 1638353220],
[2120496865, 1636714020],
[2123596685, 1636503180],
[2138472342, 1637590800],
[3318845111, 1618028800],
[4317845111, 1620028800],
[5162494923, 1652449800], // 2022
[5186883095, 1648764360],
[5304951856, 1656718440],
[5317829834, 1653152820],
[5318092331, 1652024220],
[5336336790, 1646368100],
[5362593868, 1652024520],
[5387234031, 1662137700],
[5396587273, 1648014800],
[5409444610, 1659025020],
[5416026704, 1660925460],
[5465223076, 1661710860],
[5480654757, 1660926300],
[5499934702, 1662130740],
[5513192189, 1659626400],
[5522237606, 1654167240],
[5537251684, 1664269800],
[5559167331, 1656718560],
[5568348673, 1654642200],
[5591759222, 1659025500],
[5608562550, 1664012820],
[5614111200, 1661780160],
[5666819340, 1664112240],
[5684254605, 1662134040],
[5684689868, 1661304720],
[5707112959, 1663803300],
[5756095415, 1660925940],
[5772670706, 1661539140],
[5778063231, 1667477640],
[5802242180, 1671821040],
[5853442730, 1674866100], // 2023
[5859878513, 1673117760],
[5885964106, 1671081840],
[5982648124, 1686941700],
[6020888206, 1675534800],
[6032606998, 1686998640],
[6057123350, 1676198350],
[6058560984, 1686907980],
[6101607245, 1686830760],
[6108011341, 1681032060],
[6132325730, 1692033840],
[6182056052, 1687870740],
[6279839148, 1688399160],
[6306077724, 1692442920],
[6321562426, 1688486760],
[6364973680, 1696349340],
[6386727079, 1691696880],
[6429580803, 1692082680],
[6527226055, 1690289160],
[6813121418, 1698489600],
[6865576492, 1699052400],
[6925870357, 1701192327], // 2024
] as [number, number][];

const x = entries.map((v) => v[0]);
const y = entries.map((v) => v[1]);
const regression = new PolynomialRegression(x, y, 5);
entries.sort((a, b) => a[0] - b[0]);

export function predictCreationDate(id: number) {
const r = regression.predict(id);
if (r <= 0) return now();
const d = new Date(r * 1_000);
if (isNaN(d.getHours())) return now();
if (d.getFullYear() < 2013) return now();
if (d.getFullYear() == 2013 && id >= 1_000_000_000) return now();
return d;
}
function now() {
const d = new Date();
d.setHours(0);
d.setMinutes(0);
d.setSeconds(0);
d.setMilliseconds(0);
return d;
function parseRegistrationTime(
prefix: string,
reg_time: number,
): [string, Date] {
return [prefix, new Date(reg_time * 1000)];
}

console.log(predictCreationDate(1739206386))
export function predictCreationDate(id: number) {
for (let i = 1; i < entries.length; i++) {
if (id >= entries[i - 1][0] && id <= entries[i][0]) {
const t = (id - entries[i - 1][0]) / (entries[i][0] - entries[i - 1][0]);
const reg_time = Math.floor(
entries[i - 1][1] + t * (entries[i][1] - entries[i - 1][1]),
);
return parseRegistrationTime("~", reg_time);
}
}

if (id <= 1000000) {
return parseRegistrationTime("<", 1380326400);
} else {
return parseRegistrationTime(">", 1701192327);
}
}

0 comments on commit f0b67d0

Please sign in to comment.