Skip to content

Commit

Permalink
Fix has props and composition in hint (#895)
Browse files Browse the repository at this point in the history
* Fix has props and composition in hint

* Fix hint scheme test

* Small hint scheme bugs
  • Loading branch information
munrojm authored Nov 17, 2023
1 parent 9c78dd7 commit 70094f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
33 changes: 19 additions & 14 deletions emmet-api/emmet/api/routes/materials/summary/hint_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@ def generate_hints(self, query):
hints["agg_hint"] = hints["count_hint"]

if list(query.get("criteria").keys()) != ["deprecated", "builder_meta.license"]:
for param in query["criteria"]:
if param not in [
"deprecated",
"builder_meta.license",
] and ("has_props" not in param and "composition_reduced" not in param):
hints["count_hint"] = {
"deprecated": 1,
"builder_meta.license": 1,
"formula_pretty": 1,
"material_id": 1,
param: 1,
}
hints["agg_hint"] = hints["count_hint"]
break
pure_params = [param.split(".")[0] for param in query["criteria"]]

if "has_props" in pure_params:
hints["count_hint"] = {"has_props.$**": 1}
elif "composition_reduced" in pure_params:
hints["count_hint"] = {"composition_reduced.$**": 1}
else:
for param in pure_params:
if param not in ["deprecated", "builder_meta"]:
hints["count_hint"] = {
"deprecated": 1,
"builder_meta.license": 1,
"formula_pretty": 1,
"material_id": 1,
param: 1,
}
break

hints["agg_hint"] = hints["count_hint"]

elif query.get("sort", {}):
for param in query["sort"]:
Expand Down
4 changes: 2 additions & 2 deletions emmet-api/tests/materials/summary/test_hint_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def test_summary_hint_scheme():
"sort": {"energy_above_hull": 1},
}
) == {
"count_hint": {"deprecated": 1, "builder_meta.license": 1},
"agg_hint": {"deprecated": 1, "builder_meta.license": 1},
"count_hint": {"has_props.$**": 1},
"agg_hint": {"has_props.$**": 1},
}
assert scheme.generate_hints(
{
Expand Down

0 comments on commit 70094f3

Please sign in to comment.