vba – User-defined function for estimating coefficient of performance

I am using hourly weather data to estimate performance of commercial refrigeration systems under various parameters. The formula for estimating co-efficient of performance (COP) of these systems is repeated for each hour.

I defined a formula to do this calculation:

Public Function estimatedCOP(dischargeTemp As Double, suctionTemp As Double)

Dim a As Double, b As Double, c As Double, d As Double, e As Double, f As Double

a = 9.12808037
b = 0.15059952
c = 0.00043975
d = -0.09029313
e = 0.00024061
f = -0.00099278

estimatedCOP = a + b * suctionTemp + c * suctionTemp * suctionTemp + _
    d * dischargeTemp + e * dischargeTemp * dischargeTemp + _
    f * suctionTemp * dischargeTemp

End Function

This gives the expected result, but takes a long time to calculate and update (as it’s repeated ~10,000 times). How can I improve the performance of this function?

8 – How can the field data of a user-defined block be accessed programmatically?

I need to access the field_lb_text and field_lb_glossary fields. Can someone explain to me how to deal with it?

So far I've tried this

function theme_preprocess_block(&$variables) {
     $custom_block = Drupal::entityTypeManager()->getStorage('block_content')->load('1');
     $field_content = $custom_block->field_lb_text->value;

I want the data


Enter the image description here

Sortable administration columns, which are sorted from user-defined fields, do not combine Com Search and dropdown filter

I am developing a plugin that essentially consists of a CPT that lists certificates (several) for their respective customers (user role). I've done everything that should be done:
– The CPT "Certificates"
– The user role "customer"
– The taxonomy "company"
– Carbon fields for custom fields (via Composer dependency)
– I have created the field that connects the customer with their respective company, since we have the field for the assignment when creating posts / certificates.
– I have created the rules (filter – pre_get_posts) in order to only list contributions from the company to which the user customer is connected.
– AND THE MOST DRAMATIC OF EVERYTHING – I chose the WP Admin interface myself to show this, and now I'm having problems with filtering, such as:
– – It is impossible to combine filters and search fields with columns. Sortable order from custom fields. Only sortable title columns work with search and filter combinations.

I think this decision to use the ADMIN user interface made me very complicated. I'm considering creating a separate page and getting it through WP's REST API with JS.
Or is it possible to combine the filters in the ADMIN user interface? Both options work for me. I would like someone's help because I don't know much about SQL and how I could combine these filters.

In the pictures I show an example for the ADMIN view, in which all certificates are shown:
List of certificates in the administrator view


The combination of dropdown filters with search and column order of the title works perfectly:
Search, dropdown and title column sortable


But when I try to sort by the other columns, everything disappears. see:
Combination doesn't work


If I order without using the search combination, it works normally.

The main code is here:

object-oriented – user-defined and integrated

For all user-defined objects we need a kind of variable / attribute to store a value that basically separates an object from its value. A distinction is made between the object and the value of the user-defined objects. Technically speaking, we don't say that the value is the object itself. We do that colloquially

class custom:
    def __init__(self,value):
        self.value = value

    def __repr__(self):
        return f "{self.value}"  

However, with built-in functions, it appears to the end user that the object is the value itself

a = (1,2)
b = 4

It is how it is presented

Internally, this should also work the same as for custom objects
There must be an attribute / variable in which the values ​​are stored in order to make a distinction between the object and the value

Is that true??

I was asked this question recently in the last round of an interview
a few months ago


magento2.3 – Magento 2 combines 2 user-defined tables in a user-defined module

First, thanks for reading my question. I'm learning to program in M2, so forgive me for any strange questions. So far, I have been able to create a custom module and edit page. My main database table is name dsssolutions_management_vendor. My form loads this as expected, but now I want to load additional tables to fill my form as well. For this I want to follow coding standards as well as possible.

From this point on, I am not sure and cannot find online how to load additional database tables into my form by default and later possibly save this data correctly. However, let's start with the join to figure this out correctly. I use ui_component for the form.

Personally, I would expect to have to change the vendor / DataProvider in some way so that the getData () function loads the data by default. Below is my current code for this file. Note that I changed the get-ID with (& # 39; general & # 39;) because I use tabs without M2 not filling out the edit form.

collection = $collectionFactory->create();
    $this->dataPersistor = $dataPersistor;
    parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);

 * Get data
 * @return array
public function getData()
    if (isset($this->loadedData)) {
        return $this->loadedData;
    $items = $this->collection->getItems();
    foreach ($items as $model) {
        $this->loadedData($model->getId())('general') = $model->getData();
    $data = $this->dataPersistor->get('dsssolutions_management_vendor');

    if (!empty($data)) {
        $model = $this->collection->getNewEmptyItem();
        $this->loadedData($model->getId()) = $model->getData();

    return $this->loadedData;

The database I want to join is called dsssolutions_management_vendoraddress (I know that the potential naming convention should be manufacturer addresses, but can change that later). In this table, I have a vendor_id column that should match the ID from the supplier record I received. First one to one, later maybe one to many.

Another possible place to do this would be the vendor / edit.php. To make sure, this code below.

resultPageFactory = $resultPageFactory;
    parent::__construct($context, $coreRegistry);

 * Edit action
 * @return MagentoFrameworkControllerResultInterface
public function execute()
    // 1. Get ID and create model
    $id = $this->getRequest()->getParam('vendor_id');
    $model = $this->_objectManager->create(DssSolutionsManagementModelVendor::class);

    // 2. Initial checking
    if ($id) {
        if (!$model->getId()) {
            $this->messageManager->addErrorMessage(__('This Vendor no longer exists.'));
            /** @var MagentoBackendModelViewResultRedirect $resultRedirect */
            $resultRedirect = $this->resultRedirectFactory->create();
            return $resultRedirect->setPath('*/*/');
    $this->_coreRegistry->register('dsssolutions_management_vendor', $model);

    // 3. Build edit form
    /** @var MagentoBackendModelViewResultPage $resultPage */
    $resultPage = $this->resultPageFactory->create();
        $id ? __('Edit Vendor') : __('New Vendor'),
        $id ? __('Edit Vendor') : __('New Vendor')
    $resultPage->getConfig()->getTitle()->prepend($model->getId() ? __('Edit Vendor %1', $model->getVendorName()) : __('New Vendor'));
    return $resultPage;

Hopefully someone can point me in the right direction here.

8 – Call method from user-defined module class

I tried to call a function within another class within the same module on D8, but I got a bug in the code. I received an error: Class & # 39; Drupal hospitator TimeTrackerController TimeTracker & # 39; was not found.

My main controller (HospitatorController.php):

namespace DrupalhospitatorController;

use DrupalCoreControllerControllerBase;
use DrupalhospitatorTimeTrackerControllerTimeTracker;

 * Class HospitatorController.
class HospitatorController extends ControllerBase {

   * Main Page Function.
   * @return array
   *   Return main page.
  public function mainPage() {
    $element = array(
        '#type' => 'markup',
        '#markup' => $this->t('Welcome to Hospitator!') . '
', ); $test_controller = new TimeTracker; $test_text = $test_controller->start(); return $element; } }

My secondary class (TimeTracker.php):

I was without coding for 2 years and my memory has some leaks. Can you help me? Tanhk you

Install Magento2 data User-defined attr set, attr group, attr

Here is my installation method. Why are only the attributes https://prnt.sc/s20b3a, https://prnt.sc/s20czw displayed in the standard attribute set after installation? You shouldn't be here. How do you repair?

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    $eavSetup = $this->_eavSetupFactory->create(('setup' => $setup));
    $categorySetup = $this->_categorySetupFactoryProduct->create(('setup' => $setup));

    // version 1.4.34
    // get default attribute set id
    $entityTypeId = $categorySetup->getEntityTypeId(MagentoCatalogModelProduct::ENTITY);
    $attributeSetId = $categorySetup->getDefaultAttributeSetId($entityTypeId); // default attribute set

    foreach ($this->dataAttrProduct as $section) {

        // add attribute set
        $attributeSet = $this->_attributeSetFactoryProduct->create();
        $data = (
            'attribute_set_name' => $section('attr_set_name'),
            'entity_type_id' => $entityTypeId,
            'sort_order' => 100,

        // add attributes
        foreach ($section('attrs') as $attr) {
            if (empty($attr('code')) && empty($attr('label'))) continue;

                    'type' => $attr('type'),
                    'backend' => '',
                    'frontend' => '',
                    'label' => $attr('label'),
                    'input' => $attr('input'),
                    'class' => '',
                    'source' => '',
                    'global' => MagentoEavModelEntityAttributeScopedAttributeInterface::SCOPE_STORE,
                    'visible' => $attr('visible'),
                    'required' => $attr('required'),
                    'user_defined' => false,
                    'default' => '',
                    'searchable' => false,
                    'filterable' => false,
                    'comparable' => false,
                    'visible_on_front' => $attr('visible_on_front'),
                    'used_in_product_listing' => $attr('used_in_product_listing'),
                    'unique' => false,
                    'apply_to' => '',
                    'attribute_set' => $section('attr_set_name')

        // add attributes group in  attribute set
        $attributeSetIdNomenclatures = $eavSetup->getAttributeSetId($entityTypeId,$section('attr_set_name'));

        // add attribute to group
        $attributeGroupId = $eavSetup->getAttributeGroupId($entityTypeId, $attributeSetIdNomenclatures, $section('attr_group_name'));
        foreach ($section('attrs') as $attr) {


Values ​​$ this-> dataAttrProduct

 'fastener' => (
        'attr_group_name' => 'Fastener',
        'attr_set_name' => 'Fastener',
        'attrs' => (
            0 => (
                'code' =>'fasteners_sub_type',
                'type' => 'text',
                'input' => 'text',
                'label' =>'Подраздел',
                'visible' => true,
                'required' => false,
                'visible_on_front' => false,
                'used_in_product_listing' => false
            1 => (
                'code' =>'fasteners_brand',
                'type' => 'int',
                'input' => 'select',
                'label' =>'Бренд',
                'visible' => true,
                'required' => false,
                'visible_on_front' => true,
                'used_in_product_listing' => true