Skip to content

Commit

Permalink
Refatoração da lista de Eventos de predição e Filtros (#750)
Browse files Browse the repository at this point in the history
* A method was implemented that calculates the prediction path for occultation events. #734

* Implemented first version of user location x event visibilit in Occultation endpoint #734

* Changed Map folder limit. Added more occultation path fields.

* Added maps folder highlights

* Commands were created to perform the creation of maps and occultation paths manually.

* Fix nightside computation and addition lat max min

* Foi reescrito os componentes PredictionDataGrid e PredictionFilter. Foi removido a autenticação de algumas páginas

* Filters by date, magnitude, name, dynclass and base_dynclass Done

* Removed Material ui icons 4

* Replaced material ui card for MUI card

* Geo Filter parcialmente implementado

* Geo Filter implmentado e funcionando

* Lista de eventos de predição e filtros funcionando corretamente

* Events datagrid e filter separados como components

* finished filter and events datagrid components

* Página publica foi atualizada com os novos componentes de lista de eventos de preodição e filtro

* implement prediction highlights

* reorganization of cards, hidden aladdin

* Fixed highlihts

* Fix map highlight when asteroid name have -

* Fixed asteroid alias when asteroid have - in name

* Closes #728 - 'LIneA is supported by' and 'Footer' are together on all public pages

* Closes #737 - reorganization of cards as agreed and 'sky-map' (Aladin) has been hidden

* Fixed geo filter

* Change map size in list events

* Fixed map size in prediction list.

* Changed pagesize in geofilter

* Closes #726 - layout for displaying prediction highlights

* Added devcontainer compose file

* Change default radius

* Changed line height

* Added Hide/Show Columns toolbar

* Highlight cards formating and color

* Text updated in prediction filter

* Prediction occultation table alignment

* Occultation filter text fix

* Cards text formating

* Column CA Instant now formated in UTC

* Minor fix

* Fixed prediction occultation submit interface

---------

Co-authored-by: rcboufleur <rcboufleur@gmail.com>
Co-authored-by: Jandson Vitorino <jandson1512@gmail.com>
  • Loading branch information
3 people authored Nov 1, 2023
1 parent 1ee6ab0 commit fc6e69c
Show file tree
Hide file tree
Showing 106 changed files with 6,089 additions and 42,815 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/devcontainers/python:0-3.8
FROM mcr.microsoft.com/devcontainers/python:0-3.10

ENV PYTHONUNBUFFERED 1

Expand Down Expand Up @@ -26,6 +26,7 @@ RUN pip install --upgrade pip wheel setuptools \
&& pip --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
&& rm -rf /tmp/pip-tmp

ENV DJANGO_SETTINGS_MODULE=coreAdmin.settings
# COPY --chmod=0755 ./backend/entrypoint.sh /entrypoint.sh

# COPY --chmod=0775 ./backend/start.sh /start.sh
Expand Down
30 changes: 30 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: '3.6'
services:
# Update this to the name of the service you want to work with in your docker-compose.yml file
vscode:
# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
# array). The sample below assumes your primary file is in the root of your project.
#
build:
context: .
dockerfile: .devcontainer/Dockerfile

volumes:
# Update this to wherever you want VS Code to mount the folder of your project
- ..:/workspaces:cached
# Diretório de Logs
- ./log:/log
# Diretório de Dados
- ./archive:/archive


# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
# cap_add:
# - SYS_PTRACE
# security_opt:
# - seccomp:unconfined

# Overrides default command so things don't shut down after the process ends.
command: /bin/sh -c "while sleep 1000; do :; done"
3 changes: 3 additions & 0 deletions TrojanInformation.csv:Zone.Identifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[ZoneTransfer]
ZoneId=3
HostUrl=https://files.slack.com/files-pri/T0E00562F-F062R9XLMJS/download/trojaninformation.csv?origin_team=T0E00562F
32 changes: 31 additions & 1 deletion backend/common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,43 @@
from rest_framework.decorators import action, api_view
from rest_framework.response import Response


@api_view(["GET"])
def teste(request):
if request.method == "GET":

import pandas as pd
from tno.occviz import visibility_from_coeff
from datetime import datetime, timezone
from tno.models import Occultation

lat=-22.90278
long=-43.2075
radius=50

events = Occultation.objects.filter(date_time__date='2023-08-01', have_path_coeff=True)

rows = []
ids = []
for e in events:
is_visible, info = visibility_from_coeff(
latitude=float(lat),
longitude=float(long),
radius=float(radius),
date_time= e.date_time.isoformat(),
inputdict= e.occultation_path_coeff,
)

# print(f"Occ ID: {e.id} - {e.date_time.isoformat()} - {e.name} IS Visible: [ {is_visible} ] Info: [{info}]")
if is_visible:
rows.append(e)
ids.append(e.id)

result = {
"success": True,
"rows": len(rows),
"ids": ids
}

return Response(result)


Expand Down
7 changes: 7 additions & 0 deletions backend/coreAdmin/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@
# a job is scheduled to run for every first minute of every hour
'schedule': crontab(hour='*', minute=1),
# 'schedule': 30.0
},
'occultation-path-coeff-every-10-minutes': {
'task': 'tno.tasks.create_occultation_path_coeff',
'schedule': crontab(minute='*/10')
},



