Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bug in thumnail generation #1155

Merged
merged 4 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions backend/coreAdmin/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@
"schedule": crontab(minute=0, hour="*/3"),
# 'schedule': 30.0
},
"prediction-map-every-30-minutes": {
"task": "tno.tasks.create_thumbnail_maps",
# a job is scheduled to run for every first minute of every hour
# "schedule": crontab(hour="*", minute=1),
"schedule": crontab(minute="*/30"),
},
# "prediction-map-every-30-minutes": {
# "task": "tno.tasks.create_thumbnail_maps",
# # a job is scheduled to run for every first minute of every hour
# # "schedule": crontab(hour="*", minute=1),
# "schedule": crontab(minute="*/30"),
# },
# Executes every Monday morning at 2:00 a.m.
"update_asteroid_table-every-monday": {
"task": "tno.tasks.update_asteroid_table",
"schedule": crontab(hour=2, minute=0, day_of_week=1),
},
# "update_asteroid_table-every-monday": {
# "task": "tno.tasks.update_asteroid_table",
# "schedule": crontab(hour=2, minute=0, day_of_week=1),
# },
# Executes every Day at 5:00 a.m.
"predict_job_for_updated_asteroids": {
"task": "tno.tasks.predict_jobs_by_updated_asteroids",
"schedule": crontab(hour=5, minute=0),
},
# "predict_job_for_updated_asteroids": {
# "task": "tno.tasks.predict_jobs_by_updated_asteroids",
# "schedule": crontab(hour=5, minute=0),
# },
# # Executes every 10th and 25th day of every month.
# "predict_job_for_upper_end_update": {
# "task": "tno.tasks.predict_jobs_for_upper_end_update",
Expand Down
3 changes: 2 additions & 1 deletion backend/tno/management/commands/create_thumbnail_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def handle(self, *args, **options):

start_date = options.get("start")
end_date = options.get("end")
if end_date:
end_date = end_date + " 23:59:59.999"
limit = options.get("limit", 1000)

to_run = upcoming_events_to_create_maps(start_date, end_date, limit)
self.stdout.write(f"Tasks to be executed in this block: [{len(to_run)}].")

Expand Down
35 changes: 26 additions & 9 deletions backend/tno/prediction_map.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import os
from datetime import datetime, time, timezone
from datetime import datetime, timedelta, timezone
from itertools import groupby
from operator import itemgetter
from pathlib import Path
Expand Down Expand Up @@ -113,7 +113,6 @@ def upcoming_events_to_create_maps(
date_start: Optional[str] = None,
date_end: Optional[str] = None,
limit: Optional[int] = None,
magnitude_limit: Optional[int] = 15,
) -> list:
logger = logging.getLogger("predict_maps")
logger.info(f"Looking for upcoming events")
Expand All @@ -140,25 +139,43 @@ def upcoming_events_to_create_maps(

if date_start == None:
date_start = datetime.now(timezone.utc) # Corrected UTC handling
if date_end == None:
date_end = date_start + timedelta(days=1)

if isinstance(date_start, str):
date_start = datetime.fromisoformat(date_start).astimezone(tz=timezone.utc)

next_events = Occultation.objects.filter(date_time__gte=date_start)

if isinstance(date_end, str):
date_end = datetime.fromisoformat(date_end).astimezone(tz=timezone.utc)
next_events = next_events.filter(date_time__lte=date_end)

next_events = next_events.order_by("g_star")
next_events = (
Occultation.objects.filter(date_time__range=(date_start, date_end))
.order_by("g_star")
.only(
"name",
"diameter",
"ra_star_candidate",
"dec_star_candidate",
"date_time",
"closest_approach",
"position_angle",
"velocity",
"delta",
"g_star",
"long",
"closest_approach_uncertainty",
)
)

logger.info(f"Next events count: {next_events.count()}")
logger.info(f"Query: {next_events.query}")
number_of_events = next_events.count()
logger.info(f"Next events count: {number_of_events}")
block_size = min(block_size, number_of_events)
# logger.info(f"Query: {next_events.query}")

# lets avoid bring all data
reached_block_size = False
i = 0
while not reached_block_size:
while not reached_block_size and (i * block_size) < number_of_events:

event_data = next_events[i * block_size : (i + 1) * block_size]

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 @@ -28,7 +28,7 @@ export function PredictionEventsProvider({ children }) {
maginitudeDropMin: undefined,
diameterMin: undefined,
diameterMax: undefined,
closestApproachUncertainty: 100,
closestApproachUncertainty: 500,
eventDurationMin: undefined,
geo: false,
latitude: undefined,
Expand Down
Loading