Compare date-macros in a Branch Operator

RichLRichL Member Posts: 7 Learner I
edited November 18 in Help
Hello everybody.
I´m having some problems with a process im trying to build.
So I want to check an existing table (that get´s updated through a scheduler) in my repository for updates, and if there is one, I want another process to start. If there is no update to it, then nothing happens.
To do so, I want to use the Branch-Operator, and the condition of it compares the latest entry of the table to the current date. Unfortunately the results are simply not right.
I saved the most recent date in the table as a macro, the current date also as a macro.
My question now is, how this problem should be entered into the "expression" window in the Branch operator?

I´d be very grateful for your help!

Best,
Richard

<?xml version="1.0" encoding="UTF-8"?><process version="9.5.000">
  <context>
    <input/>
    <output/>
    <macros/>
  </context>
  <operator activated="true" class="process" compatibility="9.5.000" 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="retrieve" compatibility="9.5.000" expanded="true" height="68" name="Retrieve xy data (2)" width="90" x="45" y="34">
        <parameter key="repository_entry" value="../data/xy data"/>
      </operator>
      <operator activated="true" class="nominal_to_date" compatibility="9.5.000" expanded="true" height="82" name="Nominal to Date" width="90" x="179" y="34">
        <parameter key="attribute_name" value="Erstellt"/>
        <parameter key="date_type" value="date_time"/>
        <parameter key="date_format" value="dd.MM.yyyy HH:mm"/>
        <parameter key="time_zone" value="SYSTEM"/>
        <parameter key="locale" value="English (United States)"/>
        <parameter key="keep_old_attribute" value="false"/>
      </operator>
      <operator activated="true" class="sort" compatibility="9.5.000" expanded="true" height="82" name="Sort" width="90" x="313" y="34">
        <parameter key="attribute_name" value="Erstellt"/>
        <parameter key="sorting_direction" value="decreasing"/>
      </operator>
      <operator activated="false" class="date_to_nominal" compatibility="9.5.000" expanded="true" height="82" name="Date to Nominal" width="90" x="447" y="136">
        <parameter key="attribute_name" value="Erstellt"/>
        <parameter key="date_format" value="dd.MM.yyyy HH:MM"/>
        <parameter key="time_zone" value="SYSTEM"/>
        <parameter key="locale" value="English (United States)"/>
        <parameter key="keep_old_attribute" value="false"/>
      </operator>
      <operator activated="true" class="extract_macro" compatibility="9.5.000" expanded="true" height="68" name="Extract Macro" width="90" x="648" y="34">
        <parameter key="macro" value="Date"/>
        <parameter key="macro_type" value="data_value"/>
        <parameter key="statistics" value="average"/>
        <parameter key="attribute_name" value="Erstellt"/>
        <parameter key="example_index" value="1"/>
        <list key="additional_macros"/>
      </operator>
      <operator activated="true" breakpoints="after" class="generate_macro" compatibility="9.5.000" expanded="true" height="82" name="Generate Macro" width="90" x="782" y="34">
        <list key="function_descriptions">
          <parameter key="Current Date" value="date_now()"/>
        </list>
      </operator>
      <operator activated="true" class="branch" compatibility="9.5.000" expanded="true" height="82" name="Branch" width="90" x="916" y="34">
        <parameter key="condition_type" value="expression"/>
        <parameter key="expression" value="%{Date}&gt;%{Current Date}"/>
        <parameter key="io_object" value="ANOVAMatrix"/>
        <parameter key="return_inner_output" value="true"/>
        <process expanded="true">
          <operator activated="true" class="productivity:execute_process" compatibility="9.5.000" expanded="true" height="82" name="Execute xy" width="90" x="179" y="34">
            <parameter key="process_location" value="../../../xy"/>
            <parameter key="use_input" value="true"/>
            <parameter key="store_output" value="false"/>
            <parameter key="propagate_metadata_recursively" value="true"/>
            <parameter key="cache_process" value="true"/>
            <list key="macros"/>
            <parameter key="fail_for_unknown_macros" value="true"/>
          </operator>
          <connect from_port="condition" to_op="Execute xy" to_port="input 1"/>
          <connect from_op="Execute xy" from_port="result 1" to_port="input 1"/>
          <portSpacing port="source_condition" spacing="0"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_input 1" spacing="0"/>
          <portSpacing port="sink_input 2" spacing="0"/>
        </process>
        <process expanded="true">
          <operator activated="true" class="throw_exception" compatibility="9.5.000" expanded="true" height="82" name="Throw Exception" width="90" x="179" y="34">
            <parameter key="message" value="oh no!"/>
          </operator>
          <connect from_port="condition" to_op="Throw Exception" to_port="through 1"/>
          <connect from_op="Throw Exception" from_port="through 1" to_port="input 1"/>
          <portSpacing port="source_condition" spacing="0"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_input 1" spacing="0"/>
          <portSpacing port="sink_input 2" spacing="0"/>
        </process>
      </operator>
      <connect from_op="Retrieve xy data (2)" from_port="output" to_op="Nominal to Date" to_port="example set input"/>
      <connect from_op="Nominal to Date" from_port="example set output" to_op="Sort" to_port="example set input"/>
      <connect from_op="Sort" from_port="example set output" to_op="Extract Macro" to_port="example set"/>
      <connect from_op="Extract Macro" from_port="example set" to_op="Generate Macro" to_port="through 1"/>
      <connect from_op="Generate Macro" from_port="through 1" to_op="Branch" to_port="condition"/>
      <connect from_op="Branch" from_port="input 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>


Best Answer

Answers

  • RichLRichL Member Posts: 7 Learner I
    Hey Martin,

    Thanks for the prompt reply.

    I only had to change the "<" sign and work a tiny bit on the parsing equation, but I managed to make it work!
    I just added seconds, the a (for PM/AM) and a z (for timezone).
    I also like to mention, that a future date compared to today´s brings a negative value of date_diff, while a past one brings a positive one.
    Many, many thanks for showing me the process... I´ve been trying to wrap my head around it for a while now! :)

    Best,
    Richard
  • mschmitzmschmitz Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, University Professor Posts: 2,201  RM Data Scientist
    Hi @RichL,
    one may just flip the two arguments of datediff :). I am always confusing myself which way around they are. That would do the same thing than flipping the < or multiplying by -1.

    Best,
    Martin
    - Head of Data Science Services at RapidMiner -
    Dortmund, Germany
Sign In or Register to comment.