- Backend
- API Documentation
- MemoryStore
- new MemoryStore()
- memoryStore.setPositionFromDroneMessage(message) ⇒
Object
- memoryStore.getDataForDashboard() ⇒
Object
- memoryStore.getDataForDashboardById(droneId) ⇒
Object
- memoryStore.getPositionById(droneID) ⇒
Array
|null
℗ - memoryStore.getPosition() ⇒
Object
|null
℗ - memoryStore.setPositionById(droneID, position) ℗
- memoryStore.validatePosition() ℗
- memoryStore.parsePosition(message) ⇒
Object
℗ - memoryStore.calculateSpeed(droneId) ⇒
Object
℗ - memoryStore.setSpeedById(droneId, speed) ℗
- memoryStore.getSpeedById(droneId) ⇒
Object
|null
℗ - memoryStore.getSpeed() ⇒
Object
|null
℗ - memoryStore.onLocationUpdate(droneId) ℗
- memoryStore.flagStationaryDrones(droneId) ℗
- memoryStore.findPositionInInterval(droneId, timestamp, start, range) ⇒
Object
℗ - memoryStore.setDroneFlag(droneId) ℗
- memoryStore.unsetDroneFlag(droneId) ℗
- MemoryStore
- Scalability
- No. of messages the backend can handle per second
- No. of dashboards the backend can serve simultaneously
- Real-time updates
- The backend should be able to publishe the location updates received from the drones to the dashboard in real time
Responsibilities
- Ingest - Ingesting position data sent by drones
- Store - Storing position data
- Process - Processing position data to get speeds for the respective drones and flagging stationary drones
- Serve - API to serve real-time position (& speed) data to front-end
Basis for the above Design
-
The backend has been split into 3 components each handling one major responsibility. This is to achieve modularity and ease to extend the respective components based on future requirements
-
The components are connected to each other via events. For instance the MemoryStore fires a
drone-updated
event when the location of a drone is updated. This is received by the Express API which updates the dashboard accordingly -
The separation of the UDP server (used to ingest data) from any kind of processing of the data allows to improve performance of data ingestion (number of messages received per second). This also helps reduce the number of lost data packets
-
To serve real time updates to the dashboard
socket.io
module has been used which allows for real-time bidirectional communication
-
The MemoryStore is divided into three key responsibilities
- Store position data
- Process position data to generate speed or flag stationary drones
- Interface to fetch data from MemoryStore in the format required by the Express API
-
The sub-division across the three responsibilities allows to extend the code to satisfy future requirements with ease
- Other kinds of processing on the location data can be introduced by subscribing to the event
location-updated
- The data from the MemoryStore can be formatted to serve other endpoints (in addition to the Dashboard). For this additional interfaces can be added by subscribing to the event
drone-updated
- Other kinds of processing on the location data can be introduced by subscribing to the event
The MemoryStore is an in-memory storage
Kind: global class
- MemoryStore
- new MemoryStore()
- .setPositionFromDroneMessage(message) ⇒
Object
- .getDataForDashboard() ⇒
Object
- .getDataForDashboardById(droneId) ⇒
Object
- .getPositionById(droneID) ⇒
Array
|null
℗ - .getPosition() ⇒
Object
|null
℗ - .setPositionById(droneID, position) ℗
- .validatePosition() ℗
- .parsePosition(message) ⇒
Object
℗ - .calculateSpeed(droneId) ⇒
Object
℗ - .setSpeedById(droneId, speed) ℗
- .getSpeedById(droneId) ⇒
Object
|null
℗ - .getSpeed() ⇒
Object
|null
℗ - .onLocationUpdate(droneId) ℗
- .flagStationaryDrones(droneId) ℗
- .findPositionInInterval(droneId, timestamp, start, range) ⇒
Object
℗ - .setDroneFlag(droneId) ℗
- .unsetDroneFlag(droneId) ℗
Create a MemoryStore
This method takes a message from the UDP server and stores the position for that drone
Kind: instance method of MemoryStore
Returns: Object
- Position object (with droneId)
Access: public
Param | Type | Description |
---|---|---|
message | Buffer |
Message encapsulating location data received on the UDP server |
This method returns speed data for all the drones along with a flag to specify if they should be highlighted or not on the dashboard
Kind: instance method of MemoryStore
Returns: Object
- Speed data for all the drones and their respective highlight flags
Access: public
This method returns the speed data and highlight flag for a specific drone given by the droneId
Kind: instance method of MemoryStore
Returns: Object
- Speed data for a drone and its highlight flag
Access: public
Param | Type |
---|---|
droneId | String |
Returns the position array for the provided droneId
Kind: instance method of MemoryStore
Returns: Array
| null
- An array of the droneId's positions or null if droneId is not found
in MemoryStore
Access: private
Param | Type |
---|---|
droneID | String |
Returns the position data for all the droneIds
Kind: instance method of MemoryStore
Returns: Object
| null
- An object containing data for all the droneIds positions or null if
MemoryStore is empty
Access: private
This method appends the position for the droneId in the MemoryStore
Kind: instance method of MemoryStore
Access: private
Param | Type | Description |
---|---|---|
droneID | String |
DroneId |
position | Object |
Representing position data for the drone |
To be implemented in the next version. This method is used to validate the position data - Latitude and Longitude
Kind: instance method of MemoryStore
Access: private
This method parses the message received on the UDP server into a JSON object representing position. If the received message does not fit the expected structure it is discarded
Kind: instance method of MemoryStore
Returns: Object
- Position data
Access: private
Param | Type | Description |
---|---|---|
message | String |
Concatenated string of droneId, latitude, longitude and timestamp |
This method uses the two most recent positions of a drone to calculate its speed
Kind: instance method of MemoryStore
Returns: Object
- Returns the speed for the drone
Access: private
Param | Type | Description |
---|---|---|
droneId | String |
Unique identifier for drone |
This method stores the speed for a drone in MemoryStore
Kind: instance method of MemoryStore
Access: private
Param | Type |
---|---|
droneId | String |
speed | Object |
This method is used to retrieve the speed for a drone
Kind: instance method of MemoryStore
Returns: Object
| null
- Speed data for a droneId
Access: private
Param | Type |
---|---|
droneId | String |
This method is used to retrieve the speed data for all the drones
Kind: instance method of MemoryStore
Returns: Object
| null
- Speed data for all the drones
Access: private
This method is triggered on event location-updated
and calculates the speed for that
drone using the two most recent positions and stores them in MemoryStore
Kind: instance method of MemoryStore
Access: private
Param | Type |
---|---|
droneId | String |
This method is triggered on location-update
event. It checks for and highlights stationary
drones (Drones that have covered a displacement of less than 1m in 10 seconds). If a drone
is highlighted the function triggers drone-updated
event.
Kind: instance method of MemoryStore
Access: private
Param | Type |
---|---|
droneId | String |
This method checks the position data for a drone and returns a position between an interval The interval is defined between (timestamp - start) and (timestamp - start- range)
Kind: instance method of MemoryStore
Returns: Object
- Position data
Access: private
Param | Type | Description |
---|---|---|
droneId | String |
|
timestamp | number |
In milliseconds |
start | number |
In milliseconds |
range | number |
In milliseconds |
This method sets the highlight flag for the given droneId to true
Kind: instance method of MemoryStore
Access: private
Param | Type |
---|---|
droneId | String |
This methods sets the highlight flag for the given droneId to false
Kind: instance method of MemoryStore
Access: private
Param | Type |
---|---|
droneId | String |