Skip to content

Commit

Permalink
Merge pull request #228 from J-A-A-M/offset-fix
Browse files Browse the repository at this point in the history
Технічне: fix offset in kyiv_distict_mode 4
  • Loading branch information
v00g100skr authored Sep 12, 2024
2 parents 31072e4 + 99607fb commit 0fef31f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
48 changes: 46 additions & 2 deletions deploy/websocket_server/websocket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
from datetime import datetime, timezone, timedelta
from ga4mp import GtagMP

debug_level = os.environ.get("LOGGING")
debug_level = os.environ.get("LOGGING") or "DEBUG"
websocket_port = os.environ.get("WEBSOCKET_PORT") or 38440
ping_interval = int(os.environ.get("PING_INTERVAL", 60))
memcache_fetch_interval = int(os.environ.get("MEMCACHE_FETCH_INTERVAL", 1))
random_mode = os.environ.get("RANDOM_MODE", "False").lower() in ("true", "1", "t")
test_mode = os.environ.get("TEST_MODE", "False").lower() in ("true", "1", "t")
api_secret = os.environ.get("API_SECRET") or ""
measurement_id = os.environ.get("MEASUREMENT_ID") or ""
environment = os.environ.get("ENVIRONMENT") or "PROD"
Expand Down Expand Up @@ -43,6 +44,7 @@ def __init__(self):
self.clients = {}
self.trackers = {}
self.blocked_ips = []
self.test_id = None


shared_data = SharedData()
Expand Down Expand Up @@ -303,7 +305,7 @@ async def update_shared_data(shared_data, mc):
while True:
logger.debug("memcache check")
alerts_v1, alerts_v2, weather_v1, explosions_v1, bins, test_bins, alerts_full, weather_full, explosions_full = (
await get_data_from_memcached(mc)
await get_data_from_memcached(mc) if not test_mode else await get_data_from_memcached_test(shared_data)
)

try:
Expand Down Expand Up @@ -385,6 +387,48 @@ async def print_clients(shared_data, mc):
logger.error(f"Error in update_shared_data: {e}")


async def get_data_from_memcached_test(shared_data):
if not shared_data.test_id:
shared_data.test_id = 0

alerts = []
weather = []
explosion = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

for region_name, data in regions.items():
region_id = data["id"]
if region_id == shared_data.test_id:
alert = 1
temp = 30
if region_id == 0:
explosion[25] = int(datetime.now().timestamp())
else:
explosion[region_id - 1] = int(datetime.now().timestamp())
logger.debug(f"District: %s, %s" % (region_id, region_name))
else:
alert = 0
temp = 0
region_alert = [str(alert), "2024-09-05T09:47:52Z"]
alerts.append(region_alert)
weather.append(str(temp))

shared_data.test_id += 1
if shared_data.test_id > 25:
shared_data.test_id = 0

return (
"{}",
json.dumps(alerts),
json.dumps(weather),
json.dumps(explosion),
'["latest.bin"]',
'["latest_beta.bin"]',
"{}",
"{}",
"{}",
)


async def get_data_from_memcached(mc):
alerts_cached_v1 = await mc.get(b"alerts_websocket_v1")
alerts_cached_v2 = await mc.get(b"alerts_websocket_v2")
Expand Down
16 changes: 8 additions & 8 deletions firmware/src/JaamFirmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2598,15 +2598,15 @@ void mapAlarms() {
adaptLeds(settings.kyiv_district_mode, alarm_time, adapted_alarm_timers, settings.pixelcount, offset);
adaptLeds(settings.kyiv_district_mode, explosions_time, adapted_explosion_timers, settings.pixelcount, offset);
if (settings.kyiv_district_mode == 4) {
if (alarm_leds[25] == 0 and alarm_leds[7] == 0) {
adapted_alarm_leds[7] = 0;
adapted_alarm_timers[7] = max(alarm_time[25], alarm_time[7]);
if (adapted_alarm_leds[25] == 0 and adapted_alarm_leds[7 + offset] == 0) {
adapted_alarm_leds[7 + offset] = 0;
adapted_alarm_timers[7 + offset] = max(adapted_alarm_timers[25], adapted_alarm_timers[7 + offset]);
}
if (alarm_leds[25] == 1 or alarm_leds[7] == 1) {
adapted_alarm_leds[7] = 1;
adapted_alarm_timers[7] = max(alarm_time[25], alarm_time[7]);
if (adapted_alarm_leds[25] == 1 or adapted_alarm_leds[7 + offset] == 1) {
adapted_alarm_leds[7 + offset] = 1;
adapted_alarm_timers[7 + offset] = max(adapted_alarm_timers[25], adapted_alarm_timers[7 + offset]);
}
adapted_explosion_timers[7] = max(explosions_time[25], explosions_time[7]);
adapted_explosion_timers[7 + offset] = max(adapted_explosion_timers[25], adapted_explosion_timers[7 + offset]);
}
float blinkBrightness = settings.current_brightness / 100.0f;
float explosionBrightness = settings.current_brightness / 100.0f;
Expand All @@ -2629,7 +2629,7 @@ void mapWeather() {
float adapted_weather_leds[settings.pixelcount];
adaptLeds(settings.kyiv_district_mode, weather_leds, adapted_weather_leds, settings.pixelcount, offset);
if (settings.kyiv_district_mode == 4) {
adapted_weather_leds[7] = (weather_leds[25] + weather_leds[7]) / 2.0f;
adapted_weather_leds[7 + offset] = (weather_leds[25] + weather_leds[7]) / 2.0f;
}
for (uint16_t i = 0; i < settings.pixelcount; i++) {
strip[i] = fromHue(processWeather(adapted_weather_leds[i]), settings.current_brightness);
Expand Down

0 comments on commit 0fef31f

Please sign in to comment.