#StackBounty: #magento2 #layout #collection #grid Magento2 Need to filter grid when value is entered in search box, the column of the d…

Bounty: 50

I have added 4 columns in the grid as displayed in below screenshot.

enter image description here

For displaying for eg. Recipient Email column I added following code in XML & it’s renderer PHP file. (Code is added below)

app/code/Company/Module/view/adminhtml/layout/adminhtml_giftcardaccount_block.xml

<block class="MagentoBackendBlockWidgetGridColumn">
                    <arguments>
                        <argument name="header" xsi:type="string" translate="true">Recipient Email</argument>
                        <argument name="index" xsi:type="string">recipient_email</argument>
                        <argument name="renderer" xsi:type="string">CompanyModuleBlockAdminhtmlWidgetGridColumnRendererRecipientemail</argument>
                        <argument name="sortable" xsi:type="boolean">false</argument>
                    </arguments>
                </block>

app/code/Company/Module//Block/Adminhtml/Widget/Grid/Column/Renderer/Recipientemail.php

<?php
namespace CompanyModuleBlockAdminhtmlWidgetGridColumnRenderer;
class Recipientemail extends MagentoBackendBlockWidgetGridColumnRendererAbstractRenderer
{
    protected $_storeManager;

    public function __construct(
        MagentoBackendBlockContext $context,
        MagentoStoreModelStoreManagerInterface $storeManager,      
        MagentoSalesModelOrderItem $orderItem,
        array $data = []
    ) {
        parent::__construct($context, $data);
        $this->_storeManager = $storeManager;      
        $this->orderitem =  $orderItem;  
    }


    public function render(MagentoFrameworkDataObject $row)
    {
        $code = $row->getCode();
        $result = array();
        $salesorderitem =  $this->orderitem->getCollection()
                          ->addFieldToFilter('product_options', array('like' => '%'.$code.'%'));

        if(!empty($salesorderitem)) 
        {
            foreach($salesorderitem as $orderdata){
                $productOptions = $orderdata->getProductOptions();   
                $recipientemail = $productOptions['giftcard_recipient_email'];
                if(!empty($recipientemail)){
                return $recipientemail;
                }else{
                    return '-';
                }
            }
        }else{
               return '-';
        }


    }

Main table of grid is – magento_giftcardaccount

Recipientemail table is – product_options

{"info_buyRequest":{"uenc":"aHR0cDovLzE5Mi4xNjguMS4xODQvZGcvZHJ1bW1vbmQtZ29sZi1lLWdpZnQtY2FyZC5odG1s","product":"76450","selected_configurable_option":"","related_product":"","giftcard_amount":"5","giftcard_sender_name":"test","giftcard_sender_email":"testmscgoriteeps@gmail.com","giftcard_recipient_name":"test22","giftcard_recipient_email":"arjun.cmarix@gmail.com","giftcard_message":"test test gift","qty":"1"},"giftcard_sender_name":"test","giftcard_sender_email":"testmscgoriteeps@gmail.com","giftcard_recipient_name":"test22","giftcard_recipient_email":"arjun.cmarix@gmail.com","giftcard_message":"test test gift","giftcard_lifetime":null,"giftcard_is_redeemable":0,"giftcard_email_template":null,"giftcard_type":"0","email_sent":0,"giftcard_created_codes":["HQE9EMUNTA6N"]}

My issue is the filter is not working. When I enter email in the search text field of grid it keeps on spinning for some time & grid is loaded as it is without filter.

It would be really appreciable if someone can guide me on how to filter this search text.


Get this bounty!!!

#StackBounty: #python #search #grid #knn #imputation grid search with own estimator in python

Bounty: 50

I am trying to build my own estimator (regressor) and use it for imputation (KnnImputation).
For now – I wrote a very basic knn imputation, when it will work I will change the algorithm a bit.

I’m having a problem using the grid search “GridSearchCV”.
I tried to print the shapes of the data to get a sense of the problem. When the configuration is 10-fold cross validation I would expect the prints to be 10 times this lines:

xTrain size : 2487
yTrain size : 2487
test size : 276

But instead I get this lines:

xTrain size : 2487
yTrain size : 2487
test size : 276

test size : 2487

more the 60 times.

Any idea what is the problem?

My Code:

class KnnImputation(BaseEstimator, RegressorMixin):

    def __init__(self, k=5, distance='euclidean'):
        self.k = k
        self.distance = distance

    def get_params(self, deep=False):
        return {'k': self.k, 'distance': self.distance}

    def set_params(self, **parameters):
        self.k = parameters['k']
        self.distance = parameters['distance']

    def fit(self, X, y):
        self.xTrain = X.values
        self.yTrain = y.values
        print("nxTrain size : " + str(self.xTrain.shape[0]))
        print("yTrain size : " + str(self.yTrain.shape[0]))

        return self

    def predict(self, xTest):
        xTest = xTest.values
        num_test = xTest.shape[0]
        print("test size : " + str(num_test)+"n")
        yPred = np.zeros(num_test, dtype=self.yTrain.dtype).reshape(-1, 1)

        for i in range(num_test):
            distances = np.sum(np.abs(self.xTrain - xTest[i, :]), axis=1)
            idx = np.argsort(distances)
            minIndexes = idx[:self.k]
            kClosest = self.yTrain[minIndexes[:]]
            yPred[i] = np.mean(kClosest)

        return yPred

kf = KFold(n_splits=10, shuffle=False, random_state=23)
NN = KnnImputation()
gridSearchNN = GridSearchCV(NN, param_grid=params, scoring="neg_mean_squared_error", n_jobs=1,
                                cv=kf.split(xTrain, yTrain), verbose=1)
gridSearchNN.fit(X=xTrain, y=yTrain)

The Error:

  File "C:Users....dataImputation.py", line 85, in knnImputationMethod
    gridSearchNN.fit(X=xTrain, y=yTrain)
  File "C:Users...Anaconda3libsite-packagessklearnmodel_selection_search.py", line 740, in fit
    self.best_estimator_.fit(X, y, **fit_params)
AttributeError: 'NoneType' object has no attribute 'fit'


Get this bounty!!!

#StackBounty: #unity #collision-detection #physics #mathematics #grid Redundant checks from spatial partitioning

Bounty: 100

A simple 2D grid partition system for collision detection divides space into equal-sized tiles. Colliders then map themselves to tiles with their bounding box in O(N) time. Collision detection only has to be performed between objects that occupy the same tile(s).

Collision detection is expensive so the more culled, the better. With a grid partitioning system, how are collisions culled when colliders share multiple tiles?

For example, Circle_A and Circle_B both sit on the edge between Tile_1 and Tile_2. Iterating both tiles would make collision detection between Circle_A & Circle_B run twice.
Sharing Multiple Tiles

A global pair hashtable seems performance expensive since it has to be cleared every frame. Tracking pairs inside colliders takes a lot of memory. How do you mitigate redundant pairs when iterating through partition grid tiles?


Get this bounty!!!