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

Closed #794 A table, endpoint and interfaces were created to manage t… #796

Merged
merged 1 commit into from
Jan 23, 2024
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
4 changes: 3 additions & 1 deletion backend/coreAdmin/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from rest_framework.authtoken.views import obtain_auth_token
from rest_framework.routers import DefaultRouter
from skybot.views import PositionViewSet
from tno.views import AsteroidViewSet, UserViewSet, OccultationViewSet, LeapSecondViewSet, BspPlanetaryViewSet, CatalogViewSet, PredictionJobViewSet, PredictionJobResultViewSet
from tno.views import AsteroidJobViewSet, AsteroidViewSet, UserViewSet, OccultationViewSet, LeapSecondViewSet, BspPlanetaryViewSet, CatalogViewSet, PredictionJobViewSet, PredictionJobResultViewSet

router = DefaultRouter()
router.register(r"users", UserViewSet)
Expand All @@ -59,6 +59,8 @@

router.register(r"skybot/position", PositionViewSet)


router.register(r"asteroid_jobs", AsteroidJobViewSet)
router.register(r"asteroids", AsteroidViewSet)

router.register(r"occultations", OccultationViewSet, basename="occultations")
Expand Down
14 changes: 14 additions & 0 deletions backend/tno/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib import admin

from tno.models import JohnstonArchive
from tno.models import AsteroidJob
from tno.models import Asteroid
from tno.models import BspPlanetary
from tno.models import LeapSecond
Expand All @@ -20,6 +21,19 @@ class ProfileAdmin(admin.ModelAdmin):

raw_id_fields = ("user",)

@admin.register(AsteroidJob)
class AsteroidJobAdmin(admin.ModelAdmin):
list_display = (
"id",
"status",
"submit_time",
"start",
"end",
"exec_time",
"asteroids_before",
"asteroids_after",
"error"
)


@admin.register(Asteroid)
Expand Down
29 changes: 29 additions & 0 deletions backend/tno/migrations/0049_asteroidjob.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 3.2.18 on 2024-01-23 13:52

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tno', '0048_remove_predictionjobresult_asteroid'),
]

operations = [
migrations.CreateModel(
name='AsteroidJob',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('status', models.IntegerField(choices=[(1, 'Idle'), (2, 'Running'), (3, 'Completed'), (4, 'Failed'), (5, 'Aborted'), (6, 'Warning'), (7, 'Aborting')], default=1, verbose_name='Status')),
('submit_time', models.DateTimeField(auto_now_add=True, verbose_name='Submit Time')),
('start', models.DateTimeField(blank=True, null=True, verbose_name='Start')),
('end', models.DateTimeField(blank=True, null=True, verbose_name='Finish')),
('exec_time', models.DurationField(blank=True, null=True, verbose_name='Execution Time')),
('asteroids_before', models.IntegerField(default=0, help_text='Total asteroids antes da execução', verbose_name='Asteroids Before')),
('asteroids_after', models.IntegerField(default=0, help_text='Total asteroids após a execução', verbose_name='Asteroids After')),
('path', models.CharField(blank=True, help_text='Path to the directory where the job data is located.', max_length=2048, null=True, verbose_name='Path')),
('error', models.TextField(blank=True, null=True, verbose_name='Error')),
('traceback', models.TextField(blank=True, null=True, verbose_name='Traceback')),
],
),
]
1 change: 1 addition & 0 deletions backend/tno/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .profile import Profile
from .asteroid_job import AsteroidJob
from .asteroid import Asteroid
from .occultation import Occultation
from .leadp_seconds import LeapSecond
Expand Down
70 changes: 70 additions & 0 deletions backend/tno/models/asteroid_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

from django.conf import settings
from django.db import models

class AsteroidJob (models.Model):

# Status da execução.
status = models.IntegerField(
verbose_name="Status",
default=1,
choices=(
(1, "Idle"),
(2, "Running"),
(3, "Completed"),
(4, "Failed"),
(5, "Aborted"),
(6, "Warning"),
(7, "Aborting"),
),
)

# Momento em que o Job foi submetido.
submit_time = models.DateTimeField(
verbose_name="Submit Time",
auto_now_add=True,
)

# Momento em que o Job foi criado.
start = models.DateTimeField(
verbose_name="Start", auto_now_add=False, null=True, blank=True
)

# Momento em que o Job foi finalizado.
end = models.DateTimeField(
verbose_name="Finish", auto_now_add=False, null=True, blank=True
)

# Tempo de duração do Job.
exec_time = models.DurationField(
verbose_name="Execution Time", null=True, blank=True
)

asteroids_before = models.IntegerField(
verbose_name="Asteroids Before",
help_text="Total asteroids antes da execução",
default=0,
)

asteroids_after = models.IntegerField(
verbose_name="Asteroids After",
help_text="Total asteroids após a execução",
default=0,
)

# Pasta onde estão os dados do Job.
path = models.CharField(
verbose_name="Path",
help_text="Path to the directory where the job data is located.",
max_length=2048,
null=True,
blank=True
)

error = models.TextField(verbose_name="Error", null=True, blank=True)

traceback = models.TextField(
verbose_name="Traceback", null=True, blank=True)

def __str__(self):
return str(self.id)
8 changes: 7 additions & 1 deletion backend/tno/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from rest_framework import serializers
from skybot.models.position import Position

