Skip to content

Commit

Permalink
Merge pull request #96 from swisstopo/LGVISIUM-94-Renaming-of-the-out…
Browse files Browse the repository at this point in the history
…put-from-create_png-API-path

Close #LGVISIUM-94: Renaming of the output from create png api path
  • Loading branch information
dcleres authored Oct 25, 2024
2 parents 94afd15 + c62f834 commit 498a4e3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/app/api/v1/endpoints/create_pngs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
from fastapi import HTTPException


def create_pngs(aws_filename: Path):
def create_pngs(aws_filename: Path) -> PNGResponse:
"""Convert a PDF document to PNG images. Please note that this function will overwrite any existing PNG files.
Args:
aws_filename (str): The key of the PDF document in the S3 bucket. For example, "10012.pdf".
Returns:
PNGResponse: The URLs of the PNG images in the S3 bucket.
PNGResponse: The S3 keys of the PNG images in the S3 bucket.
"""
# Check if the PDF name is valid
if not aws_filename.suffix == ".pdf":
Expand All @@ -28,7 +28,7 @@ def create_pngs(aws_filename: Path):
# Initialize the S3 client
pdf_document = load_pdf_from_aws(aws_filename)

png_urls = []
s3_keys = []

# Convert each page of the PDF to PNG
try:
Expand All @@ -47,12 +47,12 @@ def create_pngs(aws_filename: Path):
s3_bucket_png_path, # The key (name) of the file in the bucket
)

# Generate the S3 URL
png_urls.append(s3_bucket_png_path)
# Save the generated the S3 keys as a list to return through the API
s3_keys.append(s3_bucket_png_path)

# Clean up the local file
os.remove(png_path)
except Exception:
raise HTTPException(status_code=500, detail="An error occurred while processing the PDF.") from None

return PNGResponse(png_urls=png_urls)
return PNGResponse(keys=s3_keys)
2 changes: 1 addition & 1 deletion src/app/common/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Config:
class PNGResponse(BaseModel):
"""Response schema for the create_pngs endpoint."""

png_urls: list[str]
keys: list[str] # keys in the S3 bucket


########################################################################################################################
Expand Down
6 changes: 3 additions & 3 deletions tests/test_create_pngs.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ def test_create_pngs_success(test_client: TestClient, s3_client, upload_test_pdf
response = test_client.post("/api/V1/create_pngs", json={"filename": TEST_PDF_KEY.rsplit("/", 1)[-1]})
assert response.status_code == 200
json_response = response.json()
assert "png_urls" in json_response
assert len(json_response["png_urls"]) > 0
assert "keys" in json_response
assert len(json_response["keys"]) > 0

# Verify that PNG files are uploaded to S3
for png_url in json_response["png_urls"]:
for png_url in json_response["keys"]:
try:
s3_client.head_object(Bucket=config.test_bucket_name, Key=png_url)
except ClientError:
Expand Down

1 comment on commit 498a4e3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/stratigraphy
   __init__.py8188%11
   extract.py1921920%3–477
   get_files.py19190%3–47
   main.py1191190%3–314
src/stratigraphy/benchmark
   ground_truth.py21195%47
src/stratigraphy/data_extractor
   data_extractor.py57395%33, 66, 103
src/stratigraphy/depthcolumn
   boundarydepthcolumnvalidator.py412051%47, 57, 60, 81–84, 110–128, 140–149
   depthcolumn.py2238064%25, 29, 50, 67, 72, 78, 86–92, 113, 116, 124–125, 141–143, 150, 157, 165–166, 176, 193–209, 247, 255–256, 272–274, 312, 331–339, 350, 355, 362, 393, 398–405, 420–421, 464–506
   depthcolumnentry.py361072%17, 21, 37, 52, 55, 72, 81, 98–100
   find_depth_columns.py1061982%42–43, 73, 86, 180–181, 225–245
src/stratigraphy/depths_materials_column_pairs
   depths_materials_column_pairs.py18667%23, 34, 55–59
src/stratigraphy/evaluation
   evaluation_dataclasses.py491667%24, 33, 42–44, 52, 71–74, 90, 104, 125–131, 137
   metadata_evaluator.py381463%52–71, 94–101
src/stratigraphy/groundwater
   groundwater_extraction.py1479833%44, 52, 83, 98, 106, 125, 152–156, 171–191, 202–291, 307–339
   utility.py393315%10–17, 30–47, 59–73, 88–102
src/stratigraphy/layer
   layer.py371851%29, 39, 57–94, 106–107
   layer_identifier_column.py745230%16–17, 20, 28, 43, 47, 51, 59–63, 66, 74, 91–96, 99, 112, 125–126, 148–158, 172–199
src/stratigraphy/lines
   geometric_line_utilities.py86298%81, 131
   line.py51492%25, 50, 60, 110
   linesquadtree.py46198%75
src/stratigraphy/metadata
   coordinate_extraction.py108595%30, 64, 94–95, 107
   elevation_extraction.py795234%34, 42, 50, 66–69, 106–120, 132–135, 147–179, 194–202, 210–214
   language_detection.py181328%17–23, 37–45
   metadata.py662464%27, 83, 101–127, 146–155, 195–198, 206
src/stratigraphy/text
   description_block_splitter.py70297%24, 139
   extract_text.py29390%19, 53–54
   find_description.py642856%27–35, 50–63, 79–95, 172–175
   textblock.py80989%28, 56, 64, 89, 101, 124, 145, 154, 183
src/stratigraphy/util
   dataclasses.py32391%37–39
   interval.py1045547%29–32, 37–40, 46, 52, 56, 66–68, 107–153, 174, 180–196
   predictions.py1054161%74–78, 86–94, 171–203, 242, 265–283
   util.py391756%41, 69–76, 90–92, 116–117, 129–133
TOTAL220796057% 

Tests Skipped Failures Errors Time
88 0 💤 0 ❌ 0 🔥 7.043s ⏱️

Please sign in to comment.