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

Update/minor updates #179

Draft
wants to merge 9 commits into
base: development
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions api/fixtures/wx_decoder.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,15 @@
"name": "BELIZE MANUAL HOURLY DATA",
"description": "Belize manual hourly data decoder (xls)"
}
},
{
"model": "wx.decoder",
"pk": 10,
"fields": {
"created_at": "2024-10-31T20:50:23.471Z",
"updated_at": "2024-10-31T20:50:23.471Z",
"name": "SAT_TX325",
"description": "TX325 decoder for Campbell"
}
}
]
10 changes: 10 additions & 0 deletions api/fixtures/wx_format.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,15 @@
"name": "DCP TXT",
"description": "DPC TEXT messages"
}
},
{
"model": "wx.format",
"pk": 7,
"fields": {
"created_at": "2024-10-31T20:50:23.471Z",
"updated_at": "2024-10-31T20:50:23.471Z",
"name": "SAT_TX325",
"description": "TX325 format"
}
}
]
1,335 changes: 1,334 additions & 1 deletion api/fixtures/wx_variableformat.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ django-ckeditor==6.7.1
django-simple-history==3.3.0
pygeoapi
pyoscar
minio
pint==0.18
numpy==1.21.2
5 changes: 5 additions & 0 deletions api/tempestas_api/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
'task': 'wx.tasks.gen_toa5_file',
'schedule': 900
},
# aws transmission to wis2box task
'aws_transmit_wis2box': {
'task': 'wx.tasks.aws_transmit_wis2box',
'schedule': 60
},
}

app.conf.timezone = 'UTC'
Expand Down
13 changes: 13 additions & 0 deletions api/tempestas_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,16 @@

HYDROML_URL = 'http://hydroml-api:8000/en/web/api/predict/'
PGIA_REPORT_HOURS_AHEAD_TIME = 1

ENABLE_WIS2BOX_REGIONAL = str(os.getenv('ENABLE_WIS2BOX_REGIONAL'))
ENABLE_WIS2BOX_LOCAL = str(os.getenv('ENABLE_WIS2BOX_LOCAL'))

WIS2BOX_USER_REGIONAL = str(os.getenv('WIS2BOX_USER_REGIONAL'))
WIS2BOX_PASSWORD_REGIONAL = str(os.getenv('WIS2BOX_PASSWORD_REGIONAL'))
WIS2BOX_ENDPOINT_REGIONAL = str(os.getenv('WIS2BOX_ENDPOINT_REGIONAL'))

WIS2BOX_USER_LOCAL = str(os.getenv('WIS2BOX_USER_LOCAL'))
WIS2BOX_PASSWORD_LOCAL = str(os.getenv('WIS2BOX_PASSWORD_LOCAL'))
WIS2BOX_ENDPOINT_LOCAL = str(os.getenv('WIS2BOX_ENDPOINT_LOCAL'))

WIS2BOX_TOPIC_HIERARCHY = str(os.getenv('WIS2BOX_TOPIC_HIERARCHY'))
84 changes: 83 additions & 1 deletion api/wx/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from django.urls import path
from django.http import JsonResponse
from ftplib import FTP

from django.contrib import admin
from django.utils.html import format_html
from import_export.admin import ExportMixin, ImportMixin

from wx import models, forms
from wx import models, forms, tasks
from simple_history.utils import update_change_reason

@admin.register(models.AdministrativeRegion)
Expand Down Expand Up @@ -156,6 +160,47 @@ class NoaaDcpAdmin(admin.ModelAdmin):
"first_transmission_time", "transmission_window", "transmission_period", "last_datetime")
exclude = ('config_data',)

change_form_template = "admin/noaaDcp_change_form.html" # Custom template

# Custom view to handle the dcp address test
def test_dcp(self, request):
if request.method == "POST":

# Try to verify dcp address
try:
# Retrieve form data from the AJAX request
dcp_address = request.POST.get('dcp_address')
first_channel = request.POST.get('first_channel')

# ensure first channel and dcp address are entered
if not first_channel or not dcp_address:
raise Exception("Enter values for both the DCP Address and the First Channel!")

dcp_info = {
'first_channel': first_channel,
'dcp_address': dcp_address,
}

dcp_address_test_result = tasks.test_dcp_transmit(dcp_info)

# raise an exception if the test result is empty
if not dcp_address_test_result:
raise Exception("The message is empty! Please ensure values for the DCP Address and the First Channel are correct. Also ensure that the station is transmitting.")

return JsonResponse({"status": "success", "message": dcp_address_test_result})
except Exception as e:
return JsonResponse({"status": "error", "message": str(e)})

return JsonResponse({"status": "error", "message": "Invalid request method"})

# Add custom URL for the AJAX request
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path('test-dcp/', self.admin_site.admin_view(self.test_dcp), name='test-dcp'),
]
return custom_urls + urls

@admin.register(models.NoaaDcpsStation)
class NoaaDcpsStationAdmin(admin.ModelAdmin):
search_fields = ("station__name",)
Expand Down Expand Up @@ -186,6 +231,43 @@ class FTPServerAdmin(admin.ModelAdmin):
list_display = ("name", "host", "port", "username")
form = forms.FTPServerForm

change_form_template = "admin/ftpserver_change_form.html" # Custom template

# Custom view to handle the FTP connection test
def test_ftp_connection(self, request):
if request.method == "POST":
# Retrieve form data from the AJAX request
host = request.POST.get('host')
port = request.POST.get('port')
username = request.POST.get('username')
password = request.POST.get('password')

# Validate and handle empty or invalid port values
try:
port = int(port)
except ValueError:
return JsonResponse({"status": "error", "message": "Invalid port value"})

# Try to establish an FTP connection
try:
ftp = FTP()
ftp.connect(host, port, timeout=10)
ftp.login(user=username, passwd=password)
ftp.quit()
return JsonResponse({"status": "success", "message": "Connection successful!"})
except Exception as e:
return JsonResponse({"status": "error", "message": str(e)})

return JsonResponse({"status": "error", "message": "Invalid request method"})

# Add custom URL for the AJAX request
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path('test-ftp-connection/', self.admin_site.admin_view(self.test_ftp_connection), name='test-ftp-connection'),
]
return custom_urls + urls


@admin.register(models.StationFileIngestion)
class StationFileIngestionAdmin(admin.ModelAdmin):
Expand Down
23 changes: 23 additions & 0 deletions api/wx/migrations/0032_auto_20241105_2109.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.13 on 2024-11-05 21:09

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('wx', '0031_variable_synoptic_code_form'),
]

operations = [
migrations.RenameField(
model_name='station',
old_name='international_station',
new_name='international_exchange',
),
migrations.AlterField(
model_name='station',
name='is_automatic',
field=models.BooleanField(default=True),
),
]
2 changes: 1 addition & 1 deletion api/wx/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ class Station(BaseModel):
blank=True,
)

international_station = models.BooleanField(default=False)
international_exchange = models.BooleanField(default=False)

is_automatic = models.BooleanField(default=True)
is_synoptic = models.BooleanField(default=False)
Expand Down
Loading