Pages: [1]
  Print  
Author Topic: [SOLVED] Generating Attributes for a specific date range  (Read 1014 times)
Analyticaltim
Newbie
*
Posts: 15


« on: April 18, 2013, 04:46:13 PM »

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?  Roll Eyes
Thank you very much.
Tim
« Last Edit: April 18, 2013, 07:59:16 PM by Analyticaltim » Logged
awchisholm
Sr. Member
****
Posts: 404


WWW
« Reply #1 on: April 18, 2013, 05:49:21 PM »

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

Code:
date_str_custom(date_parse_custom(date,"dd/MM/yyyy"),"w")

Here's a process you could modify.

Code:
<?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>
« Last Edit: April 18, 2013, 11:42:56 PM by awchisholm » Logged

Analyticaltim
Newbie
*
Posts: 15


« Reply #2 on: April 18, 2013, 08:17:53 PM »

This works great! Thank you very much.

Tim
Logged
MacPhotoBiker
Jr. Member
**
Posts: 56


WWW
« Reply #3 on: June 18, 2013, 06:06:50 AM »

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?
Logged

MacPhotoBiker
Just do your Core Business. We do the rest.
rowan.g
Newbie
*
Posts: 47


« Reply #4 on: June 20, 2013, 01:23:20 AM »

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"
Logged
Pages: [1]
  Print  
 
Jump to: