[Traffic Intersection Agent] Websockets implementation for pushing updates in real-time#1815
Open
krish918 wants to merge 9 commits intoopen-edge-platform:mainfrom
Open
[Traffic Intersection Agent] Websockets implementation for pushing updates in real-time#1815krish918 wants to merge 9 commits intoopen-edge-platform:mainfrom
krish918 wants to merge 9 commits intoopen-edge-platform:mainfrom
Conversation
- Added more type hints. - Removed Optional NoneType from several fields. - For type compatibility at several places in code - Minor refactoring/formatting in some file - Update WeatherService for new logic to use cached data and forcing cache invalidation - Was done to avoid type incompatibility Signed-off-by: Krishna Murti <krishna.murti@intel.com>
- New /api/v1/traffic/current/ws endpoint based on websocket protocol - Mimics the functionality of /api/v1/traffic/current REST API - Updated DataAggregator service for creating and emitting an asyncio Event - emits events once vlm analysis is available. - A event loop in websocket endpoint listens for the event and sends response once event notif is receieved. - Minor refactoring in DataAggregator for handling types - Minor refactoring in VLMService for remove non-existent WeatherTypes Signed-off-by: Krishna Murti <krishna.murti@intel.com>
- websocket endpoint's images query param to have default value True
- Updated REST API and websocket's images query param to use Annotated
- Updated max size of websocket connection to allow transport of large base64 images
- Protected type casting of env var's value with 'or' operator
- for cases when env var value is empty '' and int('') will fail
Signed-off-by: Krishna Murti <krishna.murti@intel.com>
… scaling requests - Added gradios queues for handling multiple concurrent requests - Removed UI refresh and related components in favor of websocket connection - added two new async methods for fetching and handling traffic updates - fetch_intersection_data to connect to websocket endpoint - update_components to update UI based on data response from websocket - Both functions are run concurrently at UI load using interface.load() - Refactored data loader to inmplement new functions - Websocket conn uses large max_size to handle large base64 images - Asyncio queue used to put websocket responses in it - update_components picks from the queue once available and updates the UI - by yielding as soon as new data in queue is available - Added new websocket dependency in requirements.txt Signed-off-by: Krishna Murti <krishna.murti@intel.com>
- Minor refactoring in UIComponents apart from amking all methods async - Removed time format conversion method - 2 lines single use function - removed int type casting - already int type from API response - removed other unused functions Signed-off-by: Krishna Murti <krishna.murti@intel.com>
krish918
commented
Feb 19, 2026
| return request.app.state.weather_service | ||
|
|
||
|
|
||
| def _build_response_dict(traffic_response: Any, weather_data: Any, include_images: bool) -> Dict[str, Any]: |
Contributor
Author
There was a problem hiding this comment.
refactoring: Common method used for use with both REST API and Websocket endpoint.
krish918
commented
Feb 19, 2026
| weather_data = await weather_service.get_current_weather() | ||
|
|
||
| # Convert to dict for JSON response | ||
| response_dict = { |
Contributor
Author
There was a problem hiding this comment.
removed reusable code - to shift to common method.
krish918
commented
Feb 19, 2026
| @@ -129,7 +129,7 @@ async def get_current_weather(self, force_refresh: bool = False) -> Optional[Wea | |||
| """ | |||
| logger.info("Getting current weather data", force_refresh=force_refresh, has_cached=self._cached_weather is not None, use_mock=self.use_mock) | |||
|
|
|||
Contributor
Author
There was a problem hiding this comment.
unrelated change here: to avoid type incompatibility warning. slight change in cache validity check based on that.
krish918
commented
Feb 19, 2026
| except Exception as e: | ||
| logger.error(f"Error parsing API response: {str(e)}") | ||
| return None | ||
|
|
Contributor
Author
There was a problem hiding this comment.
removal of un-necessary indirection.
krish918
commented
Feb 19, 2026
| continue | ||
|
|
||
| return image_list | ||
|
|
Contributor
Author
There was a problem hiding this comment.
un-necessary unused method.
Signed-off-by: Krishna Murti <krishna.murti@intel.com>
Signed-off-by: Krishna Murti <krishna.murti@intel.com>
Signed-off-by: Krishna Murti <krishna.murti@intel.com>
yogeshmpandey
approved these changes
Mar 5, 2026
| markdown>=3.4.0 | ||
| requests>=2.25.0 No newline at end of file | ||
| requests>=2.25.0 | ||
| websockets>=15.0.0 No newline at end of file |
Contributor
There was a problem hiding this comment.
maybe we can use the latest versions of these.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces Websockets in Smart Traffic Intersection Agent, for pushing updates to clients in real-time (as soon as they are available).
Following changes have been introduced to implement this feature:
API Server Updates
UI Updates
Fixes # (issue)
Any Newly Introduced Dependencies
How Has This Been Tested?
end-to-end functional validation done.
Checklist: