-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from OKN-CollabNext/implement-search
Super simple search feature
- Loading branch information
Showing
8 changed files
with
133 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
from pyalex import Institution, Institutions | ||
import json | ||
import os | ||
import sys | ||
|
||
from pyalex import Institution, Institutions | ||
|
||
BUILD_ENV = os.getenv("BUILD_ENV") or "development" | ||
|
||
|
||
def get_institutions(institutions_file_path: str = "docs/data/institutions.json") -> list[Institution]: | ||
def get_institutions() -> list[Institution]: | ||
institutions = [] | ||
|
||
|
||
institutions_file_path = ( | ||
"docs/data/institutions.json" | ||
if BUILD_ENV == "production" | ||
else "docs/data/institutions-dev.json" | ||
) | ||
|
||
# Load institutions from JSON file | ||
try: | ||
institutions = json.load(open(institutions_file_path)) | ||
try: | ||
institutions = json.load(open(institutions_file_path)) | ||
except Exception as e: | ||
print("\nError loading institutions from JSON file", institutions_file_path, ":", e, "\n", file=sys.stderr) | ||
print( | ||
"\nError loading institutions from JSON file", | ||
institutions_file_path, | ||
":", | ||
e, | ||
"\n", | ||
file=sys.stderr, | ||
) | ||
|
||
# Get 5 random institutions in case of error | ||
if institutions is None or len(institutions) == 0: | ||
print("No institutions found in JSON file, fetching random institutions\n", file=sys.stderr) | ||
print( | ||
"No institutions found in JSON file, fetching random institutions\n", | ||
file=sys.stderr, | ||
) | ||
institutions = [Institutions().random() for _ in range(5)] | ||
|
||
return institutions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
def clamp_author_nodes_to_edges( | ||
author_nodes: list[dict], edges: list[dict] | ||
) -> list[dict]: | ||
author_ids = {x["start"] for x in edges} | ||
return [x for x in author_nodes if x["id"] in author_ids] | ||
|
||
def clamp_author_edges_to_nodes( | ||
author_edges: list[dict], nodes: list[dict] | ||
) -> list[dict]: | ||
author_ids = {x["id"] for x in nodes} | ||
return [x for x in author_edges if x["start"] in author_ids] | ||
def clamp_nodes_to_edge_start(nodes: list[dict], edges: list[dict]) -> list[dict]: | ||
edge_ids = {x["start"] for x in edges} | ||
return [x for x in nodes if x["id"] in edge_ids] | ||
|
||
|
||
def clamp_nodes_to_edge_end(nodes: list[dict], edges: list[dict]) -> list[dict]: | ||
edge_ids = {x["end"] for x in edges} | ||
return [x for x in nodes if x["id"] in edge_ids] | ||
|
||
|
||
def clamp_edge_start_to_nodes(edges: list[dict], nodes: list[dict]) -> list[dict]: | ||
node_ids = {x["id"] for x in nodes} | ||
return [x for x in edges if x["start"] in node_ids] | ||
|
||
|
||
def clamp_edge_end_to_nodes(edges: list[dict], nodes: list[dict]) -> list[dict]: | ||
node_ids = {x["id"] for x in nodes} | ||
return [x for x in edges if x["end"] in node_ids] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters