Skip to content

Commit

Permalink
change fetching by filetype
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldcampbelljr committed Sep 27, 2023
1 parent ad88578 commit b12976a
Showing 1 changed file with 17 additions and 55 deletions.
72 changes: 17 additions & 55 deletions pipestatreader/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import uvicorn
from typing import Optional
from pipestat import RecordNotFoundError, SamplePipestatManager
from pipestat.reports import fetch_pipeline_results
from pydantic import BaseModel


_LOGGER = logging.getLogger(__name__)

app = fastapi.FastAPI(
Expand Down Expand Up @@ -94,60 +96,22 @@ async def retrieve_table_contents():
return {"table_contents": results}


@app.get("/images/")
async def retrieve_images(pipeline_type: Optional[str] = None):
"""
Get all image paths reported in the table.
"""
list_columns = []
if pipeline_type == "sample":
for k, v in psm.schema._sample_level_data.items():
if v["type"] == "image":
list_columns.append(k)
return {"Image Results": psm.backend.select(columns=list_columns)}
if pipeline_type == "project":
for k, v in psm.schema._project_level_data.items():
if v["type"] == "image":
list_columns.append(k)
return {"Image Results": psm.backend.select(columns=list_columns)}
if pipeline_type is None:
if psm.schema._sample_level_data:
for k, v in psm.schema._sample_level_data.items():
if v["type"] == "image":
list_columns.append(k)
if psm.schema._project_level_data:
for k, v in psm.schema._project_level_data.items():
if v["type"] == "image":
list_columns.append(k)
return {"Image Results": psm.backend.select(columns=list_columns)}


@app.get("/files/")
async def retrieve_files(pipeline_type: Optional[str] = None):
@app.get("/{file_type}/")
async def retrieve_filetype(file_type: str):
"""
Get all file paths reported in the table.
Get all records by filetype
"""
list_columns = []
if pipeline_type == "sample":
for k, v in psm.schema._sample_level_data.items():
if v["type"] == "file":
list_columns.append(k)
return {"File Results": psm.backend.select(columns=list_columns)}
if pipeline_type == "project":
for k, v in psm.schema._project_level_data.items():
if v["type"] == "file":
list_columns.append(k)
return {"File Results": psm.backend.select(columns=list_columns)}
if pipeline_type is None:
if psm.schema._sample_level_data:
for k, v in psm.schema._sample_level_data.items():
if v["type"] == "file":
list_columns.append(k)
if psm.schema._project_level_data:
for k, v in psm.schema._project_level_data.items():
if v["type"] == "file":
list_columns.append(k)
return {"File Results": psm.backend.select(columns=list_columns)}
records_by_filetype = []
all_records = psm.get_records()["records"]
for sample in all_records:
file_result = fetch_pipeline_results(
project=psm,
pipeline_name=psm.pipeline_name,
sample_name=sample,
inclusion_fun=lambda x: x == file_type,
)
records_by_filetype.append(file_result)
return {"records_by_filetype": records_by_filetype}


@app.post("/filtered_table_contents/")
Expand Down Expand Up @@ -196,10 +160,8 @@ def main():
pipestatcfg = args.config

create_global_pipestatmanager(pipestatcfg)
# global psm
# psm = SamplePipestatManager(config_file=pipestatcfg)

uvicorn.run("reader:app", host="0.0.0.0", port=8000, reload=True)
uvicorn.run("reader:app", host="0.0.0.0", port=8001, reload=True)


if __name__ == "__main__":
Expand Down

0 comments on commit b12976a

Please sign in to comment.