Skip to content

Commit

Permalink
ESP-315 [Behavioral Optimizers] ln1p deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
rbayet committed Nov 22, 2021
1 parent 37dcc7d commit 0b4a69a
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteBehavioralOptimizer
* @author Richard Bayet <[email protected]>
* @copyright 2021 Smile
* @license Licensed to Smile-SA. All rights reserved. No warranty, explicit or implicit, provided.
* Unauthorized copying of this file, via any medium, is strictly prohibited.
*/

namespace Smile\ElasticsuiteBehavioralOptimizer\Ui\Component\Optimizer\Form\Modifier;

use Smile\ElasticsuiteCatalogOptimizer\Model\Optimizer\Locator\LocatorInterface as OptimizerLocatorInterface;

/**
* Optimizer create/edit form UI component scale function modifier.
* Allows the choice of 'ln1p' as a scale function if in edit mode and the optimizer already uses it.
*
* @category Smile
* @package Smile\ElasticsuiteBehavioralOptimizer
* @author Richard Bayet <[email protected]>
*/
class ScaleFunction implements \Magento\Ui\DataProvider\Modifier\ModifierInterface
{
/**
* @var OptimizerLocatorInterface
*/
private $locator;

/**
* Search Terms constructor.
*
* @param OptimizerLocatorInterface $locator Optimizer Locator
*/
public function __construct(OptimizerLocatorInterface $locator)
{
$this->locator = $locator;
}

/**
* {@inheritDoc}
*/
public function modifyData(array $data)
{
return $data;
}

/**
* {@inheritDoc}
*/
public function modifyMeta(array $meta)
{
$optimizer = $this->locator->getOptimizer();

$scaleFunctionsOptions = [
['value' => 'log1p', 'label' => __('Low')],
['value' => 'sqrt', 'label' => __('Medium')],
['value' => 'none', 'label' => __('High')],
];
$optionsTooltips = [
'log1p' => __('behavioral log1p desc'),
'sqrt' => __('behavioral sqrt desc'),
'none' => __('behavioral none desc'),
];
$scaleFunctionChartFunctions = [
'log1p' => 'log1p',
'sqrt' => 'sqrt',
'none' => 'none',
];

if ($optimizer && $optimizer->getId()) {
$scaleFunction = $optimizer->getConfig('scale_function');
if ($scaleFunction === 'ln1p') {
$scaleFunctionsOptions = array_merge(
[['value' => 'ln1p', 'label' => __('Low (deprecated)')]],
$scaleFunctionsOptions
);
$optionsTooltips = array_merge(
['ln1p' => __('behavioral ln1p desc')],
$optionsTooltips
);
$scaleFunctionChartFunctions = array_merge(
['ln1p' => 'ln1p'],
$scaleFunctionChartFunctions
);
}
}

$meta['behavioral']['children']['scale_function']['arguments']['data']['config']['options'] = $scaleFunctionsOptions;
$meta['behavioral']['children']['scale_function']['arguments']['data']['config']['optionsTooltips'] = $optionsTooltips;
$meta['behavioral']['children']['scale_function_chart']['arguments']['data']['config']['functions'] = $scaleFunctionChartFunctions;

return $meta;
}
}
32 changes: 32 additions & 0 deletions src/module-elasticsuite-behavioral-optimizer/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0"?>
<!--
/**
* Smile\ElasticsuiteBehavioralOptimizer adminhtml dependency injection configuration.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteBehavioralOptimizer
* @author Richard Bayet <[email protected]>
* @copyright 2021 Smile
* @license Licensed to Smile-SA. All rights reserved. No warranty, explicit or implicit, provided.
* Unauthorized copying of this file, via any medium, is strictly prohibited.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

<virtualType name="Smile\ElasticsuiteCatalogOptimizer\Ui\Component\Optimizer\Form\Modifier\Pool" type="Magento\Ui\DataProvider\Modifier\Pool">
<arguments>
<argument name="modifiers" xsi:type="array">
<item name="behavioral_scale_function" xsi:type="array">
<item name="class" xsi:type="string">Smile\ElasticsuiteBehavioralOptimizer\Ui\Component\Optimizer\Form\Modifier\ScaleFunction</item>
<item name="sortOrder" xsi:type="number">50</item>
</item>
</argument>
</arguments>
</virtualType>

</config>
Original file line number Diff line number Diff line change
Expand Up @@ -132,31 +132,20 @@
<item name="source" xsi:type="string">optimizer</item>
<item name="description" translate="true" xsi:type="string">behavioral scale function desc</item>
<item name="additionalClasses" xsi:type="string">radioset-tooltip optimizer-radioset-tooltip</item>
<!-- tooltips defined in defined in \Smile\ElasticsuiteBehavioralOptimizer\Ui\Component\Optimizer\Form\Modifier\ScaleFunction
<item name="optionsTooltips" xsi:type="array">
<item name="ln1p" translate="true" xsi:type="string">behavioral ln1p desc</item>
<item name="sqrt" translate="true" xsi:type="string">behavioral sqrt desc</item>
<item name="none" translate="true" xsi:type="string">behavioral none desc</item>
</item>
-->
</item>
</argument>
<settings>
<label translate="true">Boost impact</label>
<dataType>string</dataType>
<dataScope>config.scale_function</dataScope>
<!-- options defined in \Smile\ElasticsuiteBehavioralOptimizer\Ui\Component\Optimizer\Form\Modifier\ScaleFunction
<options>
<option name="0" xsi:type="array">
<item name="value" xsi:type="string">ln1p</item>
<item name="label" xsi:type="string" translate="true">Low</item>
</option>
<option name="1" xsi:type="array">
<item name="value" xsi:type="string">sqrt</item>
<item name="label" xsi:type="string" translate="true">Medium</item>
</option>
<option name="2" xsi:type="array">
<item name="value" xsi:type="string">none</item>
<item name="label" xsi:type="string" translate="true">High</item>
</option>
</options>
-->
</settings>
</radioset>

Expand All @@ -175,11 +164,10 @@
<item name="listens" xsi:type="array">
<item name="${ $.provider }:data.config.scale_function" xsi:type="string">onScaleFunctionChange</item>
</item>
<!-- chart function defined in \Smile\ElasticsuiteBehavioralOptimizer\Ui\Component\Optimizer\Form\Modifier\ScaleFunction
<item name="functions" xsi:type="array">
<item name="ln1p" xsi:type="string">ln1p</item>
<item name="sqrt" xsi:type="string">sqrt</item>
<item name="none" xsi:type="string">none</item>
</item>
-->
</item>
</argument>
</field>
Expand Down

0 comments on commit 0b4a69a

Please sign in to comment.