Skip to main content

Overview

Calculates the minimum power required to operate an agricultural implement on specific terrain, and classifies available tractors by compatibility using an intelligent recommendation system. The endpoint evaluates all available tractors and categorizes them into three suitability levels: OPTIMAL, OVERPOWERED, or INSUFFICIENT.

Tractor Classification System

Tractors are classified based on their power utilization efficiency:
  • OPTIMAL (Green): Power between 100-125% of required (perfect fit)
  • OVERPOWERED (Yellow): Power >125% of required (oversized but compatible)
  • INSUFFICIENT (Red): Power below required (not compatible)

Factors Considered

The calculation considers:
  • Base power requirement of the implement (HP)
  • Working depth
  • Soil type
  • Terrain slope percentage

Authentication

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

Request Body

implement_id
integer
required
ID of the agricultural implement to evaluate. Must be a positive integer greater than 0.
terrain_id
integer
required
ID of the terrain where the implement will operate. Must be a positive integer greater than 0.
working_depth_m
number
Override for working depth in meters. If not provided, uses the implement’s default working depth.Validation: 0 < working_depth_m <= 1.0Default: Uses implement’s working_depth_cm converted to meters, or 0.25m if not specified

Response

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

Request Example

curl -X POST https://api.maqagr.com/api/calculations/minimum-power \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "implement_id": 1,
    "terrain_id": 1,
    "working_depth_m": 0.3
  }'

Response Example

{
  "success": true,
  "message": "Cálculo de potencia mínima realizado con éxito",
  "data": {
    "queryId": 456,
    "implement": {
      "id": 1,
      "name": "Arado de Discos",
      "brand": "Kuhn",
      "type": "plow",
      "power_requirement_hp": 80
    },
    "terrain": {
      "id": 1,
      "name": "Campo Norte",
      "soil_type": "loam",
      "slope_percentage": 5.2
    },
    "powerRequirement": {
      "minimum_power_hp": 95.5,
      "calculated_power_hp": 98.3,
      "factors": {
        "base_power_hp": 80,
        "depth_factor": 1.15,
        "soil_factor": 1.08,
        "slope_factor": 1.05
      }
    },
    "tractorAnalysis": {
      "total_evaluated": 15,
      "summary": {
        "optimal": 3,
        "overpowered": 8,
        "insufficient": 4
      }
    },
    "recommendations": {
      "top_5": [
        {
          "rank": 1,
          "tractor_id": 5,
          "name": "Case IH Magnum 180",
          "brand": "Case IH",
          "model": "Magnum 180",
          "engine_power_hp": 115,
          "suitability": {
            "score": "OPTIMAL",
            "label": "Óptimo",
            "color": "green",
            "utilizationPercent": 83,
            "isCompatible": true
          }
        },
        {
          "rank": 2,
          "tractor_id": 3,
          "name": "John Deere 6150R",
          "brand": "John Deere",
          "model": "6150R",
          "engine_power_hp": 120,
          "suitability": {
            "score": "OPTIMAL",
            "label": "Óptimo",
            "color": "green",
            "utilizationPercent": 80,
            "isCompatible": true
          }
        },
        {
          "rank": 3,
          "tractor_id": 8,
          "name": "New Holland T7.270",
          "brand": "New Holland",
          "model": "T7.270",
          "engine_power_hp": 150,
          "suitability": {
            "score": "OVERPOWERED",
            "label": "Sobredimensionado",
            "color": "yellow",
            "utilizationPercent": 64,
            "isCompatible": true
          }
        }
      ],
      "best_match": {
        "rank": 1,
        "tractor_id": 5,
        "name": "Case IH Magnum 180",
        "brand": "Case IH",
        "model": "Magnum 180",
        "engine_power_hp": 115,
        "suitability": {
          "score": "OPTIMAL",
          "label": "Óptimo",
          "color": "green",
          "utilizationPercent": 83,
          "isCompatible": true
        }
      }
    }
  }
}

Error Responses

400 Bad Request
object
Returned when required fields are missing or validation fails.
{
  "success": false,
  "message": "Faltan campos requeridos: implement_id, terrain_id"
}
Or for validation errors:
{
  "success": false,
  "error": "working_depth_m no puede exceder 1.0 metros (profundidad agrícola máxima)"
}
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 implement or terrain is not found.
{
  "success": false,
  "message": "Implemento 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 procesando la solicitud de cálculo de potencia mínima"
}

Validation Rules

ParameterTypeRequiredValidation
implement_idintegerYesMust be > 0
terrain_idintegerYesMust be > 0
working_depth_mnumberNo0 < value <= 1.0

Suitability Thresholds

The classification system uses the following thresholds:
ClassificationPower RangeUtilization %Compatible
OPTIMAL100% - 125% of required80% - 100%Yes
OVERPOWERED> 125% of required< 80%Yes
INSUFFICIENT< 100% of required> 100%No

Recommendation Priority

The top 5 recommendations are sorted by:
  1. OPTIMAL tractors first, sorted by highest utilization percentage (most efficient)
  2. OVERPOWERED tractors second, sorted by highest utilization percentage (least oversized)
  3. INSUFFICIENT tractors are excluded from recommendations

Notes

  • Only tractors with status available are evaluated
  • If no compatible tractors exist, queryId will be null and the response includes only the power requirement calculation
  • The calculation is persisted to the database only when at least one compatible tractor is found
  • All calculations include audit logging in the query_history table
  • The best_match is always the first item in top_5 array, or null if no compatible tractors
  • Implementation reference: src/controllers/calculationController.js:244-476

Build docs developers (and LLMs) love