mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
feat: Wildlife Sightings layer from iNaturalist and Acartia
Recent community wildlife observations, as a new Wildlife group in the layer panel. - Server: keyless iNaturalist proxy (v2 observations with only the projected fields; undocumented v1 UTFGrid density tiles, decoded on the server) sharing one paced queue (burst 4, ~1/s, 60/min, 8,000/day budget, up to four in flight), in-memory caches and upstream-only cooldowns; Acartia Salish Sea marine-mammal feed rounded to 0.01 degrees with comments dropped. - Layer: grid counts drawn as a soft view-ranked density glow; real sampled sightings as taxon badges at their true positions with ambient photo thumbnails and labels; obscured records stay privacy cells; a clicked sighting stays pinned through camera moves and refreshes. - Anchored photo card per selection with the single iNaturalist link; attribution in the layer row and the Data attribution popover. - Filters (CONFIRMED, taxa presets) round-trip in share links with token 9. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
edd6212793
commit
14f88b3e08
120 files changed
+21260
-285
No files matched your search
@@ -1,21 +1,26 @@
|
||||
/** Bounded per-key and aggregate request admission. */
|
||||
const RATE_LIMITER_MAX_KEYS = 2000;
|
||||
|
||||
export function makeRateLimiter({ windowMs, max, globalMax }) {
|
||||
export function makeRateLimiter({
|
||||
windowMs,
|
||||
max,
|
||||
globalMax,
|
||||
now = () => Date.now(),
|
||||
}) {
|
||||
const hits = new Map(); // key -> number[] (timestamps within window)
|
||||
let globalTimes = []; // all hits in window, for the global backstop
|
||||
return function allow(key) {
|
||||
const now = Date.now();
|
||||
globalTimes = globalTimes.filter((t) => now - t < windowMs);
|
||||
const at = now();
|
||||
globalTimes = globalTimes.filter((t) => at - t < windowMs);
|
||||
if (globalMax && globalTimes.length >= globalMax) return false; // global backstop
|
||||
const recent = (hits.get(key) || []).filter((t) => now - t < windowMs);
|
||||
const recent = (hits.get(key) || []).filter((t) => at - t < windowMs);
|
||||
if (recent.length >= max) {
|
||||
hits.set(key, recent);
|
||||
return false;
|
||||
}
|
||||
recent.push(now);
|
||||
recent.push(at);
|
||||
hits.set(key, recent);
|
||||
globalTimes.push(now);
|
||||
globalTimes.push(at);
|
||||
// Hard key cap so a key-rotating caller can't grow the map without bound.
|
||||
if (hits.size > RATE_LIMITER_MAX_KEYS) {
|
||||
const oldest = hits.keys().next().value;
|
||||
@@ -23,7 +28,7 @@ export function makeRateLimiter({ windowMs, max, globalMax }) {
|
||||
}
|
||||
if (hits.size > 256) {
|
||||
for (const [k, v] of hits) {
|
||||
if (!v.length || now - v[v.length - 1] > windowMs) hits.delete(k);
|
||||
if (!v.length || at - v[v.length - 1] > windowMs) hits.delete(k);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { makeRateLimiter } from './rateLimit.js';
|
||||
|
||||
test('injected time drives per-client and global rolling limits', () => {
|
||||
let at = 1000;
|
||||
const allow = makeRateLimiter({
|
||||
windowMs: 60_000,
|
||||
max: 2,
|
||||
globalMax: 3,
|
||||
now: () => at,
|
||||
});
|
||||
assert.equal(allow('a'), true);
|
||||
assert.equal(allow('a'), true);
|
||||
assert.equal(allow('a'), false);
|
||||
assert.equal(allow('b'), true);
|
||||
assert.equal(allow('c'), false);
|
||||
at += 59_999;
|
||||
assert.equal(allow('a'), false);
|
||||
at += 1;
|
||||
assert.equal(allow('a'), true);
|
||||
assert.equal(allow('c'), true);
|
||||
});
|
||||
@@ -4,6 +4,7 @@ import { createWfigsPerimeterSource } from '../layers/perimeters/source.js';
|
||||
import { createDroneAirspaceSource } from '../layers/droneAirspace/source.js';
|
||||
import { createBundledCableSource } from '../layers/submarineCables/bundledSource.js';
|
||||
import { createAdsbGnssSource } from '../layers/gnss/source.js';
|
||||
import { createWildlifeSightingsSource } from '../layers/wildlifeSightings/source.js';
|
||||
|
||||
/** Construct the existing reference feeds independently of application setup. */
|
||||
export function createReferenceSources() {
|
||||
@@ -12,6 +13,7 @@ export function createReferenceSources() {
|
||||
'air-quality': createEcccAirQualitySource(),
|
||||
'fire-perimeters': createWfigsPerimeterSource(),
|
||||
'drone-airspace': createDroneAirspaceSource(),
|
||||
'wildlife-sightings': createWildlifeSightingsSource(),
|
||||
cables: createBundledCableSource(),
|
||||
'gnss-integrity': createAdsbGnssSource(),
|
||||
};
|
||||
|
||||
@@ -17,6 +17,7 @@ test('reference factories retain compatibility without starting acquisition or s
|
||||
'air-quality',
|
||||
'fire-perimeters',
|
||||
'drone-airspace',
|
||||
'wildlife-sightings',
|
||||
'cables',
|
||||
'gnss-integrity',
|
||||
]);
|
||||
@@ -24,12 +25,14 @@ test('reference factories retain compatibility without starting acquisition or s
|
||||
assert.notEqual(first['air-quality'], second['air-quality']);
|
||||
assert.notEqual(first['fire-perimeters'], second['fire-perimeters']);
|
||||
assert.notEqual(first['drone-airspace'], second['drone-airspace']);
|
||||
assert.notEqual(first['wildlife-sightings'], second['wildlife-sightings']);
|
||||
assert.notEqual(first.cables, second.cables);
|
||||
assert.notEqual(first['gnss-integrity'], second['gnss-integrity']);
|
||||
assert.equal(typeof first.earthquakes.getSnapshot, 'function');
|
||||
assert.equal(typeof first['air-quality'].getSnapshot, 'function');
|
||||
assert.equal(typeof first['fire-perimeters'].getSnapshot, 'function');
|
||||
assert.equal(typeof first['drone-airspace'].getSnapshot, 'function');
|
||||
assert.equal(typeof first['wildlife-sightings'].getSnapshot, 'function');
|
||||
assert.equal(typeof first.cables.fetch, 'function');
|
||||
assert.equal(typeof first['gnss-integrity'].getSnapshot, 'function');
|
||||
assert.equal(requests, 0);
|
||||
|
||||
Reference in new issue
Block a user