Skip to content

Commit

Permalink
Add more EQ Feature filters for PDC InAWARE
Browse files Browse the repository at this point in the history
- Add since_last_days filter
- Add since_last_hours filter
  • Loading branch information
lucernae committed May 11, 2018
1 parent 04512e9 commit 6f87c04
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: gather os specific variables
include_vars:
file: "{{ pycharm_version }}/{{ ansible_distribution }}.yml"
file: "generic/{{ ansible_distribution }}.yml"

- name: customize /etc/hosts
become: yes
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---

pycharm_settings_path: '/Users/{{ remote_user }}/Library/Preferences/PyCharm2016.3'
pycharm_settings_path: '/Users/{{ remote_user }}/Library/Preferences/PyCharm{{ pycharm_version }}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

pycharm_settings_path: '/home/{{ remote_user }}/.PyCharm{{ pycharm_version }}/config'
3 changes: 2 additions & 1 deletion deployment/ansible/development/site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
2017.1
2017.2
2017.3
2018.1
If not using Pycharm, just skip.
default: '2017.3'
default: '2018.1'
private: no
51 changes: 51 additions & 0 deletions django_project/realtime/filters/earthquake_filter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,54 @@
# coding=utf-8
import datetime

import django_filters
import pytz
import six
from django_filters.fields import Lookup

from realtime.models.earthquake import Earthquake

__author__ = 'Rizky Maulana Nugraha "lucernae" <lana.pcfre@gmail.com>'
__date__ = '23/06/15'


class DateTimeDurationFilter(django_filters.NumberFilter):
"""Used to filter DateTime field based on duration."""

def filter(self, qs, value):
if isinstance(value, Lookup):
lookup = six.text_type(value.lookup_type)
value = value.value
else:
lookup = self.lookup_type
if value in ([], (), {}, None, ''):
return qs

# Handle duration values
parsed_name = lookup.split('__')
today = pytz.utc.fromutc(datetime.datetime.utcnow())
if len(parsed_name) == 2:
duration_field = parsed_name[1]
duration_lookup = parsed_name[0]
if duration_field == 'days':
duration_value = today - datetime.timedelta(days=int(value))
elif duration_field == 'hours':
duration_value = today - datetime.timedelta(hours=int(value))
else:
duration_value = today

qs = self.get_method(qs)(
**{'%s__%s' % (self.name, duration_lookup): duration_value})

else:
qs = self.get_method(qs)(
**{'%s__%s' % (self.name, lookup): value})

if self.distinct:
qs = qs.distinct()
return qs


class EarthquakeFilter(django_filters.FilterSet):

max_magnitude = django_filters.NumberFilter(name='magnitude',
Expand All @@ -14,6 +57,13 @@ class EarthquakeFilter(django_filters.FilterSet):
lookup_type='gte')
max_time = django_filters.DateTimeFilter(name='time', lookup_type='lte')
min_time = django_filters.DateTimeFilter(name='time', lookup_type='gte')

# filter by recent days or hours
since_last_days = DateTimeDurationFilter(
name='time', lookup_type='gte__days')
since_last_hours = DateTimeDurationFilter(
name='time', lookup_type='gte__hours')

max_depth = django_filters.NumberFilter(name='depth', lookup_type='lte')
min_depth = django_filters.NumberFilter(name='depth', lookup_type='gte')

Expand All @@ -32,4 +82,5 @@ class Meta:
'min_time', 'max_depth', 'min_depth',
'maximum_magnitude', 'minimum_magnitude',
'start_date', 'end_date',
'since_last_days', 'since_last_hours',
'location_description']
4 changes: 4 additions & 0 deletions django_project/realtime/views/earthquake.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class EarthquakeList(mixins.ListModelMixin, mixins.CreateModelMixin,
* max_magnitude or maximum_magnitude
* min_time or time_start
* max_time or time_end
* since_last_days (latest EQ since the last d days)
* since_last_hours (latest EQ since the last h hours)
* location_description
* in_bbox filled with BBox String in the format SWLon,SWLat,NELon,NELat
this is used as geographic box filter
Expand Down Expand Up @@ -327,6 +329,8 @@ class EarthquakeFeatureList(EarthquakeList):
* max_magnitude or maximum_magnitude
* min_time or time_start
* max_time or time_end
* since_last_days (latest EQ since the last d days)
* since_last_hours (latest EQ since the last h hours)
* location_description
* felt shakes
* in_bbox filled with BBox String in the format SWLon,SWLat,NELon,NELat
Expand Down

0 comments on commit 6f87c04

Please sign in to comment.