new changes in the api

This commit is contained in:
2026-07-06 15:15:51 +05:30
parent c742ef0e53
commit 871981035a
43 changed files with 414 additions and 1975 deletions

View File

@@ -1,13 +1,9 @@
"""
High-performance utilities using Apache Arrow and NumPy for geographic data.
Provides vectorized operations for distances and coordinate processing.
Vectorized NumPy utilities for geographic distance calculations.
"""
import numpy as np
import pyarrow as pa
import pyarrow.parquet as pq
import logging
from typing import List, Dict, Any, Tuple
logger = logging.getLogger(__name__)
@@ -35,29 +31,3 @@ def calculate_haversine_matrix_vectorized(lats: np.ndarray, lons: np.ndarray) ->
c = 2 * np.arctan2(np.sqrt(a), np.sqrt(1 - a))
return R * c
def orders_to_arrow_table(orders: List[Dict[str, Any]]) -> pa.Table:
"""
Convert a list of order dictionaries to an Apache Arrow Table.
This enables zero-copy operations and efficient columnar storage.
"""
return pa.Table.from_pylist(orders)
def save_optimized_route_parquet(orders: List[Dict[str, Any]], filename: str):
"""
Save optimized route data to a Parquet file for high-speed analysis.
Useful for logging and historical simulation replays.
"""
try:
table = orders_to_arrow_table(orders)
pq.write_table(table, filename)
logger.info(f" Saved route data to Parquet: {filename}")
except Exception as e:
logger.error(f" Failed to save Parquet: {e}")
def load_route_parquet(filename: str) -> List[Dict[str, Any]]:
"""
Load route data from a Parquet file and return as a list of dicts.
"""
table = pq.read_table(filename)
return table.to_pylist()