[SOLVED] Generating Attributes for a specific date range

Analyticaltim
Analyticaltim New Altair Community Member
edited November 5 in Community Q&A
Dear Rapi-i Community,

I am working on a project where I need to generate an attribute for a specific date range. For example: Dates from 4/1/13 till 4/7/13 get a "week 1" attribute. Etc.

I was thinking about using the 'Generate Attribute' operation with a 'before date' command and an 'after date' command. But this seems very clunky and not replicateable over many iterations.

Do you have any advice to offer?  ::)
Thank you very much.
Tim
Tagged:

Answers

  • You could generate a week number in the year using the generate attributes operator with the following functions.

    date_str_custom(date_parse_custom(date,"dd/MM/yyyy"),"w")
    Here's a process you could modify.
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <process version="5.3.007">
     <context>
       <input/>
       <output/>
       <macros/>
     </context>
     <operator activated="true" class="process" compatibility="5.3.007" expanded="true" name="Process">
       <process expanded="true">
         <operator activated="true" class="generate_data_user_specification" compatibility="5.3.007" expanded="true" height="60" name="Generate Data by User Specification" width="90" x="112" y="120">
           <list key="attribute_values">
             <parameter key="date" value="&quot;13/4/2013&quot;"/>
           </list>
           <list key="set_additional_roles"/>
         </operator>
         <operator activated="true" class="generate_data_user_specification" compatibility="5.3.007" expanded="true" height="60" name="Generate Data by User Specification (2)" width="90" x="112" y="210">
           <list key="attribute_values">
             <parameter key="date" value="&quot;1/4/2013&quot;"/>
           </list>
           <list key="set_additional_roles"/>
         </operator>
         <operator activated="true" class="generate_data_user_specification" compatibility="5.3.007" expanded="true" height="60" name="Generate Data by User Specification (3)" width="90" x="112" y="300">
           <list key="attribute_values">
             <parameter key="date" value="&quot;19/3/2013&quot;"/>
           </list>
           <list key="set_additional_roles"/>
         </operator>
         <operator activated="true" class="append" compatibility="5.3.007" expanded="true" height="112" name="Append" width="90" x="246" y="210"/>
         <operator activated="true" class="generate_attributes" compatibility="5.3.007" expanded="true" height="76" name="Generate Attributes" width="90" x="380" y="210">
           <list key="function_descriptions">
             <parameter key="weekNumber" value="date_str_custom(date_parse_custom(date,&quot;dd/MM/yyyy&quot;),&quot;w&quot;)"/>
           </list>
         </operator>
         <connect from_op="Generate Data by User Specification" from_port="output" to_op="Append" to_port="example set 1"/>
         <connect from_op="Generate Data by User Specification (2)" from_port="output" to_op="Append" to_port="example set 2"/>
         <connect from_op="Generate Data by User Specification (3)" from_port="output" to_op="Append" to_port="example set 3"/>
         <connect from_op="Append" from_port="merged set" to_op="Generate Attributes" to_port="example set input"/>
         <connect from_op="Generate Attributes" from_port="example set output" 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>
  • Analyticaltim
    Analyticaltim New Altair Community Member
    This works great! Thank you very much.

    Tim
  • MacPhotoBiker
    MacPhotoBiker New Altair Community Member
    Hi,

    sorry, I know this topic is marked "solved", but there's something I don't understand.

    I tried this procedure and it works for "29/12/2012", but for dates "30/12/2012" and "31/12/2012" I get week 1, not 52.

    Could somebody help me out?
  • rowan_g
    rowan_g New Altair Community Member
    Hi,

    It's got to do with where the week numbering system starts. Some systems start at "Week 0" and some start at "Week 1". It also depends on the day of the week that the week starts on (Sunday or Monday)...
    It can get pretty confusing especially when you're working with different software....Excel, SQL ect ect...
    Also, I'm not sure what RapidMiner regards as the first week of the year...Is week 53 of the old year also week 0 or 1 of the new year?

    I work around for a lot of this stuff is using the year concatenated to the week "yyyyww"