Diversify persistent scale fixtures

This commit is contained in:
SimpleTest 2026-07-28 21:41:08 +03:00
parent 4490280e0e
commit 227c0bdc0c

View File

@ -311,33 +311,68 @@ defmodule Mix.Tasks.Wnh.ScaleFixtures do
'Scale help request ' || value, 'Scale help request ' || value,
'Persistent synthetic local scale request used to test viewport discovery and UI.', 'Persistent synthetic local scale request used to test viewport discovery and UI.',
'Synthetic data only; no real-world action is requested.', 'Synthetic data only; no real-world action is requested.',
'{"scale_fixture":true}'::jsonb, '{"scale_fixture":true,"scale_fixture_version":3}'::jsonb,
city.name || ' scale area', city.name || ' synthetic zone ' ||
CASE WHEN value % 97 = 0 THEN NULL ELSE ST_SetSRID( ((variation.category_key + variation.time_key) % 100 + 1),
CASE WHEN variation.visibility_key % 97 = 0 THEN NULL ELSE ST_SetSRID(
ST_MakePoint( ST_MakePoint(
city.longitude + (((value * 97) % 1001) - 500) / 100000.0, city.longitude +
city.latitude + (((value * 193) % 1001) - 500) / 100000.0 ((variation.longitude_key % 4001) - 2000) / 1000.0,
city.latitude +
((variation.latitude_key % 4003) - 2001) / 1000.0
), ),
4326 4326
) END, ) END,
CASE WHEN value % 10 < 8 THEN 'open' CASE WHEN variation.status_key % 10 < 8 THEN 'open'
WHEN value % 10 = 8 THEN 'completed' WHEN variation.status_key % 10 = 8 THEN 'completed'
ELSE 'cancelled' END, ELSE 'cancelled' END,
CASE value % 3 WHEN 0 THEN 'now' WHEN 1 THEN 'today' ELSE 'scheduled' END, CASE (variation.status_key / 10) % 3
CASE WHEN value % 97 = 0 THEN 'hidden' WHEN 0 THEN 'now'
WHEN value % 4 = 0 THEN 'exact_public' WHEN 1 THEN 'today'
WHEN value % 4 = 1 THEN 'exact_for_active_match' ELSE 'scheduled'
END,
CASE WHEN variation.visibility_key % 97 = 0 THEN 'hidden'
WHEN (variation.visibility_key / 97) % 4 = 0 THEN 'exact_public'
WHEN (variation.visibility_key / 97) % 4 = 1
THEN 'exact_for_active_match'
ELSE 'approximate_public' END, ELSE 'approximate_public' END,
CASE WHEN value % 97 = 0 OR value % 4 = 0 THEN NULL CASE WHEN variation.visibility_key % 97 = 0
WHEN value % 3 = 0 THEN 500 OR (variation.visibility_key / 97) % 4 = 0 THEN NULL
WHEN value % 3 = 1 THEN 1000 WHEN (variation.visibility_key / 388) % 3 = 0 THEN 500
WHEN (variation.visibility_key / 388) % 3 = 1 THEN 1000
ELSE 2000 END, ELSE 2000 END,
date_trunc('second', now()) + ((value % 30) + 1) * interval '1 day', date_trunc('second', now()) +
md5('wnh-scale-user-' || ((value % $2) + 1))::uuid, ((variation.time_key % 30) + 1) * interval '1 day',
(($3::text[])[((value - 1) % cardinality($3::text[])) + 1])::uuid, md5(
'wnh-scale-user-' ||
((variation.longitude_key * 37 + variation.latitude_key) % $2 + 1)
)::uuid,
(($3::text[])[
(variation.category_key % cardinality($3::text[])) + 1
])::uuid,
date_trunc('second', now()) - value * interval '1 second', date_trunc('second', now()) - value * interval '1 second',
date_trunc('second', now()) - value * interval '1 second' date_trunc('second', now()) - value * interval '1 second'
FROM generate_series(1, $1) AS value FROM generate_series(1, $1) AS value
CROSS JOIN LATERAL (
SELECT
((value - 1) % 20)::integer AS city_index,
md5('wnh-scale-request-v3-' || value) AS fixture_hash
) AS fixture
CROSS JOIN LATERAL (
SELECT
('x' || substr(fixture.fixture_hash, 1, 8))::bit(32)::bigint
AS longitude_key,
('x' || substr(fixture.fixture_hash, 9, 8))::bit(32)::bigint
AS latitude_key,
('x' || substr(fixture.fixture_hash, 17, 4))::bit(16)::bigint
AS status_key,
('x' || substr(fixture.fixture_hash, 21, 4))::bit(16)::bigint
AS visibility_key,
('x' || substr(fixture.fixture_hash, 25, 4))::bit(16)::bigint
AS time_key,
('x' || substr(fixture.fixture_hash, 29, 4))::bit(16)::bigint
AS category_key
) AS variation
CROSS JOIN LATERAL ( CROSS JOIN LATERAL (
SELECT * SELECT *
FROM ( FROM (
@ -363,9 +398,22 @@ defmodule Mix.Tasks.Wnh.ScaleFixtures do
(18, 'Sydney', 151.2093, -33.8688), (18, 'Sydney', 151.2093, -33.8688),
(19, 'Auckland', 174.7633, -36.8485) (19, 'Auckland', 174.7633, -36.8485)
) AS cities(index, name, longitude, latitude) ) AS cities(index, name, longitude, latitude)
WHERE cities.index = value % 20 WHERE cities.index = fixture.city_index
) AS city ) AS city
ON CONFLICT (id) DO NOTHING ON CONFLICT (id) DO UPDATE SET
structured_data = EXCLUDED.structured_data,
location_label = EXCLUDED.location_label,
location = EXCLUDED.location,
status = EXCLUDED.status,
urgency = EXCLUDED.urgency,
location_visibility = EXCLUDED.location_visibility,
location_radius_meters = EXCLUDED.location_radius_meters,
expires_at = EXCLUDED.expires_at,
requester_id = EXCLUDED.requester_id,
category_id = EXCLUDED.category_id,
updated_at = EXCLUDED.updated_at
WHERE help_requests.structured_data @> '{"scale_fixture":true}'::jsonb
AND help_requests.structured_data ->> 'scale_fixture_version' IS DISTINCT FROM '3'
""", """,
[rows, @synthetic_users, category_ids], [rows, @synthetic_users, category_ids],
timeout: :infinity, timeout: :infinity,
@ -385,27 +433,60 @@ defmodule Mix.Tasks.Wnh.ScaleFixtures do
md5('wnh-scale-activity-v1-' || value)::uuid, md5('wnh-scale-activity-v1-' || value)::uuid,
'Scale community activity ' || value, 'Scale community activity ' || value,
'Persistent synthetic local scale activity used to test viewport discovery and UI.', 'Persistent synthetic local scale activity used to test viewport discovery and UI.',
'{"scale_fixture":true}'::jsonb, '{"scale_fixture":true,"scale_fixture_version":3}'::jsonb,
city.name || ' public meeting area', city.name || ' synthetic zone ' ||
((variation.category_key + variation.time_key) % 100 + 1),
ST_SetSRID( ST_SetSRID(
ST_MakePoint( ST_MakePoint(
city.longitude + (((value * 89) % 1001) - 500) / 100000.0, city.longitude +
city.latitude + (((value * 181) % 1001) - 500) / 100000.0 ((variation.longitude_key % 4001) - 2000) / 1000.0,
city.latitude +
((variation.latitude_key % 4003) - 2001) / 1000.0
), ),
4326 4326
), ),
CASE WHEN value % 97 = 0 THEN 'hidden' ELSE 'approximate_public' END, CASE WHEN variation.visibility_key % 97 = 0
CASE WHEN value % 10 < 8 THEN 'open' THEN 'hidden'
WHEN value % 10 = 8 THEN 'completed' ELSE 'approximate_public'
END,
CASE WHEN variation.status_key % 10 < 8 THEN 'open'
WHEN variation.status_key % 10 = 8 THEN 'completed'
ELSE 'cancelled' END, ELSE 'cancelled' END,
date_trunc('second', now()) + ((value % 60) + 2) * interval '1 day', date_trunc('second', now()) +
date_trunc('second', now()) + ((value % 60) + 1) * interval '1 day', ((variation.time_key % 60) + 2) * interval '1 day',
2 + (value % 19), date_trunc('second', now()) +
md5('wnh-scale-user-' || ((value % $2) + 1))::uuid, ((variation.time_key % 60) + 1) * interval '1 day',
(($3::text[])[((value - 1) % cardinality($3::text[])) + 1])::uuid, 2 + ((variation.status_key + variation.time_key) % 19),
md5(
'wnh-scale-user-' ||
((variation.longitude_key * 37 + variation.latitude_key) % $2 + 1)
)::uuid,
(($3::text[])[
(variation.category_key % cardinality($3::text[])) + 1
])::uuid,
date_trunc('second', now()) - value * interval '1 second', date_trunc('second', now()) - value * interval '1 second',
date_trunc('second', now()) - value * interval '1 second' date_trunc('second', now()) - value * interval '1 second'
FROM generate_series(1, $1) AS value FROM generate_series(1, $1) AS value
CROSS JOIN LATERAL (
SELECT
((value - 1) % 20)::integer AS city_index,
md5('wnh-scale-activity-v3-' || value) AS fixture_hash
) AS fixture
CROSS JOIN LATERAL (
SELECT
('x' || substr(fixture.fixture_hash, 1, 8))::bit(32)::bigint
AS longitude_key,
('x' || substr(fixture.fixture_hash, 9, 8))::bit(32)::bigint
AS latitude_key,
('x' || substr(fixture.fixture_hash, 17, 4))::bit(16)::bigint
AS status_key,
('x' || substr(fixture.fixture_hash, 21, 4))::bit(16)::bigint
AS visibility_key,
('x' || substr(fixture.fixture_hash, 25, 4))::bit(16)::bigint
AS time_key,
('x' || substr(fixture.fixture_hash, 29, 4))::bit(16)::bigint
AS category_key
) AS variation
CROSS JOIN LATERAL ( CROSS JOIN LATERAL (
SELECT * SELECT *
FROM ( FROM (
@ -431,9 +512,22 @@ defmodule Mix.Tasks.Wnh.ScaleFixtures do
(18, 'Sydney', 151.2093, -33.8688), (18, 'Sydney', 151.2093, -33.8688),
(19, 'Auckland', 174.7633, -36.8485) (19, 'Auckland', 174.7633, -36.8485)
) AS cities(index, name, longitude, latitude) ) AS cities(index, name, longitude, latitude)
WHERE cities.index = value % 20 WHERE cities.index = fixture.city_index
) AS city ) AS city
ON CONFLICT (id) DO NOTHING ON CONFLICT (id) DO UPDATE SET
structured_data = EXCLUDED.structured_data,
location_label = EXCLUDED.location_label,
location = EXCLUDED.location,
location_visibility = EXCLUDED.location_visibility,
status = EXCLUDED.status,
starts_at = EXCLUDED.starts_at,
join_deadline = EXCLUDED.join_deadline,
capacity = EXCLUDED.capacity,
creator_id = EXCLUDED.creator_id,
category_id = EXCLUDED.category_id,
updated_at = EXCLUDED.updated_at
WHERE activities.structured_data @> '{"scale_fixture":true}'::jsonb
AND activities.structured_data ->> 'scale_fixture_version' IS DISTINCT FROM '3'
""", """,
[rows, @synthetic_users, category_ids], [rows, @synthetic_users, category_ids],
timeout: :infinity, timeout: :infinity,