Skip to content

Commit 50ed13e

Browse files
committed
Resolve "Extract basic statistics from router.info"
1 parent 36d5777 commit 50ed13e

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

nomad/app/v1/routers/info.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@
3030
from pydantic.main import BaseModel
3131

3232
from nomad import normalizing
33-
from nomad.app.v1.models import Aggregation, StatisticsAggregation
3433
from nomad.config import config
3534
from nomad.parsing import parsers
3635
from nomad.parsing.parsers import code_metadata
37-
from nomad.search import search
36+
from nomad.search import get_statistics
3837
from nomad.utils import strip
3938

4039
INFO_CACHE_TTL: Final[int] = 1 * 24 * 60 * 60 # 1 day in seconds
@@ -120,26 +119,6 @@ class InfoModel(BaseModel):
120119
)
121120

122121

123-
def get_statistics():
124-
search_response = search(
125-
aggregations=dict(
126-
statistics=Aggregation(
127-
statistics=StatisticsAggregation(
128-
metrics=[
129-
'n_entries',
130-
'n_materials',
131-
'n_uploads',
132-
'n_quantities',
133-
'n_calculations',
134-
]
135-
)
136-
)
137-
)
138-
)
139-
statistics = search_response.aggregations['statistics'].statistics.data
140-
return statistics
141-
142-
143122
@router.get(
144123
'',
145124
tags=[APITag.DEFAULT],

nomad/processing/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949

5050
import nomad.patch # noqa: F401
5151
from nomad import infrastructure, utils
52-
from nomad.app.v1.routers.info import get_statistics
5352
from nomad.config import config
5453
from nomad.config.models.config import CELERY_WORKER_ROUTING
54+
from nomad.search import get_statistics
5555

5656
if config.logstash.enabled:
5757
from nomad.utils import structlogging

nomad/search.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,3 +1973,23 @@ def quantity_values(
19731973
page_after_value = value_agg.pagination.next_page_after_value
19741974
if page_after_value is None:
19751975
break
1976+
1977+
1978+
def get_statistics():
1979+
search_response = search(
1980+
aggregations=dict(
1981+
statistics=Aggregation(
1982+
statistics=StatisticsAggregation(
1983+
metrics=[
1984+
'n_entries',
1985+
'n_materials',
1986+
'n_uploads',
1987+
'n_quantities',
1988+
'n_calculations',
1989+
]
1990+
)
1991+
)
1992+
)
1993+
)
1994+
statistics = search_response.aggregations['statistics'].statistics.data
1995+
return statistics

0 commit comments

Comments
 (0)