How to use the funcy.distinct 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 idrdex / star-django / tags / annotate_views.py View on Github external
def get_samples_columns(samples):
    preferred = ['id', 'description', 'characteristics_ch1', 'characteristics_ch2']
    exclude = ['attrs', 'supplementary_file', 'geo_accession']

    columns = distinct(cat(s.keys() for s in samples))
    return lift(preferred, lwithout(columns, *exclude))
github remorses / skema / skema / from_jsonschema.py View on Github external
def schema_to_tree(schema: SchemaBlock, node, references=[]):
    """
    type == integer -> node.insert(Node(INT, node))
    type == number -> node.insert(Node(FLOAT, node))
    type == string -> node.insert(Node(STR, node))
    type == array -> Node(LIST, node).insert(schema_to_tree(item, node))
    type == object -> Node(LIST, node).insert(schema_to_tree(item, node))
    type == or -> [OrNode.insert(schema_to_tree(item)) for item in items]
    """
    if False:
        pass
    elif schema.anyOf or schema.oneOf or schema.allOf or schema.enum:
        child = Node(AND if schema.allOf else OR, node)
        items = schema.oneOf or schema.anyOf or schema.allOf or schema.enum
        items = distinct(items, key=get_type_name)
        i = 0
        for subset in items:
            if isinstance(subset, str):
                subset = SchemaBlock(type=subset,)
            else:
                subset = SchemaBlock.make(subset,)
            if subset.type in ['string', 'integer', 'number', 'boolean', 'null']:
                child = schema_to_tree(subset, child, references)
            else:
                if all([node.value != x for x in (LIST, OR, AND)]):
                    reference_name = capitalize(node.value) + str(i)
                else:
                    reference_name = capitalize(node.parent.value) + 'Elem' + str(i)
                reference_root = Node(reference_name, child)
                reference_root = schema_to_tree(subset, reference_root, references)
                references.append(reference_root)
github repertory / docker-redash / redash / utils / __init__.py View on Github external
def _collect_key_names(nodes):
    keys = []
    for node in nodes._parse_tree:
        if isinstance(node, pystache.parser._EscapeNode):
            keys.append(node.key)
        elif isinstance(node, pystache.parser._SectionNode):
            keys.append(node.key)
            keys.extend(_collect_key_names(node.parsed))

    return distinct(keys)
github repertory / docker-redash / redash / settings.py View on Github external
'redash.query_runner.treasuredata',
    'redash.query_runner.sqlite',
    'redash.query_runner.dynamodb_sql',
    'redash.query_runner.mssql',
    'redash.query_runner.jql',
    'redash.query_runner.google_analytics',
    'redash.query_runner.snowflake',
    'redash.query_runner.axibase_tsd',
    'redash.query_runner.salesforce'
]

enabled_query_runners = array_from_string(os.environ.get("REDASH_ENABLED_QUERY_RUNNERS", ",".join(default_query_runners)))
additional_query_runners = array_from_string(os.environ.get("REDASH_ADDITIONAL_QUERY_RUNNERS", ""))
disabled_query_runners = array_from_string(os.environ.get("REDASH_DISABLED_QUERY_RUNNERS", ""))

QUERY_RUNNERS = remove(set(disabled_query_runners), distinct(enabled_query_runners + additional_query_runners))

# Destinations
default_destinations = [
    'redash.destinations.email',
    'redash.destinations.slack',
    'redash.destinations.webhook',
    'redash.destinations.hipchat',
]

enabled_destinations = array_from_string(os.environ.get("REDASH_ENABLED_DESTINATIONS", ",".join(default_destinations)))
additional_destinations = array_from_string(os.environ.get("REDASH_ADDITIONAL_DESTINATIONS", ""))

DESTINATIONS = distinct(enabled_destinations + additional_destinations)

EVENT_REPORTING_WEBHOOKS = array_from_string(os.environ.get("REDASH_EVENT_REPORTING_WEBHOOKS", ""))
github getredash / redash / redash / models / parameterized_query.py View on Github external
def _collect_key_names(nodes):
    keys = []
    for node in nodes._parse_tree:
        if isinstance(node, pystache.parser._EscapeNode):
            keys.append(node.key)
        elif isinstance(node, pystache.parser._SectionNode):
            keys.append(node.key)
            keys.extend(_collect_key_names(node.parsed))

    return distinct(keys)
github repertory / docker-redash / redash / settings.py View on Github external
disabled_query_runners = array_from_string(os.environ.get("REDASH_DISABLED_QUERY_RUNNERS", ""))

QUERY_RUNNERS = remove(set(disabled_query_runners), distinct(enabled_query_runners + additional_query_runners))

# Destinations
default_destinations = [
    'redash.destinations.email',
    'redash.destinations.slack',
    'redash.destinations.webhook',
    'redash.destinations.hipchat',
]

enabled_destinations = array_from_string(os.environ.get("REDASH_ENABLED_DESTINATIONS", ",".join(default_destinations)))
additional_destinations = array_from_string(os.environ.get("REDASH_ADDITIONAL_DESTINATIONS", ""))

DESTINATIONS = distinct(enabled_destinations + additional_destinations)

EVENT_REPORTING_WEBHOOKS = array_from_string(os.environ.get("REDASH_EVENT_REPORTING_WEBHOOKS", ""))

# Support for Sentry (http://getsentry.com/). Just set your Sentry DSN to enable it:
SENTRY_DSN = os.environ.get("REDASH_SENTRY_DSN", "")

# Client side toggles:
ALLOW_SCRIPTS_IN_USER_INPUT = parse_boolean(os.environ.get("REDASH_ALLOW_SCRIPTS_IN_USER_INPUT", "false"))
DATE_FORMAT = os.environ.get("REDASH_DATE_FORMAT", "DD/MM/YY")

# Features:
FEATURE_ALLOW_ALL_TO_EDIT_QUERIES = parse_boolean(os.environ.get("REDASH_FEATURE_ALLOW_ALL_TO_EDIT", "true"))
VERSION_CHECK = parse_boolean(os.environ.get("REDASH_VERSION_CHECK", "true"))
FEATURE_DISABLE_REFRESH_QUERIES = parse_boolean(os.environ.get("REDASH_FEATURE_DISABLE_REFRESH_QUERIES", "false"))
FEATURE_SHOW_QUERY_RESULTS_COUNT = parse_boolean(os.environ.get("REDASH_FEATURE_SHOW_QUERY_RESULTS_COUNT", "true"))
FEATURE_SHOW_PERMISSIONS_CONTROL = parse_boolean(os.environ.get("REDASH_FEATURE_SHOW_PERMISSIONS_CONTROL", "false"))
github repertory / docker-redash / redash / handlers / queries.py View on Github external
def get(self):
        """
        Retrieve up to 20 queries modified in the last 7 days.

        Responds with a list of :ref:`query ` objects.
        """
        queries = models.Query.recent(self.current_user.group_ids, self.current_user.id)
        recent = [d.to_dict(with_last_modified_by=False) for d in queries]

        global_recent = []
        if len(recent) < 10:
            global_recent = [d.to_dict(with_last_modified_by=False) for d in models.Query.recent(self.current_user.group_ids)]

        return take(20, distinct(chain(recent, global_recent), key=lambda d: d['id']))
github getredash / redash / redash / controllers.py View on Github external
def get(self):
        recent = [d.to_dict() for d in models.Dashboard.recent(current_user.id)]

        global_recent = []
        if len(recent) < 10:
            global_recent = [d.to_dict() for d in models.Dashboard.recent()]

        return distinct(chain(recent, global_recent), key=lambda d: d['id'])