Skip to content

Commit

Permalink
Merge pull request #253 from wmo-raf/aviation
Browse files Browse the repository at this point in the history
fix bugs aviation tool
  • Loading branch information
Grace-Amondi authored Aug 12, 2024
2 parents 05830ef + bb7f84e commit ceb8fa3
Show file tree
Hide file tree
Showing 28 changed files with 169 additions and 39 deletions.
33 changes: 21 additions & 12 deletions pages/aviation/decode.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime, timedelta, time

import pytz
from django.conf import settings
from metar_taf_parser.parser.parser import TAFParser,MetarParser
from metar_taf_parser.model.enum import CloudQuantity, CloudType, WeatherChangeType, Phenomenon,Intensity, Descriptive
from metar_taf_parser.model.model import WeatherCondition, WeatherChangeType
Expand All @@ -15,15 +16,22 @@
# Get the current date
current_date = datetime.now()

def fmt_date(day, time):
print(day, type(time))
print(day, time)
def fmt_date(message_type, day, time):
# Replace the day, hour, and minute in the current date
data_date = current_date.replace(day=day, hour=time.hour, minute=time.minute, second=time.second, microsecond=0)
# Adjust for month wrap-around
if data_date > current_date + timedelta(days=1):
data_date = data_date - timedelta(days=current_date.day)
# Get the settings timezone
settings_timezone = pytz.timezone(settings.TIME_ZONE)

data_date = current_date.replace(day=day, hour=time.hour, minute=time.minute, second=time.second, microsecond=0, tzinfo=None)
print("before",data_date)
data_date = pytz.UTC.localize(data_date)
print("before",data_date)
data_date = data_date.astimezone(settings_timezone).replace(tzinfo=None)
print("after",data_date)
# If the decoded date is in the future, it must be from the previous month
if message_type == 'METAR':
if data_date > current_date:
previous_month = current_date.replace(day=1) - timedelta(days=1)
data_date = data_date.replace(month=previous_month.month, year=previous_month.year)


return data_date
Expand All @@ -34,9 +42,10 @@ def parse_metar_message(message):
wind = metar._get_wind()
clouds = metar._get_clouds()
visibility = metar._get_visibility()
print("metar.day",metar.day)


metar_date = fmt_date(metar.day, metar.time)
metar_date = fmt_date('METAR',metar.day, metar.time)

decoded_message = {
"type": "METAR",
Expand Down Expand Up @@ -130,7 +139,7 @@ def parse_taf_message(message):
conditions = taf._get_weather_conditions()


taf_date = fmt_date(taf.day, taf.time)
taf_date = fmt_date('TAF',taf.day, taf.time)

decoded_message = {
"type": "TAF",
Expand Down Expand Up @@ -213,8 +222,8 @@ def parse_taf_message(message):
"trends": [
{
"trend_type": WeatherChangeType(trend.type).__repr__() if trend.type else None,
"start_date": fmt_date(trend.validity.start_day, time(trend.validity.start_hour, 0, 0)).strftime('%Y-%m-%d %H:%M:%S UTC') if trend._validity else None,
"end_date": fmt_date(trend.validity.end_day, time(trend.validity.end_hour, 0, 0)).strftime('%Y-%m-%d %H:%M:%S UTC') if trend._validity else None,
"start_date": fmt_date('TAF',trend.validity.start_day, time(trend.validity.start_hour, 0, 0)).strftime('%Y-%m-%d %H:%M:%S UTC') if trend._validity else None,
"end_date": fmt_date('TAF',trend.validity.end_day, time(trend.validity.end_hour, 0, 0)).strftime('%Y-%m-%d %H:%M:%S UTC') if trend._validity else None,
"wind": {
"direction": {
"value": trend.wind.direction if trend.wind else None,
Expand Down
23 changes: 23 additions & 0 deletions pages/aviation/migrations/0009_alter_airport_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.7 on 2024-08-10 07:01

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("aviation", "0008_rename_stationcategory_airportcategory"),
]

operations = [
migrations.AlterField(
model_name="airport",
name="id",
field=models.CharField(
help_text="The ICAO airport code or location indicator is a four-letter code designating aerodromes around the world.",
primary_key=True,
serialize=False,
unique=True,
verbose_name="ICAO Code",
),
),
]
24 changes: 24 additions & 0 deletions pages/aviation/migrations/0010_alter_airport_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.7 on 2024-08-10 07:17

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("aviation", "0009_alter_airport_id"),
]

operations = [
migrations.AlterField(
model_name="airport",
name="id",
field=models.CharField(
help_text="The ICAO airport code or location indicator is a four-letter code designating aerodromes around the world.",
max_length=4,
primary_key=True,
serialize=False,
unique=True,
verbose_name="ICAO Code",
),
),
]
9 changes: 6 additions & 3 deletions pages/aviation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.utils.translation import gettext_lazy as _
from wagtail.api.v2.utils import get_full_url


from wagtailgeowidget.helpers import geosgeometry_str_to_struct
from wagtailgeowidget.panels import LeafletPanel, GeoAddressPanel
from wagtail_color_panel.edit_handlers import NativeColorPanel
Expand Down Expand Up @@ -39,7 +40,7 @@ def __str__(self) -> str:

# Create your models here.
class Airport(models.Model):
id = models.CharField(unique=True, primary_key=True,)
id = models.CharField(unique=True, primary_key=True,max_length=4, verbose_name=_("ICAO Code"), help_text=_("The ICAO airport code or location indicator is a four-letter code designating aerodromes around the world."))
name = models.CharField(verbose_name=_("Airport Name"), max_length=255, null=True, blank=False, unique=True)
slug = AutoSlugField(populate_from='name', null=True, unique=True, default=None, editable=False)
category = models.ForeignKey(AirportCategory, verbose_name=_("Airport Category"), on_delete=models.CASCADE)
Expand All @@ -59,7 +60,7 @@ class Meta:
ordering = ['name']

def __str__(self):
return self.name
return f"{self.name} ({self.id})"

@property
def coordinates(self):
Expand All @@ -84,7 +85,6 @@ def get_context(self, request, *args, **kwargs):
return context



class Message(models.Model):

MSG_FORMAT_CHOICES = [
Expand All @@ -99,6 +99,9 @@ class Message(models.Model):
verbose_name=_("Message Format"),)
msg_datetime = models.DateTimeField(_("Message Datetime"), auto_now=False, auto_now_add=False, null=True)

def __str__(self) -> str:
return f"{self.airport} - {self.msg_datetime} - {self.msg_format}"


class AviationPage(MetadataPageMixin, RoutablePageMixin, Page):
template = "aviation/aviation_page.html"
Expand Down
Binary file added pages/aviation/static/img/barbs/barbs-1-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-10-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-11-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-12-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-13-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-14-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-15-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-16-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-17-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-18-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-19-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-2-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-20-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-21-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-22-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-3-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-4-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-5-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-6-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-7-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-8-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pages/aviation/static/img/barbs/barbs-9-flip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ceb8fa3

Please sign in to comment.