# 'add-every-30-seconds': {
# 'task': 'tno.tasks.add',
# 'schedule': 30.0,
Expand Down
15 changes: 14 additions & 1 deletion backend/coreAdmin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,15 @@
"backupCount": 5,
"filename": os.path.join(LOG_DIR, "predict_maps.log"),
"formatter": "standard",
},
},
"predict_events": {
"level": LOGGING_LEVEL,
"class": "logging.handlers.RotatingFileHandler",
"maxBytes": 1024 * 1024 * 5, # 5 MB
"backupCount": 5,
"filename": os.path.join(LOG_DIR, "predict_events.log"),
"formatter": "standard",
},
},
"loggers": {
"django": {
Expand Down Expand Up @@ -425,5 +433,10 @@
"level": LOGGING_LEVEL,
"propagate": False,
},
"predict_events": {
"handlers": ["predict_events"],
"level": LOGGING_LEVEL,
"propagate": False,
},
},
}
2 changes: 1 addition & 1 deletion backend/coreAdmin/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

router.register(r"asteroids", AsteroidViewSet)

router.register(r"occultations", OccultationViewSet)
router.register(r"occultations", OccultationViewSet, basename="occultations")

router.register(r"leap_second", LeapSecondViewSet)
router.register(r"bsp_planetary", BspPlanetaryViewSet)
Expand Down
49 changes: 49 additions & 0 deletions backend/tno/management/commands/create_occ_maps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from django.core.management.base import BaseCommand
from datetime import datetime, timezone
from tno.tasks import upcoming_events_to_create_maps, create_occ_map_task, prediction_maps_log_error
from celery import group

class Command(BaseCommand):
help = "Create Occultation Maps by Period."

def add_arguments(self, parser):
# Named (optional) arguments
parser.add_argument(
"start",
help="Start Data in format YYYY-MM-DD",
)
parser.add_argument(
"--end",
default=None,
help="End Data in format YYYY-MM-DD",
)

parser.add_argument(
"--limit",
default=1000,
type=int,
help="Maximum number of jobs to be submitted, default is 1000",
)

def handle(self, *args, **options):

start = datetime.strptime(options["start"], '%Y-%m-%d').astimezone(tz=timezone.utc)
end = datetime.strptime(options.get("end"), '%Y-%m-%d').replace(hour=23, minute=59, second=59).astimezone(tz=timezone.utc) if options.get("end", None) != None else None
limit = options['limit']

if end == None:
self.stdout.write(f"Submitting background tasks to create occultation maps for date {start}")
else:
self.stdout.write(f"Submitting background tasks to create occultation maps for period {start} to {end}")

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

# Celery tasks signature
header = [create_occ_map_task.s(**i) for i in to_run]
job = group(header)
job.link_error(prediction_maps_log_error.s())

results = job.apply_async()
self.stdout.write(f"All [{len(results)}] subtasks are submited.")
86 changes: 86 additions & 0 deletions backend/tno/management/commands/create_occ_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from django.core.management.base import BaseCommand
from datetime import datetime, timezone
from tno.tasks import calculate_occultation_path
from celery import group
from tno.models import Occultation
class Command(BaseCommand):
help = "Create Occultation Paths Coeff by Period."

def add_arguments(self, parser):
# Named (optional) arguments
parser.add_argument(
"start",
help="Start Data in format YYYY-MM-DD",
)
parser.add_argument(
"--end",
default=None,
help="End Data in format YYYY-MM-DD",
)

parser.add_argument(
"--limit",
default=1000,
type=int,
help="Maximum number of jobs to be submitted, default is 1000",
)
parser.add_argument(
"--force",
default=False,
type=bool,
help="Creates the path by overwriting previous results",
)

