Spaces:
Runtime error
Runtime error
Commit ·
b33518d
1
Parent(s): a14996c
refactor: Remove temporary file handling in data transformation process
Browse files
app.py
CHANGED
|
@@ -125,9 +125,6 @@ async def get_supported_formats():
|
|
| 125 |
return [format.value for format in FileFormat]
|
| 126 |
|
| 127 |
|
| 128 |
-
<<<<<<< HEAD
|
| 129 |
-
# ---------------------------
|
| 130 |
-
=======
|
| 131 |
@app.get("/formats/processing", tags=["Information"])
|
| 132 |
async def get_format_processing_methods():
|
| 133 |
"""Get processing methods for each file format (in-memory vs temp-file)."""
|
|
@@ -151,7 +148,6 @@ async def get_format_processing_methods():
|
|
| 151 |
}
|
| 152 |
|
| 153 |
|
| 154 |
-
>>>>>>> 0b4afac0e86141035d981bd132d8ee08dabc671e
|
| 155 |
# Core transformation endpoints
|
| 156 |
# ---------------------------
|
| 157 |
|
|
@@ -168,56 +164,6 @@ async def transform_data(request: TransformationRequestModel):
|
|
| 168 |
try:
|
| 169 |
if not request.data:
|
| 170 |
raise HTTPException(status_code=400, detail="No data provided")
|
| 171 |
-
<<<<<<< HEAD
|
| 172 |
-
|
| 173 |
-
# Create temporary JSON file
|
| 174 |
-
import json
|
| 175 |
-
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as temp_file:
|
| 176 |
-
json.dump(request.data, temp_file)
|
| 177 |
-
temp_path = temp_file.name
|
| 178 |
-
|
| 179 |
-
try:
|
| 180 |
-
# Create transformation request
|
| 181 |
-
transform_request = TransformationRequest(
|
| 182 |
-
auto_select_erp=request.auto_select_erp,
|
| 183 |
-
auto_select_entity=request.auto_select_entity,
|
| 184 |
-
entity=request.entity,
|
| 185 |
-
erp=request.erp,
|
| 186 |
-
file_data=temp_path,
|
| 187 |
-
file_format=FileFormat.JSON
|
| 188 |
-
)
|
| 189 |
-
|
| 190 |
-
# Perform transformation
|
| 191 |
-
result = transformation_engine.transform(transform_request)
|
| 192 |
-
|
| 193 |
-
# Convert result to API response
|
| 194 |
-
response_data = None
|
| 195 |
-
if result.success and result.data is not None:
|
| 196 |
-
response_data = transformation_engine.data_processor.to_dict(result.data)
|
| 197 |
-
|
| 198 |
-
processing_time = (time.time() - start_time) * 1000
|
| 199 |
-
|
| 200 |
-
return TransformationResponseModel(
|
| 201 |
-
success=result.success,
|
| 202 |
-
data=response_data,
|
| 203 |
-
detected_erp=result.detected_erp,
|
| 204 |
-
detected_entity=result.detected_entity,
|
| 205 |
-
transformation_mode=result.transformation_mode.value if result.transformation_mode else None,
|
| 206 |
-
confidence_score=result.confidence_score,
|
| 207 |
-
message=result.message,
|
| 208 |
-
column_mappings=result.column_mappings,
|
| 209 |
-
row_count=len(response_data) if response_data else 0,
|
| 210 |
-
processing_time_ms=processing_time
|
| 211 |
-
)
|
| 212 |
-
|
| 213 |
-
finally:
|
| 214 |
-
# Clean up temporary file
|
| 215 |
-
try:
|
| 216 |
-
os.unlink(temp_path)
|
| 217 |
-
except OSError:
|
| 218 |
-
pass
|
| 219 |
-
|
| 220 |
-
=======
|
| 221 |
|
| 222 |
# Convert JSON data to bytes for in-memory processing (no temp files)
|
| 223 |
import json
|
|
@@ -256,7 +202,6 @@ async def transform_data(request: TransformationRequestModel):
|
|
| 256 |
processing_time_ms=processing_time
|
| 257 |
)
|
| 258 |
|
| 259 |
-
>>>>>>> 0b4afac0e86141035d981bd132d8ee08dabc671e
|
| 260 |
except Exception as e:
|
| 261 |
logger.error(f"Transform data failed: {e}")
|
| 262 |
raise HTTPException(status_code=500, detail=f"Transformation failed: {str(e)}")
|
|
|
|
| 125 |
return [format.value for format in FileFormat]
|
| 126 |
|
| 127 |
|
|
|
|
|
|
|
|
|
|
| 128 |
@app.get("/formats/processing", tags=["Information"])
|
| 129 |
async def get_format_processing_methods():
|
| 130 |
"""Get processing methods for each file format (in-memory vs temp-file)."""
|
|
|
|
| 148 |
}
|
| 149 |
|
| 150 |
|
|
|
|
| 151 |
# Core transformation endpoints
|
| 152 |
# ---------------------------
|
| 153 |
|
|
|
|
| 164 |
try:
|
| 165 |
if not request.data:
|
| 166 |
raise HTTPException(status_code=400, detail="No data provided")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
# Convert JSON data to bytes for in-memory processing (no temp files)
|
| 169 |
import json
|
|
|
|
| 202 |
processing_time_ms=processing_time
|
| 203 |
)
|
| 204 |
|
|
|
|
| 205 |
except Exception as e:
|
| 206 |
logger.error(f"Transform data failed: {e}")
|
| 207 |
raise HTTPException(status_code=500, detail=f"Transformation failed: {str(e)}")
|