Commit d33d65ee authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fixed missing metrics data for date_histogram. #339

parent 5ab19a6e
......@@ -180,10 +180,14 @@ class RepoCalcsResource(Resource):
except Exception as e:
abort(400, message='bad parameters: %s' % str(e))
for metric in metrics:
if metric not in search_extension.metrics:
abort(400, message='there is no metric %s' % metric)
search_request = search.SearchRequest()
apply_search_parameters(search_request, args)
if date_histogram:
search_request.date_histogram(interval=interval)
search_request.date_histogram(interval=interval, metrics_to_use=metrics)
try:
assert page >= 1
......@@ -194,10 +198,6 @@ class RepoCalcsResource(Resource):
if order not in [-1, 1]:
abort(400, message='invalid pagination')
for metric in metrics:
if metric not in search_extension.metrics:
abort(400, message='there is no metric %s' % metric)
if len(statistics) > 0:
search_request.statistics(statistics, metrics_to_use=metrics)
......
......@@ -1064,6 +1064,15 @@ class TestRepo():
histogram = data.get('statistics').get('date_histogram')
assert len(histogram) == nbuckets
def test_search_date_histogram_metrics(self, api, example_elastic_calcs, no_warn):
rv = api.get('/repo/?date_histogram=true&metrics=unique_entries')
assert rv.status_code == 200
data = json.loads(rv.data)
histogram = data.get('statistics').get('date_histogram')
bucket = histogram[list(histogram.keys())[0]]
assert 'code_runs' in bucket
assert 'unique_entries' in bucket
@pytest.mark.parametrize('n_results, page, per_page', [(2, 1, 5), (1, 1, 1), (0, 2, 3)])
def test_search_pagination(self, api, example_elastic_calcs, no_warn, n_results, page, per_page):
rv = api.get('/repo/?&page=%d&per_page=%d&statistics=dft.system' % (page, per_page))
......
......@@ -15,6 +15,7 @@
from typing import List, Iterable
from elasticsearch_dsl import Q
import pytest
from datetime import datetime
from nomad import datamodel, search, processing, parsing, infrastructure, config
from nomad.search import entry_document, SearchRequest
......@@ -71,7 +72,8 @@ def test_index_upload(elastic, processed: processing.Upload):
def example_search_data(elastic, normalized: parsing.Backend):
entry_metadata = normalized.entry_archive.section_metadata
entry_metadata.m_update(
domain='dft', upload_id='test upload id', calc_id='test id')
domain='dft', upload_id='test upload id', calc_id='test id',
upload_time=datetime.now())
entry_metadata.apply_domain_metadata(normalized)
create_entry(entry_metadata)
refresh_index()
......@@ -178,15 +180,17 @@ def test_search_statistics(elastic, example_search_data):
use_metrics = search_extension.metrics.keys()
request = SearchRequest(domain='dft').statistic(
'dft.system', size=10, metrics_to_use=use_metrics).date_histogram()
'dft.system', size=10, metrics_to_use=use_metrics).date_histogram(metrics_to_use=use_metrics)
results = request.execute()
statistics = results['statistics']
assert 'results' not in results
assert 'bulk' in statistics['dft.system']
assert 'date_histogram' in statistics
example_statistic = statistics['dft.system']['bulk']
assert_metrics(example_statistic, use_metrics)
assert_metrics(statistics['date_histogram'][list(statistics['date_histogram'].keys())[0]], use_metrics)
assert_metrics(statistics['total']['all'], [])
assert 'quantities' not in results
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment