How can we use function expressions within operators in Rapidminer?

amit_pathak
amit_pathak New Altair Community Member
edited November 5 in Community Q&A
Hi, I am using a function expression in the generate macro operator as defined below.

`date_str_custom(date_now(),"EEE, MMM d, yyyy h:mm a")`

However, I would like to use this at various places within the process. I have put up email alerts throughout the process for different stages and I would want to capture this timestamp and add it to the email. Currently, I am creating a new generate macro operator before an email alert. Instead, it would be great if there is a way I can add this function expression just like I can add any macro value within an email body.

Tried `%{date_str_custom(date_now(),"EEE, MMM d, yyyy h:mm a")}` but it does not work. I understand it is a way to call macros.

Any way we can do this or maybe something better I can do?
Tagged:

Answers

  • MartinLiebig
    MartinLiebig
    Altair Employee
    edited October 2023
    Hi,
    you can just create a macro with this:
    date_str_custom(date_now(),"EEE, MMM d, yyyy h:mm a")

    and then use
    eval(%{macroName})

    That does it.

    You can even go crazy and change the time zone dynamically.

    BR,
    Martin




  • amit_pathak
    amit_pathak New Altair Community Member
    Hi Martin,

    This did not help me the way I wanted to be. I defined this macro under the name `time_stamp` and tried to use it in the email body as -

    <...><br><p>Process completed at eval((%{time_stamp<span>})</p><br><...></span>

    But this did not work. The email body had the text "eval(Tuesday, October 25, 2023 12:30 AM)". I would have ideally wanted the time stamp to be the current time and no the time at which the `time_stamp` macro was defined.
  • MartinLiebig
    MartinLiebig
    Altair Employee
    Can you maybe provide a simple example process to check?

    BR,
    Martin
  • amit_pathak
    amit_pathak New Altair Community Member
    edited October 2023
    Sure, PFB code. I am expecting that the console should output two timestamps with a gap of 5 seconds. (without defining a new macro)

    <?xml version="1.0" encoding="UTF-8"?><process version="9.9.002">

      <context>

        <input/>

        <output/>

        <macros/>

      </context>

      <operator activated="true" class="process" compatibility="9.9.002" expanded="true" name="Process">

        <parameter key="logverbosity" value="init"/>

        <parameter key="random_seed" value="2001"/>

        <parameter key="send_mail" value="never"/>

        <parameter key="notification_email" value=""/>

        <parameter key="process_duration_for_mail" value="30"/>

        <parameter key="encoding" value="SYSTEM"/>

        <process expanded="true">

          <operator activated="true" class="generate_macro" compatibility="9.9.002" expanded="true" height="68" name="Generate Macro" width="90" x="179" y="34">

            <list key="function_descriptions">

              <parameter key="timestamp" value="date_str_custom(date_now(),&quot;EEE, MMM d, yyyy h:mm:ss a&quot;)"/>

            </list>

          </operator>

          <operator activated="true" class="print_to_console" compatibility="9.9.002" expanded="true" height="68" name="Print to Console" width="90" x="581" y="34">

            <parameter key="log_value" value="Process Start: %{timestamp}. Process End: eval(%{timestamp})"/>

          </operator>

          <operator activated="true" class="delay" compatibility="9.9.002" expanded="true" height="82" name="Delay" width="90" x="380" y="34">

            <parameter key="delay" value="fixed"/>

            <parameter key="delay_amount" value="5000"/>

            <parameter key="min_delay_amount" value="0"/>

            <parameter key="max_delay_amount" value="1000"/>

          </operator>

          <connect from_op="Delay" from_port="through 1" to_port="result 1"/>

          <portSpacing port="source_input 1" spacing="0"/>

          <portSpacing port="sink_result 1" spacing="0"/>

          <portSpacing port="sink_result 2" spacing="0"/>

        </process>

      </operator>

    </process>