How to use the funcy.project function in funcy

To help you get started, we’ve selected a few funcy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github getredash / redash / tests / test_handlers.py View on Github external
description='y',
            snippet='z',
            user=self.factory.user,
            org=self.factory.org
        )
        models.db.session.add(qs)
        models.db.session.commit()
        res = self.make_request(
            'get',
            '/api/query_snippets',
            user=self.factory.user)
        self.assertEqual(res.status_code, 200)
        data = res.json
        self.assertEqual(len(data), 1)
        self.assertEqual(
            project(data[0], ['id', 'trigger', 'description', 'snippet']), {
                'id': 1,
                'trigger': 'x',
                'description': 'y',
                'snippet': 'z',
            })
        self.assertEqual(qs.trigger, 'x')
        self.assertEqual(qs.description, 'y')
        self.assertEqual(qs.snippet, 'z')
github getredash / redash / tests / handlers / test_groups.py View on Github external
def filtergroups(gs):
            return [project(g, g_keys) for g in gs]
        self.assertEqual(filtergroups(response.json),
github mpes-kit / mpes / mpes / analysis.py View on Github external
pfunc = partial(base.imrc2krc, fr=yratio, fc=xratio)
    k_rowgrid, k_colgrid = np.meshgrid(k_row, k_col)

    # Assemble into return dictionary
    kcalibdict = {}
    kcalibdict['axes'] = (k_row, k_col)
    kcalibdict['extent'] = (k_col[0], k_col[-1], k_row[0], k_row[-1])
    kcalibdict['coeffs'] = (yratio, xratio)
    kcalibdict['grid'] = (k_rowgrid, k_colgrid)

    if ret == 'all':
        return kcalibdict
    elif ret == 'func':
        return pfunc
    else:
        return project(kcalibdict, ret)
github getredash / redash / redash / serializers / __init__.py View on Github external
def public_dashboard(dashboard):
    dashboard_dict = project(serialize_dashboard(dashboard, with_favorite_state=False), (
        'name', 'layout', 'dashboard_filters_enabled', 'updated_at',
        'created_at'
    ))

    widget_list = (models.Widget.query
                   .filter(models.Widget.dashboard_id == dashboard.id)
                   .outerjoin(models.Visualization)
                   .outerjoin(models.Query))

    dashboard_dict['widgets'] = [public_widget(w) for w in widget_list]
    return dashboard_dict
github idrdex / star-django / tags / annotate_views.py View on Github external
def remove_constant_fields(rows):
    if len(rows) <= 1:
        return rows

    varying = {
        key
        for row in rows[1:]
        for key, value in row.items()
        if rows[0].get(key) != value
    }
    return [project(row, varying) for row in rows]
github idrdex / star-django / tags / annotate_core.py View on Github external
def save_validation(canonical_id, data):
    user_id = data['user_id']
    annotations = data['annotations']
    canonical = SeriesAnnotation.objects.select_for_update().get(id=canonical_id)

    if not data.get('on_demand') and canonical.raw_annotations.filter(created_by=user_id).exists():
        raise AnnotationError('You had already annotated this series/platform/tag')

    raw_annotation = RawSeriesAnnotation.objects.create(
        canonical=canonical,
        series_id=canonical.series_id,
        platform_id=canonical.platform_id,
        tag_id=canonical.tag_id,
        created_by_id=user_id,
        **project(data, ['column', 'regex', 'note', 'from_api',
                         'is_active', 'on_demand', 'by_incompetent'])
    )
    raw_annotation.fill_samples(annotations.items())

    ValidationJob.objects.filter(annotation=canonical).delete()

    calc_validation_stats(raw_annotation)
    if raw_annotation.is_active:
        update_canonical(canonical.pk)
    if canonical.best_cohens_kappa != 1:
        reschedule_validation(canonical)

    return raw_annotation
github repertory / docker-redash / redash / serializers.py View on Github external
def public_dashboard(dashboard):
    dashboard_dict = project(dashboard.to_dict(), ('name', 'layout', 'dashboard_filters_enabled', 'updated_at', 'created_at'))

    widget_list = (models.Widget.query
                   .filter(models.Widget.dashboard_id == dashboard.id)
                   .outerjoin(models.Visualization)
                   .outerjoin(models.Query))
    widgets = {w.id: public_widget(w) for w in widget_list}

    widgets_layout = []
    for row in dashboard_dict['layout']:
        new_row = []
        for widget_id in row:
            widget = widgets.get(widget_id, None)
            if widget:
                new_row.append(widget)
        widgets_layout.append(new_row)
github mpes-kit / mpes / mpes / fprocessing.py View on Github external
:Parameters:
        hfile : HDF5 file instance
            Instance of the ``h5py.File`` class.
        attributes, groups : list, list | [], []
            List of strings representing the names of the specified attribute/group names.
            When specified as None, the components (all attributes or all groups) are ignored.
            When specified as [], all components (attributes/groups) are included.
            When specified as a list of strings, only the attribute/group names matching the strings are retrieved.
    """

    out = {}
    # Extract the file attributes
    if attributes is not None:
        attrdict = dict(hfile.attrs.items()) # Contains all file attributes
        if len(attributes) > 0:
            attrdict = project(attrdict, attributes)

    out = u.dictmerge(out, attrdict)

    # Extract the group information
    if groups is not None:
        # groups = None will not include any group.
        if len(groups) == 0:
            # group = [] will include all groups.
            groups = list(hfile)

        for g in groups:
            gdata = hfile.get(g)
            out[g] = dict(gdata.attrs)
            out[g]['shape'] = gdata.shape

    return out
github getredash / redash / redash / serializers / query_result.py View on Github external
def serialize_query_result(query_result, is_api_user):
    if is_api_user:
        publicly_needed_keys = ['data', 'retrieved_at']
        return project(query_result.to_dict(), publicly_needed_keys)
    else:
        return query_result.to_dict()
github mpes-kit / mpes / mpes / analysis.py View on Github external
ecalibdict['bvec'] = bvec
    if (E0 is not None) and (t is not None):
        ecalibdict['axis'] = pfunc(E0, t)
        ecalibdict['E0'] = E0
        
    elif (Eref is not None) and (t is not None):
        E0 = -pfunc(-Eref, pos[refid])
        ecalibdict['axis'] = pfunc(E0, t)
        ecalibdict['E0'] = E0

    if ret == 'all':
        return ecalibdict
    elif ret == 'func':
        return pfunc
    else:
        return project(ecalibdict, ret)