Training Simulator

URL: <base-url>/backend/hrc#/simulator
Directory: VaahCms/Modules/HRC/Vue/pages/simulator
Controller: VaahCms/Modules/HRC/Http/Controllers/Backend/SimulatorController.php
Model: None
Store: VaahCms/Modules/HRC/Vue/store/modules/store-simulator.js

Description

The live preview of the horse training works when the EHM Device send data regarding horse to the API and the Live Training Centers page starts receiving the live data. But during the development or maintenance it is not ideal to have a real horse around to do testing. So we have created the Simulator that can simulate the device as if a horse is in a race course and this will send the data to the Equetronic API. The simulated training can be previewed in real time from the Live Training Centers Page.

Race Course Management

Purpose

  • To simulate the device sending data to Equetronic API.
  • To Mimic various data points such as is_horse_standing, has_no_GPS etc.
  • To import an existing data set and simulate as if it is happening in real time.

Start simulation

  • If you are working on a local machine, then first open up your Equetronic API project and run the following command
    npm run start

    This will start your node server, where your API is hosted. (usually: http://127.0.0.1:5000/)
  • Then open the Training Simulator Page.
  • You will find that at the top there is a field that defines the API endpoint API Endpoint Field By default it will take the value set in WEBSOCKET_API_ENPOINT in your .env
  • Select the mode of simulation. There are two options
    1. Auto Generate: This will generate random ehm data values for a given horse. This is good for quick testing of API and any other cosmetic features.
    2. Import File: You can import a json file that contains accurate ehm data of any previous training records. This is useful if we want to re-simulate any training record and debug any issue.

    Mode Of Simulation
  • If you have selected the Auto Generate mode then, search and select the horse you want to simulate. Search Horse
  • If you have selected the Import File mode then, an upload button would appear, and upload your sample file.

    on the right hand side you will find a sample file


    Upload Simulator File
    Note: As soon as the horse is selected by dropdown or from the uploaded file, the simulator will send /initialize request to the API with the horse RFID, thus creating a session.
  • Click on the Start button. This will start sending data to the API. Then you will be able to see the data being sent. Simulator Data
  • You can go to the Live Training Page and select the race course and the horse to see the live preview.

Important Note: Due to restrictions by the browser memory management, if the simulator page is not visible on screen then the page will temporarily pause. To avoid this after starting the simulation, it is recommended to take the simulator page in a separate window resize it and keep it open the screen.

Here is an example

Methods

update(name, value)

Updates state value using $vaah.updateState() method

Arguments
NameTypeDescription
nameanythe name of the state
valueanythe new value of the state
Return
TypeDescriptionExample
undefinedno return valueN/A
Usage
Example
this.update('state_name', 'state_value')

updateView()

Dispatches Vuex action to update view with $store.dispatch()

Arguments
NameTypeDescription
N/AN/AN/A
Return
TypeDescriptionExample
undefinedno return valueN/A
Usage
Example
this.updateView()

onLoad()

Calls getAssets() method to get assets data

Arguments
NameTypeDescription
N/AN/AN/A
Return
TypeDescriptionExample
undefinedno return valueN/A
Usage
Example
this.onLoad()

async getAssets()

Dispatches Vuex action to get assets data asynchronously using $store.dispatch()

Arguments
NameTypeDescription
N/AN/AN/A
Return
TypeDescriptionExample
undefinedno return valueN/A
Usage
Example
await this.getAssets()

setHorse(item)

Sets selected horse and initializes the API using apiInitialize() method

Arguments
NameTypeDescription
itemobjectthe horse object to select
Return
TypeDescriptionExample
undefinedno return valueN/A
Usage
Example
this.setHorse(horse)

apiInitialize()

Initializes API using $vaah.ajax() method and sets API send request data

Arguments
NameTypeDescription
N/AN/AN/A
Return
TypeDescriptionExample
undefinedno return valueN/A
Usage
Example
this.apiInitialize()

apiInitializeAfter(data, res)

Callback function after apiInitialize() method, finishes progress bar, sets API initialize response data and sets API send request data

Arguments
NameTypeDescription
dataobjectthe API response data
resobjectthe API response object
Return
TypeDescriptionExample
undefinedno return valueN/A
Usage

This function is called internally after the apiInitialize() method.


start()

Starts the simulator and sends sensor data to the API.

Arguments
NameTypeDescription
N/AN/AN/A
Return
TypeDescriptionExample
undefinedNo return valueN/A
Usage
// Example usage
this.start();

stop()

Stops the simulator.

Arguments
NameTypeDescription
N/AN/AN/A
Return
TypeDescriptionExample
undefinedNo return valueN/A
Usage
// Example usage
this.stop();

setSensorDataToSend(records)

Generates sensor data and sets it to the sensor_data_to_send array.

Arguments
NameTypeDescription
recordsNumberThe number of sensor data records to generate.
Return
TypeDescriptionExample
undefinedNo return valueN/A
Usage
// Example usage
this.setSensorDataToSend(150);

convertToDeviceFormat(coordinate)

Converts a coordinate from a specific format to the device format.

Arguments
NameTypeDescription
coordinateStringThe coordinate value to convert.
Return
TypeDescriptionExample
StringThe converted coordinate value.N/A
Usage
// Example usage of convertToDeviceFormat method
const coordinate = "N35°55'47.5786";
const deviceCoordinate = this.convertToDeviceFormat(coordinate);
console.log(deviceCoordinate); // Output: 355547.5786N

setImportedDataToSend()

This method sets the data to be sent to the API by pushing the items from imported_data array to sensor_data_to_send array in reverse order.

Arguments
NameTypeDescription
N/AN/AThis method doesn't take any arguments.
Return
TypeDescriptionExample
N/AThis method doesn't return anything.N/A
Usage Example
Example
  // usage examples with output mentioned in comments

  // Example 1
  this.setImportedDataToSend();

getRandomArbitrary(min, max)

This method returns a random number between min and max.

Arguments
NameTypeDescription
minnumberThe minimum value of the range.
maxnumberThe maximum value of the range.
Return
TypeDescriptionExample
numberThe random number between min and max.4.67
Usage Example
Example
  // usage examples with output mentioned in comments

  // Example 1
  let randomNumber = this.getRandomArbitrary(1, 10);
  console.log(randomNumber); // output: 7.42

sendSensorDataToApi(i)

This method sends sensor data to the API by making an AJAX call to the websocket API endpoint with the item at index i of sensor_data_to_send array as the parameters.

Arguments
NameTypeDescription
inumberThe index of the item to be sent to the API in sensor_data_to_send array.
Return
TypeDescriptionExample
N/AThis method doesn't return anything.N/A
Usage Example
Example
  // usage examples with output mentioned in comments

  // Example 1
  this.sendSensorDataToApi(0);

  // Example 2
  for(let i=0; i<this.sensor_data_to_send.length; i++){
    this.sendSensorDataToApi(i);
  }

sendSensorDataToApiAfter(data)

This method is called after the API call made by sendSensorDataToApi() method is completed.

Arguments
NameTypeDescription
dataanyThe response data returned by the API.
Return
TypeDescriptionExample
N/AThis method doesn't return anything.N/A
Usage Example
Example
  // usage examples with output mentioned in comments

  // Example 1
  this.sendSensorDataToApiAfter({"status": "success", "message": "Data sent successfully"});

  // Example 2
  let self = this;
  this.$vaah.ajax(url, params, function(data){
    self.sendSensorDataToApiAfter(data);
  });

readData()

This method reads a file and populates the imported data list with the file's contents.

Arguments

None

Return

None

Usage Example
Example

Assumptions

  • The Equetronic API is functional
  • The endpoint provided for API is correct
  • The selected horse is associated with a Training Center
  • In case of uploaded file, it has correct format

Acceptance Criteria

  • The dropdown for horses should be searchable
  • Sample file must be downloadable
  • When horse is selected, initiation request must be passed
  • When start is pressed it should show the data being sent