Skip to main content

Floor

Math Data Analysis

Synopsis

Calculates the floor function of numeric values, returning the largest integer that is less than or equal to the input value.

Schema

- floor:
description: <text>
field: <ident>
value: <string>
if: <script>
ignore_failure: <boolean>
ignore_missing: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>

Configuration

The following fields are used to define the processor:

FieldRequiredDefaultDescription
fieldYField to store the floor result
valueYNumeric value or field reference to calculate floor for
descriptionN-Explanatory notes
ifN-Condition to run
ignore_failureNfalseSee Handling Failures
ignore_missingNfalseContinue processing if referenced fields are missing
on_failureN-See Handling Failures
on_successN-See Handling Success
tagN-Identifier
disabledNfalseWhen true, the processor is skipped and the event continues to the next one. Lets you take a processor out of the path without removing its configuration
warning

This operand is resolved by getNumericValue, which accepts exactly two forms: a numeric literal such as 3600, or a bare field path such as stats.total. Nothing else is evaluated.

There is no expression evaluator here, and no template expansion. "a / b" is looked up as a field literally named a / b, and "{{price}}" as a field literally named {{price}} — both fail with field does not exist. To compute a value first, use a math processor and reference the field it writes.

Details

The processor applies the mathematical floor function to numeric values. The floor function returns the largest integer that is less than or equal to the input value. For example:

  • floor(3.7) = 3
  • floor(-2.3) = -3
  • floor(5.0) = 5
  • floor(-1.0) = -1

The value parameter can be either a literal numeric value or a field reference. When using field references, the processor will resolve the field value and apply the floor operation to it.

info

The floor function is commonly used in data processing for grouping continuous values into discrete buckets, time-based calculations, and normalization operations.

note

For negative numbers, the floor function rounds towards negative infinity, not towards zero. This means floor(-2.3) equals -3, not -2.

tip

Use the floor processor in combination with mathematical operations to create time-based groupings, such as rounding timestamps to the nearest hour or creating histogram buckets.

Examples

Basic Floor Operation

Calculate the floor of a decimal value...

{
"price": 19.99
}
- floor:
field: price_floor
value: "price"

to get the integer part:

{
"price": 19.99,
"price_floor": 19
}

Negative Number Floor

Floor of negative numbers...

{
"temperature": -2.7
}
- floor:
field: temp_floor
value: "temperature"

rounds towards negative infinity:

{
"temperature": -2.7,
"temp_floor": -3
}

Time Bucket Creation

Create hourly time buckets...

{
"timestamp": 1705318847.234,
"hour_seconds": 3600
}
- math:
field: _hours
operation: divide
left_operand: timestamp
right_operand: hour_seconds
- floor:
field: hour_bucket
value: "_hours"

for time-based grouping:

{
"timestamp": 1705318847.234,
"hour_seconds": 3600,
"hour_bucket": 473699
}

Literal Values

Use literal numeric values...

{
"data": "processing"
}
- floor:
field: constant_floor
value: "7.89"

for constant calculations:

{
"data": "processing",
"constant_floor": 7
}

Score Normalization

Normalize scores to integer ranges...

{
"raw_score": 87.6,
"max_score": 100,
"scale_factor": 10
}
- math:
field: _ratio
operation: divide
left_operand: raw_score
right_operand: max_score
- math:
field: _scaled
operation: multiply
left_operand: _ratio
right_operand: scale_factor
- floor:
field: normalized_score
value: "_scaled"

for categorical grouping:

{
"raw_score": 87.6,
"max_score": 100,
"scale_factor": 10,
"normalized_score": 8
}

Percentage Buckets

Create percentage buckets...

{
"completion_rate": 0.847
}
- math:
field: _scaled
operation: multiply
left_operand: completion_rate
right_operand: "10"
- floor:
field: completion_bucket
value: "_scaled"

for progress tracking:

{
"completion_rate": 0.847,
"completion_bucket": 8
}

In-Place Modification

Modify the original field...

{
"average_rating": 4.73
}
- floor:
field: average_rating
value: "average_rating"

by using the same field name:

{
"average_rating": 4
}

Compound Calculations

Use complex mathematical expressions...

{
"value_a": 15.7,
"value_b": 8.2,
"multiplier": 2.5
}
- math:
field: _sum
operation: add
left_operand: value_a
right_operand: value_b
- math:
field: _product
operation: multiply
left_operand: _sum
right_operand: multiplier
- math:
field: _scaled
operation: divide
left_operand: _product
right_operand: "10"
- floor:
field: complex_result
value: "_scaled"

for advanced calculations:

{
"value_a": 15.7,
"value_b": 8.2,
"multiplier": 2.5,
"complex_result": 5
}

Zero and Integer Values

Floor of integers and zero...

{
"integer_val": 42,
"zero_val": 0
}
- floor:
field: int_floor
value: "integer_val"
- floor:
field: zero_floor
value: "zero_val"

remain unchanged:

{
"integer_val": 42,
"zero_val": 0,
"int_floor": 42,
"zero_floor": 0
}