Skip to content

Commit

Permalink
Fixed #906 - Maps now are filtered by mag limit 16 and solar time bet…
Browse files Browse the repository at this point in the history
…ween 18:00 and 06:00
  • Loading branch information
glaubervila committed Mar 6, 2024
1 parent 76d5bf6 commit 9c04790
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
8 changes: 4 additions & 4 deletions backend/coreAdmin/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
"schedule": crontab(minute=0, hour="*/3"),
# 'schedule': 30.0
},
"prediction-map-every-hour": {
"prediction-map-every-30-minutes": {
"task": "tno.tasks.create_prediction_maps",
# a job is scheduled to run for every first minute of every hour
"schedule": crontab(hour="*", minute=1),
# 'schedule': 30.0
# "schedule": crontab(hour="*", minute=1),
"schedule": crontab(minute="*/30"),
},
# Executes every Monday morning at 2:00 a.m.
"update_asteroid_table-every-hour": {
"update_asteroid_table-every-monday": {
"task": "tno.tasks.update_asteroid_table",
"schedule": crontab(hour=2, minute=0, day_of_week=1),
},
Expand Down
20 changes: 12 additions & 8 deletions backend/tno/prediction_map.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import logging
import os
from datetime import datetime, timezone
from itertools import groupby
from operator import itemgetter
from datetime import datetime, timezone, time
from pathlib import Path
from typing import Optional, Union

from django.db.models import Q
import humanize
import numpy as np
from django.conf import settings
from sora.prediction.occmap import plot_occ_map as occmap
from tno.models import Occultation


Expand Down Expand Up @@ -95,13 +90,14 @@ def upcoming_events_to_create_maps(
date_start: Optional[str] = None,
date_end: Optional[str] = None,
limit: Optional[int] = None,
magnitude_limit: Optional[int] = 16,
) -> list:
logger = logging.getLogger("predict_maps")
logger.info(f"Looking for upcoming events")

# Checar o tamanho da pasta x tamanho limite im MB
# Recupera proximos eventos
# Dividir em blocos 100
# Dividir em blocos
# checa se já existe mapa.
# Checa se a predição é mais recente do que o arquivo mapa.
# Retorna uma lista de eventos que precisam de mapa.
Expand Down Expand Up @@ -132,6 +128,14 @@ def upcoming_events_to_create_maps(
date_end = datetime.fromisoformat(date_end).astimezone(tz=timezone.utc)
next_events.filter(date_time__lte=date_end)

# Filtro por magnitude
next_events.filter(g_star__lte=magnitude_limit)

# Filtro por Solar Time 18:00 - 06:00
after = Q(loc_t__gte=time(18, 0, 0), loc_t__lte=time(23, 59, 59))
before = Q(loc_t__gte=time(0, 0, 0), loc_t__lte=time(6, 0, 0))
next_events.filter(Q(after | before))

logger.debug(f"Next events count: {next_events.count()}")
for obj in next_events:
# Verifica se existe mapa já criado e se esta atualizado
Expand Down
2 changes: 1 addition & 1 deletion backend/tno/views/occultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def radius_filter(self, queryset, name, value):
def solar_time(self, queryset, name, value):
# Se value.start for maior que value.stop
if value.start > value.stop:
# Periodo de Meio dia até o meio meia noite e de meia noite até meio dia
# Periodo de Meio dia até meia noite e de meia noite até meio dia
# Na pratica o start é de meio dia até meio dia do proximo dia.
after = Q(loc_t__gte=value.start, loc_t__lte=time(23, 59, 59))
before = Q(loc_t__gte=time(0, 0, 0), loc_t__lte=value.stop)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/contexts/PredictionContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function PredictionEventsProvider({ children }) {
date_time_before: null,
filterType: 'name',
filterValue: undefined,
maginitudeMax: 16,
maginitudeMax: 15,
solar_time_after: dayjs().set('hour', 18).startOf('hour'),
solar_time_before: dayjs().set('hour', 6).startOf('hour'),
nightside: true,
Expand Down

0 comments on commit 9c04790

Please sign in to comment.