Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions log_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"default": {
"()": "uvicorn.logging.DefaultFormatter",
"fmt": "%(asctime)s - %(levelprefix)s (%(funcName)s) %(message)s",
"use_colors": null
},
"access": {
"()": "uvicorn.logging.AccessFormatter",
"fmt": "%(asctime)s - %(levelprefix)s %(client_addr)s - \"%(request_line)s\" %(status_code)s"
}
},
"handlers": {
"default": {
"formatter": "default",
"class": "logging.StreamHandler",
"stream": "ext://sys.stderr"
},
"access": {
"formatter": "access",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout"
}
},
"loggers": {
"uvicorn": {
"handlers": [
"default"
],
"level": "INFO",
"propagate": false
},
"uvicorn.error": {
"level": "DEBUG"
},
"uvicorn.access": {
"handlers": [
"access"
],
"level": "INFO",
"propagate": false
}
}
}
23 changes: 19 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
import uuid
from typing import Dict, Any
from pathlib import Path
import logging
from anyio import open_file


# Log to uvicorn general-purpose server logger
logger = logging.getLogger('uvicorn.error')


app = FastAPI(
title="NetworkX Graph API",
Expand Down Expand Up @@ -283,16 +290,20 @@ async def get_node_type_counts(graph_id: str):
Returns:
A JSON object containing the count of nodes for each type.
"""
logger.debug("Calling.")
# Check if graph ID exists in registry
if graph_id not in graph_registry:
raise HTTPException(status_code=404, detail="Graph ID not found")

try:
# Load the graph from file
file_path = graph_registry[graph_id]
with open(file_path, 'r') as f:
data = json.load(f)
async with await open_file(file_path, 'r') as f:
logger.debug("Opening file.")
content = await f.read()
logger.debug("Closing file.")

data = json.loads(content)
# Load as NetworkX graph
graph = nx.node_link_graph(data)

Expand Down Expand Up @@ -328,16 +339,20 @@ async def get_edge_type_counts(graph_id: str):
Returns:
A JSON object containing the count of edges for each type.
"""
logger.debug("Calling.")
# Check if graph ID exists in registry
if graph_id not in graph_registry:
raise HTTPException(status_code=404, detail="Graph ID not found")

try:
# Load the graph from file
file_path = graph_registry[graph_id]
with open(file_path, 'r') as f:
data = json.load(f)
async with await open_file(file_path, 'r') as f:
logger.debug("Opening file.")
content = await f.read()
logger.debug("Closing file.")

data = json.loads(content)
# Load as NetworkX graph
graph = nx.node_link_graph(data)

Expand Down