Compare commits

...

3 Commits

Author SHA1 Message Date
LilyRose2798 9c16be8bf3 Change default variant back to density 2024-04-23 11:33:30 +10:00
LilyRose2798 9f99c6a528 Remove whitespace 2024-04-23 11:33:15 +10:00
LilyRose2798 7bc02bbd07 Fix rtt average calculations 2024-04-23 11:32:58 +10:00
2 changed files with 8 additions and 10 deletions

View File

@ -21,7 +21,7 @@ import numpy as np
ip_bytes = 4
ip_bits = ip_bytes * 8
num_ips = 1 << ip_bits
num_ips_sqrt = 1 << ip_bits // 2
num_ips_sqrt = 1 << (ip_bits >> 1)
def make_coord_range(start: int, end: int):
return decode(np.arange(start, end, dtype = np.uint32), num_dims = 2, num_bits = 16).astype(np.uint16)
@ -239,7 +239,7 @@ def make_tiles(coords_path: Path, input_path: Path, tiles_dir: Path, *,
def squish():
nonlocal density_data
nonlocal possible_overlaps
density_data = np.swapaxes(density_data.reshape(density_data.shape[0] // 2, 2, density_data.shape[1] // 2, 2), 1, 2)
density_data = np.swapaxes(density_data.reshape(density_data.shape[0] >> 1, 2, density_data.shape[1] >> 1, 2), 1, 2)
print("calculating density sum...", end = " ", flush = True)
density_data[:, :, 0, 0] += density_data[:, :, 0, 1]
density_data[:, :, 0, 0] += density_data[:, :, 1, 0]
@ -293,7 +293,7 @@ def make_tiles(coords_path: Path, input_path: Path, tiles_dir: Path, *,
def squish():
nonlocal rtt_data
print(f"sorting rtt values for median calculation...", end = " ", flush = True)
rtt_data = np.swapaxes(rtt_data.reshape(rtt_data.shape[0] // 2, 2, rtt_data.shape[1] // 2, 2), 1, 2)
rtt_data = np.swapaxes(rtt_data.reshape(rtt_data.shape[0] >> 1, 2, rtt_data.shape[1] >> 1, 2), 1, 2)
mask = np.empty((rtt_data.shape[0], rtt_data.shape[1]), dtype = np.bool_)
np.less(rtt_data[:, :, 0, 0], rtt_data[:, :, 0, 1], out = mask) # sort first row
rtt_data[mask, 0] = rtt_data[mask, 0, ::-1]
@ -310,15 +310,15 @@ def make_tiles(coords_path: Path, input_path: Path, tiles_dir: Path, *,
print("calculating median rtt values...", end = " ", flush = True)
mask2 = np.empty((rtt_data.shape[0], rtt_data.shape[1]), dtype = np.bool_) # need second mask for binary ops
np.not_equal(rtt_data[:, :, 1, 1], 0, out = mask) # four nums populated
rtt_data[mask, 0, 1] //= 2
rtt_data[mask, 1, 0] //= 2
rtt_data[mask, 0, 0] = rtt_data[mask, 0, 1]
rtt_data[mask, 0, 0] -= rtt_data[mask, 1, 0]
rtt_data[mask, 0, 0] >>= 1
rtt_data[mask, 0, 0] += rtt_data[mask, 1, 0] # take average of middle two nums
np.logical_and(np.not_equal(rtt_data[:, :, 1, 0], 0, out = mask), np.equal(rtt_data[:, :, 1, 1], 0, out = mask2), out = mask) # three nums populated
rtt_data[mask, 0, 0] = rtt_data[mask, 0, 1] # take middle of three nums
np.logical_and(np.not_equal(rtt_data[:, :, 0, 1], 0, out = mask), np.equal(rtt_data[:, :, 1, 0], 0, out = mask2), out = mask) # two nums populated
rtt_data[mask, 0, 0] //= 2
rtt_data[mask, 0, 1] //= 2
rtt_data[mask, 0, 0] -= rtt_data[mask, 0, 1]
rtt_data[mask, 0, 0] >>= 1
rtt_data[mask, 0, 0] += rtt_data[mask, 0, 1] # take average of first two nums
# everything else (1 or 0 nums populated) don't need any modifications
print("done")
@ -330,8 +330,6 @@ def make_tiles(coords_path: Path, input_path: Path, tiles_dir: Path, *,
for _ in range(skip_iters):
squish()
def write_all_colormaps():
if raws_path is not None:
create_tiles(raws_path / variant_name, rtt_data.view(np.uint8).reshape(rtt_data.shape[0], rtt_data.shape[1], 4))

View File

@ -230,7 +230,7 @@
}
const apiUrl = "https://ipapi.7circles.moe"
const defaultVariant = "rtt"
const defaultVariant = "density"
const defaultColormap = "viridis"
const tileSize = 256
const tilesDir = "assets/tiles"