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

add support for merged datasets #1082

Merged
merged 88 commits into from
Aug 24, 2017
Merged

add support for merged datasets #1082

merged 88 commits into from
Aug 24, 2017

Conversation

ukanga
Copy link
Member

@ukanga ukanga commented Aug 6, 2017

Implements merged datasets as described in #1057

@ivermac
Copy link
Contributor

ivermac commented Aug 7, 2017

Hey @ukanga I was testing out the the last_submission_time on merged dataset and it seems not to be returned. On further investigation, it seems a merged dataset object is created before setting the last_submission_time variable - which I believe was what this function was meant to do. We could add a utility function that returns the last submission time outside the serializer class (borrowed this snippet from what is in the get_last_submission_time function):

def get_last_submission_time(xforms):
    values = [
        x.last_submission_time
        for x in xforms
        if x.last_submission_time
    ]
    if values:
        return sorted(values, reverse=True)[0]

Then inside the create serializer function, we could set the last_submission_time in the validated_data variable:

...
validated_data['last_submission_time'] = get_last_submission_time(
            validated_data['xforms']
        )

The above snippets seem to work for me but if there is a better implementation, that would be great.

@ukanga
Copy link
Member Author

ukanga commented Aug 7, 2017

The idea was that it will be calculated on the fly. I will check on it.

@ukanga
Copy link
Member Author

ukanga commented Aug 7, 2017

@ivermac I have made the changes on the forms endpoint, 8692573.

@ivermac
Copy link
Contributor

ivermac commented Aug 7, 2017

Cool, thanks @ukanga. I'll check it out

UPDATE: works as expected

Merged Datasets
***************

This endpoint provides access to data from multiple forms Merged datasets should have the same functionality as the forms endpoint with the difference being:
Copy link
Member

Choose a reason for hiding this comment

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

add a period after "from" and before "Merged datasets"

^^^^^^^^^^
- ``name`` - Name or title of the merged dataset (required)
- ``project`` - Project for the merged dataset (required)
- ``xforms`` - list of forms to merge (required, at least 2 forms should be provided )
Copy link
Member

Choose a reason for hiding this comment

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

should the "L" in "List" be capitalized? To make it consistent with the lines above, or should the others be lowercased (also, I know it's a nitpick sorry, there's an extra space before the parenthesis at the end of this line)

How data in parent forms differs from and affects the merged xform
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

A merged dataset combines data from multiple forms into one. It creates a new form structure from the intersection of the fields from the forms being merged.
Copy link
Member

Choose a reason for hiding this comment

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

I change the final "from" to "in" for clarity, so end of this line changes to "in the forms being merged."

CacheControlMixin,
ETagsMixin,
# pylint: disable=R0901
class ChartsViewSet(AnonymousUserPublicFormsMixin, AuthenticateHeaderMixin,
Copy link
Member

Choose a reason for hiding this comment

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

I don't get why to change this esp if it requires adding the pylint flag? I like the previous format

Copy link
Member Author

Choose a reason for hiding this comment

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

Pylint R0901 has to do with "Too many ancestors".

The formatting at this time was under the mercy of yapf command, I tend to take its recommendations. I should probably look into and check-in yapf's configuration.

@@ -171,7 +171,13 @@ def _get_instances(xform, start, end):
if isinstance(end, datetime.datetime):
kwargs.update({'date_created__lte': end})

instances = xform.instances.filter(**kwargs)
instances = xform.instances
Copy link
Member

Choose a reason for hiding this comment

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

this could go in an else

@ukanga ukanga force-pushed the merged-datasets branch 2 times, most recently from 16e7429 to 776fdf9 Compare August 17, 2017 04:35
@ivermac
Copy link
Contributor

ivermac commented Aug 18, 2017

I would like is_merged_dataset field to be added to this line to allow zebra to only list non-merged forms when a user wants to select forms that can be merged i.e. the form listing on the screenshot below should only have normal forms - no dataviews or merged datasets.
screen shot 2017-08-18 at 15 30 58

@ukanga
Copy link
Member Author

ukanga commented Aug 18, 2017

@ivermac I will add the field.

@ukanga
Copy link
Member Author

ukanga commented Aug 19, 2017

This PR now includes service integrations support for merged datasets.

intersect = set([__ for (__, ___) in intersect])

merged_xform_dict['children'] = _get_elements(children, intersect)
del merged_xform_dict['_xpath']
Copy link
Contributor

Choose a reason for hiding this comment

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

@ukanga This could be re-written as

...
merged_xform_dict.get("_xpath") and merged_xform_dict.pop("_xpath")

On stage and locally, saving a merged dataset triggers the following error
screen shot 2017-08-21 at 14 19 18

Ona KE code machine added 17 commits August 24, 2017 06:43
Ensure that:
 - `name` is a required field
 - `project` is a required field
 - `xforms` is a list of at least 2 xforms & should have unique elements

Signed-off-by: Njagi Mwaniki <[email protected]>
apply the MergedXForm permissions in roles

Signed-off-by: Njagi Mwaniki <[email protected]>
Also, set sms_keyword to match the id_string, this affects sms_id_string

Signed-off-by: Njagi Mwaniki <[email protected]>
ukanga added 25 commits August 24, 2017 06:43
It is messing up other tests and there is no point updating all fixtures
to add the additional fields specific to this one test.
Added get_merged_xform_survey() function that uses the intersection of
fields of xforms being merged to create a new survey object with only
the intersecting fields.
PyxfformMarkdown is already mixed in TestBase
@ukanga ukanga merged commit 960250d into master Aug 24, 2017
@ukanga ukanga deleted the merged-datasets branch August 24, 2017 09:49
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.

4 participants