(
        domain,
        app_id,
        xmlns,
        user_ids,
        startdate,
        enddate,
        by_submission_time=True)
return result
Gets stats on the duration of a selected form grouped by users
Gets stats on the duration of a selected form grouped by users
Gets stats on the duration of a selected form grouped by users
def get_form_duration_stats_by_user(
        domain,
        app_id,
        xmlns,
        user_ids,
        startdate,
        enddate,
        by_submission_time=True):
    """Gets stats on the duration of a selected form grouped by users"""
    date_filter_fn = submitted_filter if by_submission_time else completed_filter

    missing_users = None in user_ids

    query = (
        FormES()
        .domain(domain)
        .user_ids_handle_unknown(user_ids)
        .remove_default_filter('has_user')
        .xmlns(xmlns)
        .filter(date_filter_fn(gte=startdate, lt=enddate))
        .aggregation(
            TermsAggregation('user_id', 'form.meta.userID').aggregation(
                ExtendedStatsAggregation(
                    'duration_stats',
                    'form.meta.timeStart',
                    script=_duration_script(),
                )
            )
        )
        .size(0)
    )

    if app_id:
        query = query.app(app_id)

    if missing_users:
        query = query.aggregation(
            MissingAggregation('missing_user_id', 'form.meta.userID').aggregation(
                ExtendedStatsAggregation(
                    'duration_stats',
                    'form.meta.timeStart',
                    script=_duration_script(),
                )
            )
        )

    result = {}
    aggregations = query.run().aggregations

    if missing_users:
        result[MISSING_KEY] = aggregations.missing_user_id.bucket.duration_stats.result

    buckets_dict = aggregations.user_id.buckets_dict
    for user_id, bucket in buckets_dict.items():
        result[user_id] = bucket.duration_stats.result
    return result
def get_form_duration_stats_by_user ( domain , app_id , xmlns , user_ids , startdate , enddate , by_submission_time = True ) : date_filter_fn = submitted_filter if by_submission_time else completed_filter missing_users = None in user_ids query = ( FormES ( ) . domain ( domain ) . user_ids_handle_unknown ( user_ids ) . remove_default_filter ( 'has_user' ) . xmlns ( xmlns ) . filter ( date_filter_fn ( gte = startdate , lt = enddate ) ) . aggregation ( TermsAggregation ( 'user_id' , 'form.meta.userID' ) . aggregation ( ExtendedStatsAggregation ( 'duration_stats' , 'form.meta.timeStart' , script = _duration_script ( ) , ) ) ) . size ( 0 ) ) if app_id : query = query . app ( app_id ) if missing_users : query = query . aggregation ( MissingAggregation ( 'missing_user_id' , 'form.meta.userID' ) . aggregation ( ExtendedStatsAggregation ( 'duration_stats' , 'form.meta.timeStart' , script = _duration_script ( ) , ) ) ) result = { } aggregations = query . run ( ) . aggregations if missing_users : result [ MISSING_KEY ] = aggregations . missing_user_id . bucket . duration_stats . result buckets_dict = aggregations . user_id . buckets_dict for user_id , bucket in buckets_dict . items ( ) : result [ user_id ] = bucket . duration_stats . result return result