mirror of
https://codeberg.org/vlw/vlw.se.git
synced 2025-09-13 21:13:40 +02:00
151 lines
No EOL
5.2 KiB
PHP
151 lines
No EOL
5.2 KiB
PHP
<?php
|
|
|
|
use Reflect\Response;
|
|
|
|
use VLW\Client\API;
|
|
use VLW\API\Endpoints;
|
|
|
|
use VLW\API\Databases\VLWdb\Models\Work\WorkModel;
|
|
|
|
require_once VV::root("src/client/API.php");
|
|
require_once VV::root("api/src/Endpoints.php");
|
|
|
|
function to_plural(int $value): string {
|
|
return $value !== 1 ? "s" : "";
|
|
}
|
|
|
|
$time = new class extends DateTimeImmutable {
|
|
public function __construct() {
|
|
parent::__construct("now", new DateTimeZone($_ENV["time"]["date_time_zone"]));
|
|
}
|
|
|
|
public function hours(): int {
|
|
return (int) $this->format("G");
|
|
}
|
|
|
|
public function minutes(): int {
|
|
return (int) $this->format("i");
|
|
}
|
|
|
|
public function since_midnight_str(): string {
|
|
$hours = $this->hours();
|
|
$minutes = $this->minutes();
|
|
|
|
// Show minutes if we're not into the first hour yet
|
|
if ($hours < 1) {
|
|
return $minutes . " minute" . to_plural($minutes);
|
|
}
|
|
|
|
// Round up to the nearest hour
|
|
return ($minutes < 45 ? $hours : $hours + 1) . " hour" . to_plural($hours);
|
|
}
|
|
};
|
|
|
|
$coffee = new class extends API {
|
|
const THRESHOLDS = [
|
|
[-10, "a lot less than"],
|
|
[-5, "a bit less than"],
|
|
[0, "average"],
|
|
[5, "a bit more than"],
|
|
[10, "a lot more than"]
|
|
];
|
|
|
|
private readonly int $now;
|
|
private readonly Response $resp;
|
|
|
|
public function __construct() {
|
|
parent::__construct();
|
|
|
|
$this->now = time();
|
|
$this->resp = $this->call(Endpoints::PLAYGROUND_COFFEE->value)->get();
|
|
}
|
|
|
|
private function get_until_timestamp(int $offset = 0): array {
|
|
return array_filter($this->resp->json(), fn(int $timestamp): int => $timestamp > $offset);
|
|
}
|
|
|
|
private function get_average_month(): int {
|
|
$days = [0];
|
|
|
|
foreach ($this->get_until_timestamp(2592000) as $timestamp) {
|
|
// Append new value for next 24 hours
|
|
if ($timestamp % 86400 === 0) {
|
|
$days[] = 0;
|
|
}
|
|
|
|
$days[count($days) - 1]++;
|
|
}
|
|
|
|
// Count the average for each day
|
|
return array_sum($days) / count($days);
|
|
}
|
|
|
|
// Return the number of cups within the last 24 hours
|
|
public function get_today(): int {
|
|
return $this->resp->ok ? count($this->get_until_timestamp(86400)) : 0;
|
|
}
|
|
|
|
public function get_average_month_str(): string {
|
|
$diff = $this->get_today() - $this->get_average_month();
|
|
|
|
// Check diff of today against monthyl average thresholds
|
|
foreach (self::THRESHOLDS as $threshold) {
|
|
[$limit, $msg] = $threshold;
|
|
|
|
// Bail out if diff is less than threshold limit
|
|
if ($diff < $limit) {
|
|
return $msg;
|
|
}
|
|
}
|
|
|
|
// Return last entry if diff is more than last threshold limit
|
|
return self::THRESHOLDS[count(self::THRESHOLDS) - 1][1];
|
|
}
|
|
};
|
|
|
|
?>
|
|
<style><?= VV::css("public/assets/css/pages/playground/index") ?></style>
|
|
<section class="title">
|
|
|
|
<!-- I was listening to https://www.youtube.com/watch?v=DsUb4Lq6DBE when I made the dancing letters -->
|
|
<?php foreach (str_split("playground") as $idx => $char): ?>
|
|
<img src="data:image/gif;base64,<?= base64_encode(VV::embed("public/assets/media/playground/{$char}.gif")) ?>" style="animation-delay:<?= ($idx % rand(2, 4)) * 500 ?>ms">
|
|
<?php endforeach; ?>
|
|
|
|
</section>
|
|
<!--
|
|
<section class="sss">
|
|
<h1>I'm so bored.</h1>
|
|
<p>Don't like the way my website looks? These oficially very Super Secret Settings<sup><a href="https://minecraft-archive.fandom.com/wiki/Super_Secret_Settings">™</a></sup> will give you something else to look at!</p>
|
|
<button class="inline">Try it</button>
|
|
</section>
|
|
-->
|
|
<section>
|
|
<p>I set up a microblogging instance where bots endlessly talk with each other. It's as dumb or dumber than you think - the idea that is. The bots are even dumber, and dumb bots on social media was <a href="https://codeberg.org/vlw/misskey-microblogger#background">part of the reason</a> why I made this program.</p>
|
|
</section>
|
|
<section class="misskey-feed" data-endpoint="<?= $_ENV["playground"]["misskey_demo_instance"] ?>">
|
|
<h3>What-a' bots doin'?!</h3>
|
|
<p>Loading feed preview...</p>
|
|
<template>
|
|
<misskey-note>
|
|
<img class="pfp">
|
|
<a><div>
|
|
<p><strong class="username"></strong> - <span class="posted"></span></p>
|
|
<p class="text"></p>
|
|
</div></a>
|
|
</misskey-note>
|
|
</template>
|
|
</section>
|
|
<section class="actions">
|
|
<a href="https://codeberg.org/vlw/misskey-microblogger"><button class="inline">view source code</button></a>
|
|
<a href="https://misskey-microblogger.sites.vlw.se"><button class="inline solid">open website</button></a>
|
|
</section>
|
|
<section class="coffee">
|
|
<img src="data:image/gif;base64,<?= base64_encode(VV::embed("public/assets/media/playground/coffee.gif")) ?>">
|
|
<div>
|
|
<h1>What else.. I've had <?= $coffee->get_today() ?> cup<?= to_plural($coffee->get_today()) ?> of coffee today!</h1>
|
|
<p>That's <?= $coffee->get_average_month_str() ?> the daily average for me (last 30 days). Here I'm counting how many ~300ml cups of coffee I've had since midnight for my timezone <?= $_ENV["time"]["date_time_zone"] ?>, that was <?= $time->since_midnight_str() ?> ago.</p>
|
|
<p>How much coffee is enough coffee? <a href="<?= $_ENV["api"]["base_url"] . Endpoints::PLAYGROUND_COFFEE->value ?>">Click here to see my answer!</a> (NOT CLICKBAIT, RAW DATA!). Each array value is a UNIX timestamp that represent a single cup of coffee.</p>
|
|
</div>
|
|
</section>
|
|
<script type="module"><?= VV::js("public/assets/js/pages/playground/index") ?></script>
|