Skip to content

Commit

Permalink
Unpack gps data into altitude, presion, latitude and longitude columns
Browse files Browse the repository at this point in the history
  • Loading branch information
WinnyTroy committed Aug 24, 2020
1 parent d80bb18 commit 8238f10
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion onadata/apps/api/tests/viewsets/test_open_data_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,17 @@ def test_tableau_get_repeat_data(self):
self.assertEqual(response.status_code, 200)
# cast generator response to list for easy manipulation
row_data = streaming_data(response)
# Test that Tableau receives this data
# Test that Tableau receives group data
self.assertEqual(
row_data[0]['children_1__childs_name'],
'Tom')
self.assertEqual(
row_data[0]['children_2__childs_age'],
5)
# Test that gps data is unpacked for Tableau appropriately.
self.assertEqual(
row_data[0]['_gps_latitude'],
'-1.2625621')
self.assertEqual(
row_data[0]['_gps_longitude'],
'36.7921711')
11 changes: 11 additions & 0 deletions onadata/apps/api/viewsets/open_data_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from onadata.apps.logger.models import Instance
from onadata.apps.logger.models.open_data import OpenData
from onadata.apps.logger.models.xform import XForm, question_types_to_exclude
from onadata.apps.viewer.models.data_dictionary import DataDictionary
from onadata.libs.data import parse_int
from onadata.libs.utils.logger_tools import remove_metadata_fields
from onadata.libs.mixins.cache_control_mixin import CacheControlMixin
Expand Down Expand Up @@ -105,6 +106,16 @@ def get_ordered_repeat_value(key, item, index):
for choice in choices:
xpaths = f'{key}_{choice}'
flat_dict[xpaths] = choice
if qstn_type == 'geopoint':
parts = value.split(' ')
gps_xpaths = \
DataDictionary.get_additional_geopoint_xpaths(
key)
gps_parts = dict(
[(xpath, None) for xpath in gps_xpaths])
if len(parts) == 4:
gps_parts = dict(zip(gps_xpaths, parts))
flat_dict.update(gps_parts)
else:
flat_dict[key] = value
except AttributeError:
Expand Down

0 comments on commit 8238f10

Please sign in to comment.