-
Notifications
You must be signed in to change notification settings - Fork 133
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
Tableau v2 #1910
Tableau v2 #1910
Conversation
260c198
to
72e552b
Compare
ab9f686
to
8fc3ad9
Compare
ed167a7
to
fe7c2ad
Compare
585812c
to
ad257ab
Compare
Here is an overview of what got changed by this pull request: Complexity increasing per file
==============================
- onadata/apps/api/viewsets/tableau_viewset.py 25
Clones added
============
- onadata/apps/api/viewsets/open_data_viewset.py 1
- onadata/apps/api/viewsets/tableau_viewset.py 1
See the complete overview on Codacy |
2f55c5d
to
66949a2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few comments but it generally looks good
# Pop any list within the returned repeat data. | ||
# Lists represent a repeat group which should be in a | ||
# separate field. | ||
cleaned_data = [] | ||
for data_dict in repeat_data: | ||
remove_keys = [] | ||
for k, v in data_dict.items(): | ||
if isinstance(v, list): | ||
remove_keys.append(k) | ||
flat_dict[k].extend(v) | ||
# pylint: disable=expression-not-assigned | ||
[data_dict.pop(k) for k in remove_keys] | ||
cleaned_data.append(data_dict) | ||
flat_dict[qstn_name] = cleaned_data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move this to function that returns cleaned_data
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
picked_choices = value.split(" ") | ||
choice_names = [ | ||
question["name"] for question in qstn["children"]] | ||
list_name = qstn.get('list_name') | ||
for choice in choice_names: | ||
qstn_name = f"{list_name}_{choice}" | ||
|
||
if prefix: | ||
qstn_name = prefix + '_' + qstn_name | ||
|
||
if choice in picked_choices: | ||
flat_dict[qstn_name] = "TRUE" | ||
else: | ||
flat_dict[qstn_name] = "FALSE" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this to a function outside this function that updates flat_dict
?
value_parts = value.split(' ') | ||
gps_xpath_parts = [] | ||
for part in GPS_PARTS: | ||
name = f"_{qstn_name}_{part}" | ||
if prefix: | ||
name = prefix + '_' + name | ||
gps_xpath_parts.append((name, None)) | ||
if len(value_parts) == 4: | ||
gps_parts = dict( | ||
zip(dict(gps_xpath_parts), value_parts)) | ||
flat_dict.update(gps_parts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this to a function outside this function?
dde45e9
to
5ae768a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting close
def unpack_select_multiple_data(picked_choices, list_name, | ||
choice_names, prefix, flat_dict): | ||
for choice in choice_names: | ||
qstn_name = f"{list_name}_{choice}" | ||
|
||
if prefix: | ||
qstn_name = prefix + '_' + qstn_name | ||
|
||
if choice in picked_choices: | ||
flat_dict[qstn_name] = "TRUE" | ||
else: | ||
flat_dict[qstn_name] = "FALSE" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change this function to return flat_dict
- just like it's been done in line 116 - then assign the returned value to flat_dict
in line 70
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made this change
gps_parts = unpack_gps_data( | ||
value, qstn_name, prefix) | ||
flat_dict.update(gps_parts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if unpack_gps_data
returns None
, line 79 would trigger an error, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say no. I dont believe there could be a scenerio where it would return None
. Maybe this is something new we could test
The function can only be called if the element is of "geopoint" question type. All geopoint question types are space separated strings, unless the user does not provide data for this question, for which the field is then not present in the json returned by the serializer. I could be wrong Cc: @DavisRayM
7bb5906
to
e14821d
Compare
Add repeat column headers list if the headers list already exists.
…mn headers have been defined using the select multiple question. Gnerate column headers with gps headers split into 4 column headers ie. altitude, latitude, precision and longitude
- Split gps fields into separate columns - Ensure schema and data always have the same columns by utilizing the JSON of an XLS Form - Support "select_multiple" questions
Add tests
ded004d
to
604567f
Compare
Break apart the process tableau data function into separate functions
604567f
to
78896bf
Compare
085441a
to
4676dd3
Compare
4676dd3
to
049f53a
Compare
Changes / Features implemented
Defines a new endpoint implementing multiple tables on Tableau repeat data collected on Onadata.
With this every repeat/nested repeat defines a new tableau table.
Steps taken to verify this change does what is intended
Confirming schema and data definitions on the new
/api/v1/open-data/v2
endpointAdd tests
An alternative solution for #1880
Part of #1885