Skip to content

Commit 850145a

Browse files
committed
feat(box): add map link field (fixes #43)
1 parent ebe3428 commit 850145a

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

routers/box.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from fastapi.responses import JSONResponse
33

44
from api import api_call
5-
from utils import extract_sn, normalize_items, remove_sn, status_to_str, list_to_str, str_to_list, get_coordinates
5+
from utils import extract_sn, normalize_items, remove_sn, status_to_str, list_to_str, str_to_list, get_coordinates, get_box_map_link
66

77
router = APIRouter(prefix='/box')
88

@@ -47,8 +47,9 @@ def _get_onu_level(name) -> float | None:
4747
api_call('task', 'get_list', f'house_id={id}&state_id=18,3,17,11,1,16,19')['list']
4848
))) if get_tasks else None,
4949
'manager_id': house.get('manage_employee_id'),
50-
'coord': get_coordinates(house['coordinates']),
51-
'active': not house.get('is_not_in_use', False),
50+
'coords': get_coordinates(house['coordinates']),
51+
'active': not house.get('is_not_use', True),
52+
'map_link': get_box_map_link(get_coordinates(house['coordinates']), id),
5253
'customers': customers
5354
}
5455
return JSONResponse({

utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,7 @@ def get_coordinates(polygon: list[list[float]]) -> list[float]:
188188
points = polygon[:-1]
189189
lats = [p[0] for p in points]
190190
lons = [p[1] for p in points]
191-
return [sum(lats) / len(lats), sum(lons) / len(lons)]
191+
return [sum(lats) / len(lats), sum(lons) / len(lons)]
192+
193+
def get_box_map_link(coords: list[float], box_id: int):
194+
return f'https://us.neotelecom.kg/map/show?opt_wh=1&by_building={box_id}&is_show_center_marker=1@{coords[0]},{coords[1]},18z'

0 commit comments

Comments
 (0)