forms – What is best practice for passing routing parameters?

In submitForm() I want to redirect to a controller and pass the form values. The form values are all arrays, btw.

Here is submitForm.

public function submitForm(array &$form, FormStateInterface $form_state) {
    // get values
    $demo_values = $form_state->getValue('demo');
    $data_set_value = $form_state->getValue('data_set');
    $engineering_degrees1 = $form_state->getValue('engineering_degrees1');
    $engineering_degrees2 = $form_state->getValue('engineering_degrees2');
    $engineering_degrees3 = $form_state->getValue('engineering_degrees3');
    $engineering_degrees4 = $form_state->getValue('engineering_degrees4');
    $physical_science_degrees = $form_state->getValue('physical_science_degrees');

   
    # set form data in url redirect
    $params = ('demos' => $demo_values,
      'data_set' => $data_set_value,
      'engineering_degrees1' => $engineering_degrees1,
      'engineering_degrees2' => $engineering_degrees2,
      'engineering_degrees3' => $engineering_degrees3,
      'engineering_degrees4' => $engineering_degrees4,
      'physical_science_degrees' => $physical_science_degrees);
    $form_state->setRedirect('stats_degrees.render_chart',$params);
  }
}

Here is my routing YML file.

stats_degrees.render_form:
  path: '/statistics/stats-degrees'
  defaults:
    _title: 'Engineering and Physical Science Degrees Earned by Members of Underrepresented Groups'
    _form: 'Drupalstats_degreesFormStatsDegreesForm'
  requirements:
      _permission: 'access content'
stats_degrees.render_chart:
  path: '/statistics/stats-degrees-chart/{demos}/{data_set}/{engineering_degrees1}/{engineering_degrees2}/{engineering_degrees3}/{engineering_degrees4}/{physical_science_degrees}'
  defaults:
    _controller: 'Drupalstats_degreesControllerStatsDegreesController::stats_degrees_chart'
  requirements:
    _permission: 'access content'

Here is my Controller method call.

