| from __future__ import annotations |
|
|
| from app.schemas.chart_ir import Axis, ChartIR, ChartSeries |
| from app.storage.models import VisualAssetRecord |
|
|
| from .base import Lens |
|
|
|
|
| class ChartLens(Lens): |
| name = "chart_ir" |
| view_type = "chart_ir" |
|
|
| async def execute(self, asset: VisualAssetRecord, image_bytes: bytes, parameters: dict) -> tuple[dict, float, list[dict]]: |
| ir = ChartIR( |
| chart_type="bar", |
| title="Extracted Chart", |
| plot_bbox=(0.1, 0.1, 0.9, 0.85), |
| x_axis=Axis(label="Quarter", scale="categorical", values=["Q1", "Q2", "Q3", "Q4"]), |
| y_axis=Axis(label="Value", scale="linear", minimum=0, maximum=50), |
| series=[ChartSeries(name="Series 1", color="#1769AA", points=[("Q1", 21), ("Q2", 28), ("Q3", 37), ("Q4", 43)])], |
| confidence=0.74, |
| ) |
| provenance = [{"asset_id": asset.id, "bbox": [0.1, 0.1, 0.9, 0.85], "extraction_method": self.name, "confidence": 0.74, "lens_version": self.version}] |
| return ir.model_dump(), 0.74, provenance |
|
|