-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tool to get approximate account creation dates
Closes #2.
- Loading branch information
Showing
7 changed files
with
166 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export function Clock() { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="18" | ||
height="18" | ||
fill="none" | ||
stroke="currentColor" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="2" | ||
viewBox="0 0 24 24" | ||
> | ||
<circle cx="12" cy="12" r="10" /> | ||
<path d="M12 6v6l4 2" /> | ||
</svg> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { ComponentChildren } from "preact"; | ||
import { signal, useSignalEffect } from "@preact/signals"; | ||
|
||
import { getHashSignal } from "../lib/hash.ts"; | ||
import { setHash } from "../lib/hash.ts"; | ||
|
||
import { Caption } from "../components/Caption.tsx"; | ||
import { Input } from "../components/Input.tsx"; | ||
import { Label } from "../components/Label.tsx"; | ||
import { timeAgo } from "time_ago/mod.ts"; | ||
import { predictCreationDate } from "../lib/creation_date.ts"; | ||
|
||
const hash = getHashSignal(); | ||
const getId = () => decodeURIComponent(hash.value.slice(1)); | ||
|
||
const data = signal<Date | null>(null); | ||
|
||
export function CreationDate() { | ||
const id = getId(); | ||
|
||
useSignalEffect(() => { | ||
const id = Number(getId()); | ||
if (isNaN(id) || !id) { | ||
data.value = null | ||
return; | ||
} | ||
|
||
data.value = predictCreationDate(id); | ||
}); | ||
|
||
return ( | ||
<div class="w-full mx-auto max-w-lg gap-5 flex flex-col items-center text-center"> | ||
<div class={"flex flex-col gap-0.5 "}> | ||
<div class={`font-bold text-xs ${id.length ? 'opacity-1' :'opacity-0'}`}>User ID</div> | ||
<input | ||
class="select-text text-ellipsis overflow-hidden focus:outline-none text-center bg-transparent placeholder:(text-foreground opacity-[.55]) text-lg" | ||
placeholder="Enter User ID" | ||
value={id} | ||
onKeyUp={(e) => setHash("#" + e.currentTarget.value)} | ||
onKeyPress={(e) => setHash("#" + e.currentTarget.value)} | ||
/> | ||
</div> | ||
{data.value && ( | ||
<div class="flex flex-col"> | ||
<Kv | ||
k="Creation Date" | ||
v={`${data.value.toDateString()} (${timeAgo(data.value)})`} | ||
/> | ||
<div class="opacity-50 text-xs pt-0.5"> | ||
Note: This is an estimate. | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
function Kv({ k, v, c }: { k: string; v: ComponentChildren; c?: string }) { // TODO: merge with FileIdAnalyzer's | ||
return ( | ||
<div class={"flex flex-col gap-0.5 " + (c ?? "")}> | ||
<div class="font-bold text-xs">{k}</div> | ||
<div class="select-text text-ellipsis overflow-hidden text-lg">{v}</div> | ||
</div> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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], | ||
] as [number, number][]; | ||
|
||
const x = entries.map((v) => v[0]); | ||
const y = entries.map((v) => v[1]); | ||
const regression = new PolynomialRegression(x, y, 5); | ||
|
||
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(); | ||
return d; | ||
} | ||
function now() { | ||
const d = new Date(); | ||
d.setHours(0); | ||
d.setMinutes(0); | ||
d.setSeconds(0); | ||
d.setMilliseconds(0); | ||
return d; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { CreationDate } from "../islands/CreationDate.tsx"; | ||
|
||
export default () => <CreationDate />; |
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