from tno.models import (Asteroid, BspPlanetary, Catalog, JohnstonArchive,
from tno.models import (AsteroidJob, Asteroid, BspPlanetary, Catalog, JohnstonArchive,
LeapSecond, Occultation, PredictionJob,
PredictionJobResult, PredictionJobStatus, Profile)



class UserSerializer(serializers.ModelSerializer):
dashboard = serializers.SerializerMethodField()

Expand Down Expand Up @@ -73,6 +74,11 @@ class Meta:
)


class AsteroidJobSerializer(serializers.ModelSerializer):
class Meta:
model = AsteroidJob
fields = '__all__'

class AsteroidSerializer(serializers.ModelSerializer):
class Meta:
model = Asteroid
Expand Down
1 change: 1 addition & 0 deletions backend/tno/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from tno.views.user import UserViewSet
from tno.views.asteroid_job import AsteroidJobViewSet
from tno.views.asteroid import AsteroidViewSet
from tno.views.occultation import OccultationViewSet
from tno.views.johnston_archive import JohnstonArchiveViewSet
Expand Down
12 changes: 12 additions & 0 deletions backend/tno/views/asteroid_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from rest_framework import viewsets
from tno.models import AsteroidJob
from tno.serializers import AsteroidJobSerializer


class AsteroidJobViewSet(viewsets.ReadOnlyModelViewSet):

queryset = AsteroidJob.objects.select_related().all()
serializer_class = AsteroidJobSerializer
# filter_fields = ("id", "name", "number", "dynclass", "base_dynclass")
# search_fields = ("name", "number")

7 changes: 6 additions & 1 deletion frontend/src/components/Drawer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ const routes = [
{ path: '/dashboard/stats', title: 'Dashboard' },
{ path: '/dashboard/data-preparation/des/orbittrace-detail/:id', title: 'Orbit Trace Details' },
{ path: '/dashboard/data-preparation/des/orbittrace/asteroid/:id', title: 'Orbit Trace Asteroid' },
{ path: '/dashboard/asteroid_job', title: 'Asteroid Job' },
{ path: '/dashboard/asteroid_job/:id', title: 'Asteroid Job Detail' },
]

const useCurrentPath = () => {
Expand Down Expand Up @@ -199,7 +201,10 @@ export default function PersistentDrawerLeft({ children }) {
</ListItemButton>
<ListItemButton onClick={() => navigate('/')}>
<ListItemText primary='Public Page' />
</ListItemButton>
</ListItemButton>
<ListItemButton onClick={() => navigate('/dashboard/asteroid_job')}>
<ListItemText primary='Asteroid Jobs' />
</ListItemButton>
</List>
</Drawer>
<Main open={open}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Box from '@mui/material/Box';
import moment from '../../../node_modules/moment/moment'
import moment from 'moment';
function ImageCell(props) {
if (props.value == null) {
return (
Expand Down
108 changes: 108 additions & 0 deletions frontend/src/pages/AsteroidJob/AsteroidJobDetail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import Grid from '@mui/material/Grid'
import Card from '@mui/material/Card';
import Box from '@mui/material/Box';
import CardContent from '@mui/material/CardContent';
import { useParams } from 'react-router-dom'
import TextField from '@mui/material/TextField';
import { getAsteroidJobById } from '../../services/api/AsteroidJob';
import { useQuery } from 'react-query';
import Alert from '@mui/material/Alert';
import moment from 'moment';
import ColumnStatus from '../../components/Table/ColumnStatus';
function AsteroidJob() {
const { id } = useParams();

const { data, isLoading } = useQuery({
queryKey: ['asteroidJob', { id }],
queryFn: getAsteroidJobById,
keepPreviousData: false,
refetchInterval: false,
refetchOnWindowFocus: false,
refetchOnmount: false,
refetchOnReconnect: false,
staleTime: 1 * 60 * 60 * 1000,
})

console.log(data)
return (
<Grid container spacing={2}>
{data !== undefined && data.status === 4 && (
<Grid item xs={12}>
<Alert severity='error'>{data?.error}</Alert>
</Grid>
)}
<Grid item xs={12}>
<Box
component="form"
sx={{
'& > :not(style)': { m: 1, width: '25ch' },
}}
noValidate
autoComplete="off"
>
<TextField
label="ID"
value={data?.id}
InputProps={{
readOnly: true,
}}
/>
<ColumnStatus status={data?.status} />
<TextField
label="Submit Time"
value={moment(data?.submit_time).utc().format('YYYY-MM-DD HH:mm:ss')}
InputProps={{
readOnly: true,
}}
/>
<TextField
label="Start Time"
value={moment(data?.start).utc().format('YYYY-MM-DD HH:mm:ss')}
InputProps={{
readOnly: true,
}}
/>
<TextField
label="End Time"
value={moment(data?.end).utc().format('YYYY-MM-DD HH:mm:ss')}
InputProps={{
readOnly: true,
}}
/>
<TextField
label="Execution Time"
value={data?.exec_time}
InputProps={{
readOnly: true,
}}
/>
<TextField
label="Asteroids Before"
value={data?.asteroids_before}
InputProps={{
readOnly: true,
}}
/>
<TextField
label="Asteroids After"
value={data?.asteroids_after}
InputProps={{
readOnly: true,
}}
/>
<TextField
label="Traceback"
value={data?.traceback}
multiline
rows={4}
InputProps={{
readOnly: true,
}}
/>
</Box>
</Grid>
</Grid>
)
}

export default AsteroidJob
Loading