(user_id)
return result
gets the last form submission for each app for a given user id
    :param user_id: id of a couch user
    :return: last form submission for every app that user has submitted
gets the last form submission for each app for a given user id
    :param user_id: id of a couch user
    :return: last form submission for every app that user has submitted
gets the last form submission for each app for a given user id : param user_id : id of a couch user : return : last form submission for every app that user has submitted
def get_last_forms_by_app(user_id):
    """
    gets the last form submission for each app for a given user id
    :param user_id: id of a couch user
    :return: last form submission for every app that user has submitted
    """
    query = (
        FormES()
            .user_id(user_id)
            .aggregation(
            TermsAggregation('app_id', 'app_id').aggregation(
                TopHitsAggregation(
                    'top_hits_last_form_submissions',
                    'received_on',
                    is_ascending=False,
                )
            )
        )
        .size(0)
    )

    aggregations = query.run().aggregations

    buckets_dict = aggregations.app_id.buckets_dict
    result = []
    for app_id, bucket in buckets_dict.items():
        result.append(bucket.top_hits_last_form_submissions.hits[0])

    return result
def get_last_forms_by_app ( user_id ) : query = ( FormES ( ) . user_id ( user_id ) . aggregation ( TermsAggregation ( 'app_id' , 'app_id' ) . aggregation ( TopHitsAggregation ( 'top_hits_last_form_submissions' , 'received_on' , is_ascending = False , ) ) ) . size ( 0 ) ) aggregations = query . run ( ) . aggregations buckets_dict = aggregations . app_id . buckets_dict result = [ ] for app_id , bucket in buckets_dict . items ( ) : result . append ( bucket . top_hits_last_form_submissions . hits [ 0 ] ) return result