Skip to content

Commit

Permalink
Support uploading model runs from the web client
Browse files Browse the repository at this point in the history
  • Loading branch information
floryst committed Aug 28, 2024
1 parent 6b2b171 commit 3cb8427
Show file tree
Hide file tree
Showing 15 changed files with 617 additions and 75 deletions.
117 changes: 47 additions & 70 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ apache-airflow-client = "^2.9.0"
beautifulsoup4 = "^4.12.3"
django-allauth = {extras = ["socialaccount"], version = "^0.63.2"}
django-login-required-middleware = "^0.9.0"
django-s3-file-field = {extras = ["minio"], version = "^1.0.1"}

[tool.poetry.group.dev.dependencies]
django-stubs = "^4.2.7"
Expand Down
13 changes: 13 additions & 0 deletions rdwatch/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from rdwatch.core.models import (
ModelRun,
ModelRunUpload,
Performer,
Region,
SatelliteFetching,
Expand Down Expand Up @@ -123,3 +124,15 @@ class SiteObservationAdmin(admin.ModelAdmin):
)
list_filter = ('timestamp',)
raw_id_fields = ('siteeval', 'label', 'constellation', 'spectrum')


@admin.register(ModelRunUpload)
class ModelRunUploadAdmin(admin.ModelAdmin):
list_display = (
'id',
'title',
'performer',
'region',
'zipfile',
'task_id',
)
59 changes: 59 additions & 0 deletions rdwatch/core/migrations/0033_modelrunupload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Generated by Django 5.0.8 on 2024-08-14 21:17

import uuid

import s3_file_field.fields

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
('core', '0032_siteevaluation_point_siteobservation_point_and_more'),
]

operations = [
migrations.CreateModel(
name='ModelRunUpload',
fields=[
(
'id',
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
('title', models.CharField(max_length=1000)),
(
'private',
models.BooleanField(
default=False,
help_text='Whether this model run should be private',
),
),
(
'region',
models.CharField(
blank=True,
help_text='Override for the region this model run belongs to',
max_length=1000,
),
),
(
'performer',
models.CharField(
blank=True,
help_text='Override for the team that produced this evaluation',
max_length=1000,
),
),
('zipfile', s3_file_field.fields.S3FileField()),
(
'task_id',
models.CharField(help_text='celery task ID', max_length=128),
),
],
),
]
2 changes: 2 additions & 0 deletions rdwatch/core/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from . import lookups
from .annotation_exports import AnnotationExport
from .model_run import ModelRun
from .model_run_upload import ModelRunUpload
from .performer import Performer
from .region import Region
from .satellite_fetching import SatelliteFetching
Expand All @@ -12,6 +13,7 @@
'AnnotationExport',
'lookups',
'ModelRun',
'ModelRunUpload',
'Performer',
'Region',
'SiteEvaluation',
Expand Down
38 changes: 38 additions & 0 deletions rdwatch/core/models/model_run_upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from uuid import uuid4

from s3_file_field import S3FileField

from django.db import models
from django.db.models.signals import pre_delete
from django.dispatch import receiver


class ModelRunUpload(models.Model):
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)

title = models.CharField(max_length=1000)
private = models.BooleanField(
default=False, help_text='Whether this model run should be private'
)
region = models.CharField(
max_length=1000,
blank=True,
help_text='Override for the region this model run belongs to',
)
performer = models.CharField(
max_length=1000,
blank=True,
help_text='Shortcode override for the team that produced this evaluation',
)
zipfile = S3FileField()

task_id = models.CharField(max_length=256, help_text='Celery task ID')

def __str__(self) -> str:
return f'<ModelRunUpload {self.id}>'


@receiver(pre_delete, sender=ModelRunUpload)
def delete_zipfile(sender, instance, **kwargs):
if instance.zipfile:
instance.zipfile.delete(save=False)
Loading

0 comments on commit 3cb8427

Please sign in to comment.