Skip to content
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

Include support for repeating sections for the tableau-onadata integration #1845

Merged
merged 5 commits into from
Aug 28, 2020

Conversation

WinnyTroy
Copy link
Contributor

@WinnyTroy WinnyTroy commented Jul 8, 2020

Changes / Features implemented

Include support for nested repeats and nested groups for the tableau integration.

Steps taken to verify this change does what is intended

  • QA

Side effects of implementing this change

None

Closes #
Resolves part of #1777

@WinnyTroy WinnyTroy force-pushed the tableau_repeating_section_support branch from 9be5c9d to dee81d5 Compare July 8, 2020 13:13
@WinnyTroy WinnyTroy marked this pull request as ready for review July 9, 2020 12:22
@faith-mutua
Copy link

@WinnyTroy Data in nested groups is being downloaded to Tableau.
However, I have noted that data within nested repeat groups is not being downloaded. It's only data in the main/parent repeat group that's being downloaded. Use this sample form to test this.

@faith-mutua
Copy link

@WinnyTroy I have tested different scenarios and the results are as follows;

  1. Nested repeat in a group- Data in the nested repeat group is not downloaded but data in the parent repeat group and the group is downloaded.

  2. Nested repeat in nested group - Only data in the nested groups is downloaded. Data collected in both the parent repeat group and the nested repeat group is not downloaded.

  3. Nested group - All data is downloaded

  4. Nested repeat - Data is downloaded

  5. Group in a nested repeat - Data in the group is not downloaded. Data collected in both the parent repeat group and the nested repeat group is downloaded.

  6. nested group in a nested repeat - Data in nested groups is not downloaded. Data collected in both the parent repeat group and the nested repeat group is downloaded.

Copy link
Member

@ukanga ukanga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests, please?

@WinnyTroy WinnyTroy force-pushed the tableau_repeating_section_support branch from 481755b to f3a4b47 Compare July 27, 2020 15:23
Copy link
Contributor

@ivermac ivermac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me. I've added a few suggestions

index=index,
close_tag=index_tags[1])
]
if len(key.split('/')) > 1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SInce we've referenced len(key.split('/')) in line 70 and 64, may be we want to set the call in a variable then call the variable on those lines.

except TypeError:
xpaths = xpaths[0] + ('/').join(nested_key_diff)
else:
xpaths = xpaths + [nested_key.split('/')[1]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SInce we've referenced nested_key.split('/') in line 76 and 60, may be we want to set the call in a variable then call the variable on those lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, let me update this

Comment on lines 62 to 68
xpaths = [
'{key}{open_tag}{index}{close_tag}'.format(
key=key if len(key.split('/')) > 1
else nested_key.split('/')[0],
open_tag=index_tags[0],
index=index,
close_tag=index_tags[1])
]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure what's going on here 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen where it's been moved from 😄

@WinnyTroy WinnyTroy force-pushed the tableau_repeating_section_support branch 5 times, most recently from a78b80c to 5874767 Compare August 11, 2020 07:18
Copy link
Contributor

@ivermac ivermac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting close.

Comment on lines 63 to 68
def unpack_data(key, value, data=None, xpaths=None):
if isinstance(value, str) and data:
choices = value.split(" ")
for choice in choices:
xpaths = f'{key}/{choice}'
data[xpaths] = choice
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to rename this function to something like update_data since we are updating the data dictionary in the function?

xpaths = key + f'[{index}]/' + '/'.join(nested_key_diff)
return xpaths

def unpack_data(key, value, data=None, xpaths=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a docstring for this function.... Finding it a bit hard to tell why xpaths is an argument... In what scenario would someone pass xpaths ?

Is data supposed to be optional ? Seems like the function can't run without it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah...changed those two items. Thanks for the catch

@WinnyTroy WinnyTroy force-pushed the tableau_repeating_section_support branch from 5874767 to b7d97e6 Compare August 11, 2020 14:15
Copy link
Contributor

@ivermac ivermac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting close

xpaths = key + f'[{index}]/' + '/'.join(nested_key_diff)
return xpaths

def unpack_select_multiple_data(key, value, data):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure about the function name here since as mentioned in my previous comment, the main functionality, and correct me if I'm wrong, is to update the data variable using choices values. How about we rename it to get_updated_data and make ensure that data is returned?

...
if isinstance(value, str) and data:
    choices = value.split(" ")
    for choice in choices:
        xpaths = f'{key}/{choice}'
        data[xpaths] = choice

return data

Then we can then assign the data variable with result from get_updated_data like the following:

...
if qstn_type == MULTIPLE_SELECT_TYPE:
    data = get_updated_data(xpaths, nested_val, data)

@WinnyTroy WinnyTroy force-pushed the tableau_repeating_section_support branch 3 times, most recently from 7438753 to 78d16d8 Compare August 12, 2020 08:37
Copy link
Member

pld commented Aug 12, 2020

Codacy Here is an overview of what got changed by this pull request:

Complexity decreasing per file
==============================
+ onadata/apps/api/viewsets/open_data_viewset.py  -1
         

See the complete overview on Codacy

ivermac
ivermac previously approved these changes Aug 24, 2020
ukanga
ukanga previously approved these changes Aug 27, 2020
@WinnyTroy WinnyTroy dismissed stale reviews from ukanga and ivermac via 628dd53 August 28, 2020 11:48
@WinnyTroy WinnyTroy force-pushed the tableau_repeating_section_support branch from 78d16d8 to 628dd53 Compare August 28, 2020 11:48
Copy link
Member

pld commented Aug 28, 2020

Codacy Here is an overview of what got changed by this pull request:

Complexity decreasing per file
==============================
+ onadata/apps/api/viewsets/open_data_viewset.py  -1
         

Clones added
============
- onadata/apps/api/tests/viewsets/test_open_data_viewset.py  2
         

See the complete overview on Codacy

@DavisRayM DavisRayM merged commit 454e89e into master Aug 28, 2020
@DavisRayM DavisRayM deleted the tableau_repeating_section_support branch August 28, 2020 11:53
@DavisRayM DavisRayM mentioned this pull request Aug 31, 2020
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants