telescope_states.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:valhalla 作者: LCOGT 项目源码 文件源码
def _get_es_data(self, sites, telescopes):
        date_range_query = {
            "query": {
                "bool": {
                    "filter": [
                        {
                            "range": {
                                "timestamp": {
                                    # Retrieve documents 1 hour back to capture the telescope state at the start.
                                    "gte": (self.start - timedelta(hours=1)).strftime(ES_STRING_FORMATTER),
                                    "lte": self.end.strftime(ES_STRING_FORMATTER),
                                    "format": "yyyy-MM-dd HH:mm:ss"
                                }
                            }
                        },
                        {
                            "terms": {
                                "telescope": telescopes
                            }
                        },
                        {
                            "terms": {
                                "site": sites
                            }
                        }
                    ]
                }
            }
        }
        event_data = []
        query_size = 10000

        try:
            data = self.es.search(
                index="telescope_events", body=date_range_query, size=query_size, scroll='1m',  # noqa
                _source=['timestamp', 'telescope', 'enclosure', 'site', 'type', 'reason'],
                sort=['site', 'enclosure', 'telescope', 'timestamp']
            )
        except ConnectionError:
            raise ElasticSearchException

        event_data.extend(data['hits']['hits'])
        total_events = data['hits']['total']
        events_read = min(query_size, total_events)
        scroll_id = data.get('_scroll_id', 0)
        while events_read < total_events:
            data = self.es.scroll(scroll_id=scroll_id, scroll='1m') # noqa
            scroll_id = data.get('_scroll_id', 0)
            event_data.extend(data['hits']['hits'])
            events_read += len(data['hits']['hits'])
        return event_data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号