# duration

## Usage

{% hint style="info" %}
This calculator allows the user to compute the duration in days between 2 date.
{% endhint %}

This calculator can be used with the following method:

<mark style="color:red;">**`duration`**</mark>

Examples:

* Compute the duration between the product launch date and the sale date.
* Compute a promo period duration based on the start and the end date of the promo

***

## Main Parameters

{% hint style="success" %}
**The bold options** represent the default values when the parameters are optional.
{% endhint %}

* *<mark style="color:blue;">input\_columns</mark>* \
  list of columns used as input of the calculators: The list of columns that will be used to fill the output column.
* *<mark style="color:blue;">output\_columns</mark>* \
  list of columns added by the calculators : Name of the filled column added to the dataset.
* *<mark style="color:blue;">global</mark>* *(true, **false)*** \
  Should this calculator be performed before data splitting during training for cross-validation
* *<mark style="color:blue;">steps</mark>* \[optionnal] *(**training, prediction**, postprocessing*\*)\*\*\* \
  List of steps in a pipeline where columns from this calculator are added to the data. Note that when the training option is listed, the calculator is actually added during preprocessing.
* *<mark style="color:blue;">store\_in\_model</mark>* \[optionnal] *(true, **false)*** \
  Please indicate whether the "calculated" columns by the calculator should be stored in the model or not to avoid recalculating them during prediction. This is only relevant if the calculated columns are added to both training and prediction. Without this parameter, the values will not be stored in the model. The following parameters only make sense if this parameter is set to *true*.
* *<mark style="color:blue;">stored\_columns</mark>* \[required if *<mark style="color:blue;">store\_in\_model</mark> is true*] \
  List indicating the columns to be stored among the *<mark style="color:blue;">output\_columns</mark>*.
* *<mark style="color:blue;">stored\_keys</mark>* \[required if *<mark style="color:blue;">store\_in\_model</mark> is true*] \
  List indicating the columns to use for identifying the correct values to join on the data for prediction among the stored values (logically, they are to be chosen from the *<mark style="color:blue;">input\_columns</mark>*).

***

## Specific Parameters

* *<mark style="color:blue;">begin\_date</mark>* \
  The name of the column containing the lower bound for days counting.
* *<mark style="color:blue;">end\_date</mark>* \
  The name of the column containing the upper bound for days counting.

***

## Examples

1. Given dataset containing daily sales data of several products with the sales date (`receipt_date` ) and the date when the product was launched (`receipt_date`). The user want to get the number of days between the sale and the product launch.

   ```yaml
   calculated_cols:
   	calc_duration:
   	    method: duration
   	    input_columns:
   	    - receipt_date
   	    - product_launch_date
   	    output_columns:
   	    - product_duration
   	    params:
   	      begin_col: product_launch
   	      end_col: receipt_date
   ```

   **Result :**

   | receipt\_date | product\_launch | product\_duration |
   | ------------- | --------------- | ----------------- |
   | 2023-01-01    | 2022-07-25      | 160               |
   | 2023-01-02    | 2022-07-25      | 161               |
   | 2023-01-03    | 2022-07-25      | 162               |
   | 2023-01-01    | 2023-01-01      | 0                 |
   | 2023-01-02    | 2023-01-01      | 1                 |
   | 2023-01-03    | 2023-01-01      | 2                 |