public function stats_degrees_chart($demos,$data_set,$engineering_degrees1,$engineering_degrees2,$engineering_degrees3,$engineering_degrees4,$physical_science_degrees) {

Currently, it’s throwing a 500 error after I submit the form. Is there a better way to pass the parameters to the controller?

machine learning – How to chose the probability distribution and its parameters in maximum likelihood estimation

I’m reading the book “Mathematics for Machine Learning”, it’s a free book that you can find here. So I’m reading section 8.3 of the book which explains the maximum likelihood estimation (or MLE).
This is my understanding of how MLE works in machine learning:

Say we have a dataset of vectors $(x_1, x_2, …, x_n)$, we also have corresponding labels $(y_1, y_2, …, y_n)$ which are real numbers, finally we have a model with parameters $theta$. Now MLE is a way to find the best parameters $theta$ for the model, so that model would map $x_n$ to $hat{y}_n$ and $hat{y}_n$ is as close to $y_n$ as possible.

For each $x_n$ and $y_n$ we have a probability distribution $p(y_n|x_n,theta)$. Basically it estimates how likely our model with parameters $theta$ will output $y_n$ when we feed it $x_n$ (and the bigger the probability the better).

We then take a logarithm of each of the estimated probabilities and sum up all the logarithms, like this:
$$sum_{n=1}^Nlog{p(y_n|x_n,theta)}$$

The bigger this sum the better our model with parameters $theta$ explains the data, so we have to maximize the sum.

What I don’t understand is how do we chose the probability distribution $p(y_n|x_n,theta)$ and its parameters? In the book there is an Example 8.4, where they chose the probability distribution to be Gaussian distribution with zero mean, $epsilon_n sim mathcal{N}(0,,sigma^{2})$. They then assume that the linear model $x_n^Ttheta$ is used for prediction, so:
$$p(y_n|x_n,theta) = mathcal{N}(y_n|x_n^Ttheta,,sigma^{2})$$
and I don’t understand why they replaced zero mean with $x_n^Ttheta$, also where do we get covariance $sigma^{2}$?

So this is my question, how do we chose the probability distribution and it’s parameters? In the example above the distribution is Gaussian but it could be any other distribution from those that exist and different distributions have different types and numbers of parameters. Also as I understood each $x_n$ and $y_n$ have its own probability distribution $p(y_n|x_n,theta)$ which even more complicates the problem.

I would really appreciate your help. Also note that I’m just learning the math for machine learning and not very skilled. If you need any additional info please ask in the comments.

Thanks!

fisheye – Which parameters to use with FFMPEG to rectify Mars Ingenuity helicopter images?

I know how to convert a fisheye image to equirectangular, to view it inside a 3D VR viewer as a “panorama”:

ffmpeg -i input.jpg -vf v360:fisheye:equirectangular:ih_fov=180:iv_fov=180:pitch=0 -y output.jpg
  • -i input file
  • -vf video filter
    • v360: VR360 panorama conversion
      • fisheye: source format
      • equirectangular: destination format
      • ih_fov: input horizontal FOV
      • iv_fov: input verticalFOV
      • pitch: camera up/down orientation
    • -y Overwrite
    • Output file

Instead I would like to “rectify” the Ingenuity fisheye image, as if it was shot with a standard camera; I know about lensfun and lenscorrection parameters , but I don’t undrestand which parameters I should use.

Cameras official data:

Navigation (NAV) Camera has a field-of-view (FOV) of 133 deg
(horizontal) by 100 deg (vertical) with an average Instantaneous
Field-of-view (IFOV) of 3.6 mRad/pixel

Return-to-Earth (RTE) Camera has a FOV of 47 deg (horizontal) by 47 deg (vertical) with
an average IFOV of 0.26 mRad/pixel.

The NAV camera is pointed directly towards nadir, and the RTE camera
is pointed approximately 22 deg below the horizon, resulting in an
overlap region between the two camera image footprints of
approximately 30 deg × 47 deg.

Source: https://rotorcraft.arc.nasa.gov/Publications/files/Balaram_AIAA2018_0023.pdf

Full FFMPEG documentation: link

Ingenuity raw images: https://mars.nasa.gov/mars2020/multimedia/raw-images/index.cfm?af=REAR_HAZCAM_RIGHT

recursion – A recursive_transform template function for the multiple parameters cases in C++

This is a follow-up question for A recursive_transform template function for the binary operation cases in C++. Thanks for G. Sliepen’s answer. Based on the mentioned suggestion, I am attempting to improve the extendibility of recursive_transform template function for the multiple parameters cases.

  • recursive_invoke_result template struct and recursive_variadic_invoke_result template struct

    recursive_invoke_result struct is updated with integrating unwrap_level parameter instead of using std::invocable in order to make the logic of recursion be consistent. The recursive_invoke_result struct is focus on the result type of invoking functions with unary input and the recursive_variadic_invoke_result struct deals with the result type of invoking functions with multiple inputs.

  • recursive_transform template function for the multiple parameters cases

    The main part of this post. The multiple parameterized lambda for recursive transform is supported.

    For example, the following code can be compiled.

    std::vector<std::string> test_vector1{ "1", "4", "7" };
    std::vector<std::string> test_vector2{ "2", "5", "8" };
    std::vector<std::string> test_vector3{ "3", "6", "9" };
    std::vector<std::string> test_vector4{ "a", "b", "c" };
    auto output = recursive_transform<1>(
        ()(auto element1, auto element2, auto element3, auto element4) { return element1 + element2 + element3 + element4; },
        test_vector1, test_vector2, test_vector3, test_vector4);
    for (auto&& element : output)
    {
        std::cout << element << std::endl;
    }
    

    The output in the above code is a std::vector<std::string>. The console output:

    123a
    456b
    789c
    

The experimental implementation

  • recursive_invoke_result template struct implementation: recursive_invoke_result struct here integrating unwrap_level parameter. struct recursive_invoke_result<0, F, T> is a kind of partial template specialization which plays the role of recursion termination condition. Whether typename T is a range or not, the type just comes from std::invoke_result_t<F, T> if unwrap_level is 0.

    //  recursive_invoke_result_t implementation
    template<std::size_t, typename, typename>
    struct recursive_invoke_result { };
    
    template<typename T, typename F>
    struct recursive_invoke_result<0, F, T> { using type = std::invoke_result_t<F, T>; };
    
    template<std::size_t unwrap_level, typename F, template<typename...> typename Container, typename... Ts>
    requires (std::ranges::input_range<Container<Ts...>> &&
              requires { typename recursive_invoke_result<unwrap_level - 1, F, std::ranges::range_value_t<Container<Ts...>>>::type; })
    struct recursive_invoke_result<unwrap_level, F, Container<Ts...>>
    {
        using type = Container<typename recursive_invoke_result<unwrap_level - 1, F, std::ranges::range_value_t<Container<Ts...>>>::type>;
    };
    
    template<std::size_t unwrap_level, typename F, typename T>
    using recursive_invoke_result_t = typename recursive_invoke_result<unwrap_level, F, T>::type;
    
  • recursive_variadic_invoke_result template struct implementation: recursive_variadic_invoke_result struct deals with the result type of invoking functions with multiple inputs.

    //  recursive_variadic_invoke_result_t implementation
    template<std::size_t, typename, typename, typename...>
    struct recursive_variadic_invoke_result { };
    
    template<typename F, class...Ts1, template<class...>class Container1, typename... Ts>
    struct recursive_variadic_invoke_result<0, F, Container1<Ts1...>, Ts...>
    {
        using type = std::invoke_result_t<F, Container1<Ts1...>, Ts...>;
    };
    
    template<typename F, class...Ts1, template<class...>class Container1, typename... Ts>
    struct recursive_variadic_invoke_result<1, F, Container1<Ts1...>, Ts...>
    {
        using type = Container1<std::invoke_result_t<F,
            std::ranges::range_value_t<Container1<Ts1...>>,
            std::ranges::range_value_t<Ts>...>>;
    };
    
    template<std::size_t unwrap_level, typename F, class...Ts1, template<class...>class Container1, typename... Ts>
    requires (  std::ranges::input_range<Container1<Ts1...>> &&
                requires { typename recursive_variadic_invoke_result<
                                        unwrap_level - 1,
                                        F,
                                        std::ranges::range_value_t<Container1<Ts1...>>,
                                        std::ranges::range_value_t<Ts>...>::type; })                //  The rest arguments are ranges
    struct recursive_variadic_invoke_result<unwrap_level, F, Container1<Ts1...>, Ts...>
    {
        using type = Container1<
            typename recursive_variadic_invoke_result<
            unwrap_level - 1,
            F,
            std::ranges::range_value_t<Container1<Ts1...>>,
            std::ranges::range_value_t<Ts>...
            >::type>;
    };
    
    template<std::size_t unwrap_level, typename F, typename T1, typename... Ts>
    using recursive_variadic_invoke_result_t = typename recursive_variadic_invoke_result<unwrap_level, F, T1, Ts...>::type;
    
  • transform function for any $n$-ary function: from G. Sliepen’s answer

    template<typename OutputIt, typename NAryOperation, typename InputIt, typename... InputIts>
    OutputIt transform(OutputIt d_first, NAryOperation op, InputIt first, InputIt last, InputIts... rest) {
        while (first != last) {
            *d_first++ = op(*first++, (*rest++)...);
        }
        return d_first;
    }
    
  • The first recursive_transform template function overloading: dealing with unary input transform cases.

    //  recursive_transform implementation (the version with unwrap_level)
    template<std::size_t unwrap_level = 1, class T, class F>
    constexpr auto recursive_transform(const F& f, const T& input)
    {
        if constexpr (unwrap_level > 0)
        {
            recursive_invoke_result_t<unwrap_level, F, T> output{};
            std::ranges::transform(
                std::ranges::cbegin(input),
                std::ranges::cend(input),
                std::inserter(output, std::ranges::end(output)),
                (&f)(auto&& element) { return recursive_transform<unwrap_level - 1>(f, element); }
            );
            return output;
        }
        else
        {
            return f(input);
        }
    }
    
  • The second recursive_transform template function overloading: handling the cases with multiple input function.

    //  recursive_transform for the multiple parameters cases (the version with unwrap_level)
    template<std::size_t unwrap_level = 1, class F, class Arg1, class... Args>
    constexpr auto recursive_transform(const F& f, const Arg1& arg1, const Args&... args)
    {
        if constexpr (unwrap_level > 0)
        {
            recursive_variadic_invoke_result_t<unwrap_level, F, Arg1, Args...> output{};
            transform(
                std::inserter(output, std::ranges::end(output)),
                (&f)(auto&& element1, auto&&... elements) { return recursive_transform<unwrap_level - 1>(f, element1, elements...); },
                std::ranges::cbegin(arg1),
                std::ranges::cend(arg1),
                std::ranges::cbegin(args)...
            );
            return output;
        }
        else
        {
            return f(arg1, args...);
        }
    }
    

The testing code

In the following Godbolt link, the testing code is divide into three parts: unary_test_cases, binary_test_cases and ternary_test_cases.

A Godbolt link is here.

unary_test_cases and binary_test_cases are similar to the previous posts.

Let’s check ternary_test_cases:

void ternary_test_cases()
{
    std::cout << "*****ternary_test_cases*****" << std::endl;

    //  non-nested input test, lambda function applied on input directly
    int test_number = 3;
    std::cout << recursive_transform<0>(
        ()(auto&& element1, auto&& element2, auto&& element3) { return element1 + element2 + element3; },
        test_number, test_number, test_number) << std::endl;
    
    //  nested input test, lambda function applied on input directly
    std::vector<int> test_vector = {
        1, 2, 3
    };
    std::cout << recursive_transform<0>(()(auto element1, auto element2, auto element3)
        {
            return element1.size() + element2.size() + element3.size();
        },
        test_vector, test_vector, test_vector) << std::endl;
    
    //  std::vector<int> -> std::vector<std::string>
    auto recursive_transform_result = recursive_transform<1>(
        ()(int element1, int element2, int element3)->std::string { return std::to_string(element1 + element2 + element3); },
        test_vector, test_vector, test_vector
    );                                                                                  //  For testing
    std::cout << "std::vector<int> -> std::vector<std::string>: " +
        recursive_transform_result.at(1) << std::endl;                                  //  recursive_transform_result.at(0) is a std::string
    
    //  std::vector<string> -> std::vector<int>
    std::cout << "std::vector<string> -> std::vector<int>: "
              << recursive_transform<1>(
            ()(std::string element1, std::string element2, std::string element3) 
                  { return std::atoi((element1 + element2 + element3).c_str()); },
            recursive_transform_result, recursive_transform_result, recursive_transform_result).at(0) + 1 << std::endl;                         //  std::string element to int
    
    //  std::vector<std::vector<int>> -> std::vector<std::vector<std::string>>
    std::vector<decltype(test_vector)> test_vector2 = {
        test_vector, test_vector, test_vector
    };

    auto recursive_transform_result2 = recursive_transform<2>(
        ()(int element1, int element2, int element3)
        { return std::to_string(element1) + std::to_string(element2) + std::to_string(element3); },
        test_vector2, test_vector2, test_vector2
    );                                                                                  //  For testing
    std::cout << "string: " + recursive_transform_result2.at(0).at(0) << std::endl;     // recursive_transform_result.at(0).at(0) is also a std::string
    
    //  std::deque<int> -> std::deque<std::string>
    std::deque<int> test_deque;
    test_deque.push_back(1);
    test_deque.push_back(1);
    test_deque.push_back(1);

    auto recursive_transform_result3 = recursive_transform<1>(
        ()(int element1, int element2, int element3)
        { return std::to_string(element1) + std::to_string(element2) + std::to_string(element3); },
        test_deque, test_deque, test_deque);                            //  For testing

    std::cout << "string: " + recursive_transform_result3.at(0) << std::endl;
    
    //  std::deque<std::deque<int>> -> std::deque<std::deque<std::string>>
    std::deque<decltype(test_deque)> test_deque2;
    test_deque2.push_back(test_deque);
    test_deque2.push_back(test_deque);
    test_deque2.push_back(test_deque);

    auto recursive_transform_result4 = recursive_transform<2>(
        ()(int element1, int element2, int element3)
        { return std::to_string(element1) + std::to_string(element2) + std::to_string(element3); },
        test_deque2, test_deque2, test_deque2);                         //  For testing

    std::cout << "string: " + recursive_transform_result4.at(0).at(0) << std::endl;
    
    //  std::list<int> -> std::list<std::string>
    std::list<int> test_list = { 1, 2, 3, 4 };
    auto recursive_transform_result5 = recursive_transform<1>(
        ()(int element1, int element2, int element3)
        { return std::to_string(element1) + std::to_string(element2) + std::to_string(element3); },
        test_list, test_list, test_list);                               //  For testing
    std::cout << "string: " + recursive_transform_result5.front() << std::endl;


    //  std::list<std::list<int>> -> std::list<std::list<std::string>>
    std::list<std::list<int>> test_list2 = { test_list, test_list, test_list, test_list };
    auto recursive_transform_result6 = recursive_transform<2>(
        ()(int element1, int element2, int element3)
        { return std::to_string(element1) + std::to_string(element2) + std::to_string(element3); },
        test_list2, test_list2, test_list2);                            //  For testing
    std::cout << "string: " + recursive_transform_result6.front().front() << std::endl;
    return;
}

The output of the testing code above:

*****ternary_test_cases*****
9
9
std::vector<int> -> std::vector<std::string>: 6
std::vector<string> -> std::vector<int>: 334
string: 111
string: 111
string: 111
string: 111
string: 111

Other details

The different container types can be used simultaneously as the parameters of recursive_transform, such as the following example.

std::list<std::string> data1{ "1", "4", "7" };
std::vector<std::string> data2{ "2", "5", "8" };
std::list<std::string> data3{ "3", "6", "9" };
std::list<std::string> data4{ "a", "b", "c" };
auto output = recursive_transform<1>(
    ()(auto element1, auto element2, auto element3, auto element4) { return element1 + element2 + element3 + element4; },
    data1, data2, data3, data4);
std::cout << typeid(output).name() << std::endl;
for (auto&& element : output)
{
    std::cout << element << std::endl;
}

However, the container type of the output (in the case of output is ranges) follows the first input range parameter. Therefore, the type of the container of output is std::list<>.

The output of the testing code above (from clang):

NSt7__cxx114listINS_12basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EEE
123a
456b
789c

All suggestions are welcome.

The summary information:

  • Which question it is a follow-up to?

    A recursive_transform template function for the binary operation cases in C++

  • What changes has been made in the code since last question?

    I am attempting to improve the extendibility of recursive_transform template function for the multiple parameters cases in this post.

  • Why a new review is being asked for?

    If there is any possible improvement, please let me know.

javascript – Flask – Calling python function which takes input parameters on button OnClick event

I have a Flask web app with a download button. When I click on the button I would like to execute a python method, not a javascript method. This python method should take as input some recently modified html code from the web page.

Most precisely the following happens: the user is asked to fill the blanks in some text and when she is done clicks on the download button. When the button gets clicked, a python function render_pdf() is executed that converts the html modified text to a pdf by using pdfkit library.

In its most simple version, my project has the following structure:

  • static/sample.pdf
  • templates/index.html
  • main.py

And this is the code I have so far:

main.py

from flask import Flask, render_template
import pdfkit 

app = Flask(__name__)


@app.route("https://stackoverflow.com/")
def index():
    return render_template('index.html')
    
if __name__ == "__main__":
    app.run(debug=True)

index.html

<body>

    <p class="test">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Temporibus, beatae!
        <span contenteditable="true" class="badge alert-info name" data-placeholder="Enter your name" data-focused-advice="Start typing"></span><i class="fa fa-lg fa-plus-circle"></i>
        Lorem ipsum dolor sit, amet consectetur adipisicing elit. Perspiciatis, laboriosam?
    </p>

    <button onclick="render_pdf()"><a href="../static/sample.pdf" download="my_file">Download</a></button>
</body>

The python method I would like to execute should be this one, passing htmlstr as input:

import pdfkit

def render_pdf(htmlstr):
    pdfkit.from_string(htmlstr, './static/sample.pdf') 

I know I can get with javascript the variable htmlstr by doing document.getElementsByClassName("test")(0).innerHTML;

I feel I am super close to get there and I have checked maybe a bit old but very similar questions but I just do not know how to pass the input html to the python method. What am I missing?

google search console – What should I add to the URL parameters tool to solve “Indexed although blocked by robots.txt”

I have an online shop. Google search console is warning that a URL is “Indexed although blocked by robots.txt”. When I use Google’s robots.txt tool, I see that the page is blocked by this rule.

enter image description here

I am building my website with OXID and when I asked in their forums (in German), say that all URLs with *?cur=x will be excluded to avoid duplicate content. To solve this problem, I should add a few parameters to Google Search Console URL-Parameter tool rather than changing robots.txt.

enter image description here

Which URL parameter should be added here?

Is this docker entrypoint bash script for passing parameters to the containerized app ‘good’?

Source code located here

I am trying to pass extra parameters from a container to the contained application. The following bash script is working to pass extra variables, but I’m not sure that it’s optimal, or a standard method for running a containerized application. Any insight would be appreciated.

#!/bin/bash

# allow arguments to be passed to dnsmasq
if (( ${1:0:1} = '-' )); then
  EXTRA_ARGS="$@"
  set --
elif (( ${1} == dnsmasq || ${1} == $(which dnsmasq) )); then
  EXTRA_ARGS="${@:2}"
  set --
fi

# default behaviour is to launch dnsmasq
if (( -z ${1} )); then
  echo "Starting dnsmasq..."
  exec $(which dnsmasq) --log-facility=- --keep-in-foreground --no-resolv --no-hosts --strict-order ${EXTRA_ARGS}
else
  exec "$@"
fi

python – How to prduce a new dataframe and name the dataframe by the parameters of a “def”

I have a problem. I would like to create a new DataFrame by using a “def” method in Python and the code, error messages as following. I realize it’s about the global and local parameter error. But still have no better solution. Hope seniors here can help me to solve the problem. Thank you.


def cut_date(start, end, df, column_name, df_2, df_3):
for i in range(len(df(column_name))-1):
if df(column_name)(i)(:4) == str(start-1) and df(column_name)(i+1)(:4) == str(start):
x = i
for i in range(len(df(column_name))-1):
if df(column_name)(i)(:4) == str(end) and df(column_name)(i+1)(:4) == str(end+1):
y = i
print(‘index %s: %s’ % (x, df(column_name)(x+1)))
print(‘index %s: %s’ % (y, df(column_name)(y)))

error messages as below

NameError Traceback (most recent call last)
in
1 cut_date(2013, 2016, df, ‘日期’, ‘df_date’, ‘df’)
—-> 2 df_date_mod

NameError: name ‘df_date_mod’ is not defined

sql server – SQL profiler not showing incoming parameters of store procedure

My Task

When user updates some values on the front end UI of an application, I want to know which SQL table/fields are updated, which SQL statements were executed, etc.

My method

Using SQL profiler, I updated some value from the applications user interface. then try to track the SQL statements executed. In Events Selection Tab, I selected all RPC & TSQL.

Problem

SQL Profiler does not show the value of incoming parameter, showing

e.g.

exec [sys].sp_describe_undeclared_parameters N'SELECT FIELD_NAME FROM EXTRA_FIELDS WHERE TABLE_NAME = @P1 AND EDITABLE = ''N'' ORDER BY CONTROL_NO, SEQNO'

Is there anyway I can get the @P1 value?

See screenshot

enter image description here

sharepoint server – RecordPageClick parameters

I need to change the search criteria paramater that is passed onto RecordPageClick method vis JavaScript

I am hoping to do this in the display template or the search page template

What is the best way to manipulate the parameters passed on to the RecordPageClick method