Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/github_actions/peaceiris/action…
Browse files Browse the repository at this point in the history
…s-gh-pages-4.0.0
  • Loading branch information
153957 authored Apr 13, 2024
2 parents 9be2d81 + 55b4ba8 commit f700514
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ WORKDIR /publicdb

# Install miniconda
RUN \
wget --no-verbose https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh \
wget --no-verbose https://repo.continuum.io/miniconda/Miniconda3-py310_24.1.2-0-Linux-x86_64.sh -O miniconda.sh \
&& bash miniconda.sh -b -p /opt/miniconda;

# Use conda Python
Expand Down
14 changes: 7 additions & 7 deletions provisioning/roles/publicdb/files/requirements-conda.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pip
ipython
numpy
pytables
scipy
psycopg2
supervisor
uwsgi
ipython~=8.10.0
numpy~=1.26.4
pytables~=3.7.0
scipy~=1.10.1
psycopg2~=2.9.3
supervisor~=4.2.5
uwsgi~=2.0.20
4 changes: 2 additions & 2 deletions provisioning/roles/publicdb/files/requirements-pip.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Django~=3.2.14
Django~=4.2.11
python-dateutil==2.9.0.post0

sentry-sdk
sentry-sdk~=1.10.1

hisparc-sapphire==2.0.0
41 changes: 41 additions & 0 deletions publicdb/histograms/migrations/0002_initial_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from pathlib import Path

from django.core import serializers
from django.db import migrations


def load_fixture(apps, schema_editor):
"""Load initial data for histogram and dataset types from the fixture"""
original_apps = serializers.python.apps
serializers.python.apps = apps

fixture_file = Path(__file__).parent.parent / 'fixtures/initial_types.json'
with fixture_file.open('r') as fixture:
objects = serializers.deserialize('json', fixture, ignorenonexistent=True)
for obj in objects:
obj.save()

serializers.python.apps = original_apps


def unload_fixture(apps, schema_editor):
"""Delete all entries from the histogram/dataset types
This will also delete all related histograms/datasets!
"""
histogram_type_model = apps.get_model('histograms', 'HistogramType')
histogram_type_model.objects.all().delete()
dataset_type_model = apps.get_model('histograms', 'DatasetType')
dataset_type_model.objects.all().delete()


class Migration(migrations.Migration):

dependencies = [
('histograms', '0001_initial'),
]

operations = [
migrations.RunPython(load_fixture) # reverse_code=unload_fixture
]
36 changes: 36 additions & 0 deletions publicdb/histograms/migrations/0003_initial_generator_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from pathlib import Path

from django.core import serializers
from django.db import migrations


def load_fixture(apps, schema_editor):
"""Load initial data for generator state from the fixture"""
original_apps = serializers.python.apps
serializers.python.apps = apps

fixture_file = Path(__file__).parent.parent / 'fixtures/initial_generator_state.json'
with fixture_file.open('r') as fixture:
objects = serializers.deserialize('json', fixture, ignorenonexistent=True)
for obj in objects:
obj.save()

serializers.python.apps = original_apps


def unload_fixture(apps, schema_editor):
"""Delete all entries from the generator state"""

generator_state_model = apps.get_model('histograms', 'GeneratorState')
generator_state_model.objects.all().delete()


class Migration(migrations.Migration):

dependencies = [
('histograms', '0002_initial_types'),
]

operations = [
migrations.RunPython(load_fixture) # reverse_code=unload_fixture
]
27 changes: 11 additions & 16 deletions publicdb/inforecords/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.db.models import Max
from django.utils.text import slugify

from ..histograms.models import Configuration, Summary
from ..histograms.models import Configuration

FIRSTDATE = datetime.date(2004, 1, 1)

Expand Down Expand Up @@ -276,22 +276,17 @@ def latest_location(self, date=None):
if date is None:
date = datetime.date.today()

# Initialize new config with all None values.
config = Configuration()

try:
summaries = Summary.objects.with_config().filter(station=self, date__lte=date).reverse()
for summary in summaries:
try:
config = (
Configuration.objects.filter(summary=summary).exclude(gps_latitude=0, gps_longitude=0).latest()
)
except Configuration.DoesNotExist:
pass
else:
break
except Summary.DoesNotExist:
pass
config = (
Configuration.objects.exclude(
gps_latitude=0,
gps_longitude=0,
timestamp__gt=date,
).filter(summary__station=self).latest()
)
except Configuration.DoesNotExist:
# Initialize new config with all None values.
config = Configuration()

return {
'latitude': (round(config.gps_latitude, 7) if config.gps_latitude is not None else None),
Expand Down

0 comments on commit f700514

Please sign in to comment.