Ejemplo n.º 1
0
    def _fetch_queries(self):
        query_aggregations = aggregate_queries(self._data_queries)

        for dataset_id, query_map in query_aggregations.items():
            for query in query_map.values():
                df = fetch_query(query)
                for query_dimensions, query_infos in query['queries'].items():
                    if valid_dimensions(query_dimensions, df):
                        queried_df = df.query(
                            build_query_string(query_dimensions))
                        for query_info in query_infos:
                            query_info.data = queried_df[
                                query_info.query.coordinate.measure]
                    else:
                        for query_info in query_infos:
                            query_info.data = Series()

        for query_info in self._data_queries:
            if query_info.data is None or len(query_info.data) == 0:
                query_info.processor.calculate(
                    query_info.attr,
                    ProcessorResult(
                        False, f'No data found for '
                        f'Coordinate {query_info.query.coordinate}'))
            else:
                query_info.processor.calculate(
                    query_info.attr, ProcessorResult(True, query_info.data))
Ejemplo n.º 2
0
    def _fetch_queries(self):
        query_aggregations = aggregate_queries(self._data_queries)

        for dataset_id, query_map in query_aggregations.items():
            for query in query_map.values():
                df = fetch_query(query)
                for query_dimensions, query_infos in query['queries'].items():
                    if valid_dimensions(query_dimensions, df):
                        queried_df = df.query(
                            build_query_string(query_dimensions))
                        for query_info in query_infos:
                            measure = query_info.query.coordinate.measure
                            query_info.data = queried_df[measure if isinstance(
                                measure, str) else measure.value]
                    else:
                        for query_info in query_infos:
                            query_info.data = Series()

        for query_info in self._data_queries:
            if query_info.data is None or len(query_info.data) == 0:
                asyncio.get_event_loop().run_until_complete(
                    query_info.processor.calculate(
                        query_info.attr,
                        ProcessorResult(
                            False, f'No data found for '
                            f'Coordinate {query_info.query.coordinate}'),
                        self.rule_cache))
            else:
                asyncio.get_event_loop().run_until_complete(
                    query_info.processor.calculate(
                        query_info.attr,
                        ProcessorResult(True,
                                        query_info.data), self.rule_cache))