parser.add_argument(
"--id",
default=None,
type=int,
help="Run only for select ID",)

def handle(self, *args, **options):

if options['id'] != None:
to_run = [Occultation.objects.get(pk=options['id'])]
self.stdout.write(f"Submitting background tasks to create occultation paths for id {options['id']}")
limit = 1
else:
start = datetime.strptime(options["start"], '%Y-%m-%d').astimezone(tz=timezone.utc)
end = datetime.strptime(options.get("end"), '%Y-%m-%d').replace(hour=23, minute=59, second=59).astimezone(tz=timezone.utc) if options.get("end", None) != None else None
limit = options['limit']

if end == None:
self.stdout.write(f"Submitting background tasks to create occultation paths for date {start}")
else:
self.stdout.write(f"Submitting background tasks to create occultation paths for period {start} to {end}")

to_run = Occultation.objects.filter(
date_time__gte=start).order_by('date_time')
if end != None:
to_run.filter(
date_time__lte=end
)
if options['force'] == False:
to_run.filter(have_path_coeff=False)

self.stdout.write(f"Events to run [{len(to_run)}].")
job = group(
calculate_occultation_path.s(
occultation_id = event.id,
date_time=event.date_time.isoformat(),
ra_star_candidate=event.ra_star_candidate,
dec_star_candidate=event.dec_star_candidate,
closest_approach=event.closest_approach,
position_angle=event.position_angle,
velocity=event.velocity ,
delta_distance=event.delta,
offset_ra=event.off_ra,
offset_dec=event.off_dec,
object_diameter=event.diameter,
ring_radius=None) for event in to_run[0:limit])

# Submete as tasks aos workers
results = job.apply_async()


self.stdout.write(f"All [{len(results)}] subtasks are submited.")
self.stdout.write("For monitoring use celery*.log in log directory")
14 changes: 14 additions & 0 deletions backend/tno/management/commands/garbage_collector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.core.management.base import BaseCommand
from datetime import datetime, timezone
from tno.tasks import garbage_collector
from celery import group

class Command(BaseCommand):
help = "Run Garbage Collector."

def handle(self, *args, **options):

self.stdout.write("Running garbage collector.")
self.stdout.write("For monitoring use garbage_collector.log in log directory")
garbage_collector()
self.stdout.write("Done")
33 changes: 33 additions & 0 deletions backend/tno/migrations/0038_auto_20231005_2321.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 3.2.18 on 2023-10-05 23:21

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tno', '0037_auto_20230726_1846'),
]

operations = [
migrations.AddField(
model_name='occultation',
name='have_path_coeff',
field=models.BooleanField(blank=True, default=False, help_text='Have Path Coeff', null=True, verbose_name='Have Path Coeff'),
),
migrations.AddField(
model_name='occultation',
name='max_longitude',
field=models.FloatField(blank=True, default=None, help_text='Max Logintude Occultation Path', null=True, verbose_name='Max Logintude'),
),
migrations.AddField(
model_name='occultation',
name='min_longitude',
field=models.FloatField(blank=True, default=None, help_text='Min Logintude Occultation Path', null=True, verbose_name='Min Logintude'),
),
migrations.AddField(
model_name='occultation',
name='occultation_path_coeff',
field=models.JSONField(blank=True, default={}, help_text='Occultation Path Coeff', null=True, verbose_name='Occultation Path Coeff'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.18 on 2023-10-05 23:21

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tno', '0038_auto_20231005_2321'),
]

operations = [
migrations.AlterField(
model_name='occultation',
name='occultation_path_coeff',
field=models.JSONField(blank=True, default=dict, help_text='Occultation Path Coeff', null=True, verbose_name='Occultation Path Coeff'),
),
]
23 changes: 23 additions & 0 deletions backend/tno/migrations/0040_auto_20231016_1606.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.18 on 2023-10-16 16:06

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tno', '0039_alter_occultation_occultation_path_coeff'),
]

operations = [
migrations.AddField(
model_name='occultation',
name='max_latitude',
field=models.FloatField(blank=True, default=None, help_text='Max Latitude Occultation Path', null=True, verbose_name='Max Latitude'),
),
migrations.AddField(
model_name='occultation',
name='min_latitude',
field=models.FloatField(blank=True, default=None, help_text='Min Latitude Occultation Path', null=True, verbose_name='Min Latitude'),
),
]
Loading

0 comments on commit fc6e69c

Please sign in to comment.