Skip to main content

Overview

Calculates the power losses of a tractor operating on specific terrain conditions. The calculation considers multiple loss factors including slope, altitude, rolling resistance, and wheel slippage. The result is persisted in the database with audit logging for historical tracking and analysis.

Loss Factors Calculated

The endpoint computes four primary loss factors:
  • Slope Loss: Power loss due to terrain inclination
  • Altitude Loss: Power loss due to altitude above sea level (air density reduction)
  • Rolling Resistance: Loss according to soil type (based on ASABE D497.7 Cone Index)
  • Slippage Loss: Power loss due to wheel slip

Authentication

This endpoint requires authentication via Bearer token in the Authorization header.
Authorization: Bearer <your_token>

Request Body

tractor_id
integer
required
ID of the tractor to evaluate. Must be a positive integer greater than 0.
terrain_id
integer
required
ID of the terrain where the tractor will operate. Must be a positive integer greater than 0.
working_speed_kmh
number
required
Working speed in kilometers per hour. Must be greater than 0 and less than 40 km/h.Validation: 0 < working_speed_kmh < 40
carried_objects_weight_kg
number
default:"0"
Weight of carried objects/implements in kilograms. Must be non-negative.Default: 0Validation: carried_objects_weight_kg >= 0
slippage_percent
number
default:"10"
Wheel slippage percentage. Typical values range from 5% to 20%.Default: 10

Response

success
boolean
Indicates whether the calculation was successful.
message
string
Human-readable message describing the result.
data
object
Container for calculation results.

Request Example

curl -X POST https://api.maqagr.com/api/calculations/power-loss \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "tractor_id": 1,
    "terrain_id": 1,
    "working_speed_kmh": 7.5,
    "carried_objects_weight_kg": 500,
    "slippage_percent": 10
  }'

Response Example

{
  "success": true,
  "message": "Cálculo realizado con éxito",
  "data": {
    "queryId": 123,
    "tractor": {
      "brand": "John Deere",
      "model": "7230R"
    },
    "terrain": {
      "name": "Campo Norte",
      "soil_type": "loam"
    },
    "losses": {
      "slope_loss_hp": 12.5,
      "altitude_loss_hp": 8.3,
      "rolling_resistance_loss_hp": 15.7,
      "slippage_loss_hp": 9.2,
      "total_loss_hp": 45.7
    },
    "net_power_hp": 184.3,
    "engine_power_hp": 230,
    "efficiency_percentage": 80.13
  }
}

Error Responses

400 Bad Request
object
Returned when required fields are missing or validation fails.
{
  "success": false,
  "message": "Faltan campos requeridos: tractor_id, terrain_id, working_speed_kmh"
}
Or for validation errors:
{
  "error": "working_speed_kmh debe ser menor a 40 km/h (velocidad agrícola razonable)"
}
401 Unauthorized
object
Returned when the authentication token is missing or invalid.
{
  "success": false,
  "message": "Token no proporcionado o inválido"
}
404 Not Found
object
Returned when the specified tractor or terrain is not found.
{
  "success": false,
  "message": "Tractor no encontrado"
}
Or:
{
  "success": false,
  "message": "Terreno no encontrado"
}
500 Internal Server Error
object
Returned when an unexpected error occurs during processing.
{
  "success": false,
  "message": "Error interno del servidor"
}

Validation Rules

ParameterTypeRequiredValidation
tractor_idintegerYesMust be > 0
terrain_idintegerYesMust be > 0
working_speed_kmhnumberYes0 < value < 40
carried_objects_weight_kgnumberYesMust be >= 0
slippage_percentnumberNoDefaults to 10

Soil Type Cone Index (Cn) Mapping

The rolling resistance calculation uses the ASABE D497.7 Cone Index standard:
Soil TypeCone Index (Cn)
Clay / Arcilla45
Loam / Franco35 (default)
Sand / Arena25
Firm / Firme50
Soft / Suave20

Notes

  • All calculations are persisted to the database with audit logging
  • The queryId can be used to retrieve calculation history via the /api/calculations/history endpoint
  • Default temperature of 15°C is used if not specified in terrain data
  • Results are logged for analytics and performance tracking (src/controllers/calculationController.js:144-152)

Build docs developers (and LLMs) love