Skip to content
  • There are no suggestions because the search field is empty.

Calculations

This article explains calculations in ONE RACEHUB

Calculations are user functions to calculate values which are not directly stored in the database. They can be used for different purposes which are presented in the scope section.

There are some example functions at the end of the article.

Defining Calculations

Clicking on calculations will present a list of existing calculations. Add a new calculation using the "Add Calculation" button. The ensuing dialog presents:

add-formula-dialog

1. Enter the name of the formula
2. Enter the scope of the formula
3. Enter the version of the formula. This is not used internally and is only to facilitate organizing
4. Enter the parameter result name
5. If the formula is set to "active" ONE RACEHUB will use it
6. Define the function string

Scope (Type)

Each formula has a scope. The available scopes are:

- Car Setup (can be used on the flexible setup sheet / to use them they need to be added to the chassis specification)
- Data Service (will be downloaded by car data service and used in kpi calculation)
- KPI (not yet implemented)
- Lap (will be calculated for each lap)
- RunSheet (not yet implemented)

Function string

The function string will define the calculation result of the formula. Variables in the function string can be defined with the keyword "var"

var wheelBase = 2.5;

Data values are prefixed with a $. Use the schema documentation to understand the available variables. The following scopes are available:

- $runsheet: all values stored in the runsheet document
- $lap: all values stored in the lap document
- $setup: all values stored in the car setup document

Math functions in the function string

Car Data Service (DATA_SERVICE)

Formulas intended to be used for the data service will use c# syntax. Therefore c# math functions are allowed. Please refer to c# math class documentation for details.

If statements on car data service

If statements can be used in car data service to generate conditional values. Consider the following example for an average vehicle velocity in pitlane KPI:

Create a vCarPitlane calculation with the following formula:

if (($BCarInPitlane) == 1)
{
  return ($vCar);
}
else
{
   return double.NaN;
}

In this case use MeanNan as kpi for vCarInPitlane to get the average vehicle velocity when the car is in pitlane condition.

Function chaining for car data service functions

Calculations with the DATA_SERVICE scope can use the result of other calculations in the same manner as they would use a parameter. 

Car Setup / KPI / Lap / Runsheet

Formulas intended to be used for non data service purposes use javascript as underyling structure. The Math Class can be used. For convenicence reasons a conversion from c# to javascript is done.

Null / undefined checks on Car Setup / KPI / Lap / Runsheet

Since formulas for the front end are using javascript, a null check with ?? is possible.

Examples

Average damper travel in car data

Assuming your damper travel channel in the car data is called "xDamperXX". The type is "DATA_SERVICE":

return ($xDamperFL + $xDamperFR) / 2;

Simple ride height channel

Assuming your damper travel channel in the car data is called "xDamperXX", the ride height on the car is measured at the axle level and the motion ratio between damper travel and ride height is 1. The type is "DATA_SERVICE":

return $setup.front.hRide - ($xDamperFL + $xDamperFR) / 2;

Laptime ratio

The ratio of the current laptime against the fastest laptime of a given run. The type is "LAP":

return ($lap.tLapMax/$runsheet.fastestLap);

Pythagorean Theorem

As an example on how to use math functions:

return Math.Sqrt(Math.Pow($a,2)+Math.Pow($b,2));