A program to recognize and reward our most engaged community members
synchronized(this) { wait(2000);}return input[0];
<?xml version="1.0" encoding="UTF-8" standalone="no"?><process version="5.0"> <context> <input> <location/> </input> <output> <location/> </output> <macros/> </context> <operator activated="true" class="process" expanded="true" name="Process"> <process expanded="true" height="280" width="346"> <operator activated="true" class="loop_parameters" expanded="true" height="76" name="Loop Parameters" width="90" x="112" y="30"> <list key="parameters"> <parameter key="Set Macro.value" value="1,2,3,4,5,6,7,8,9,10"/> </list> <process expanded="true" height="527" width="922"> <operator activated="true" class="set_macro" expanded="true" height="76" name="Set Macro" width="90" x="112" y="30"> <parameter key="macro" value="index"/> <parameter key="value" value="will be replaced"/> </operator> <operator activated="true" class="read_model" expanded="true" height="60" name="Read Model" width="90" x="246" y="30"> <parameter key="model_file" value="your model file %{index}.mod"/> </operator> <connect from_port="input 1" to_op="Set Macro" to_port="through 1"/> <connect from_op="Set Macro" from_port="through 1" to_port="performance"/> <portSpacing port="source_input 1" spacing="0"/> <portSpacing port="source_input 2" spacing="0"/> <portSpacing port="sink_performance" spacing="0"/> <portSpacing port="sink_result 1" spacing="0"/> </process> </operator> <portSpacing port="source_input 1" spacing="0"/> <portSpacing port="sink_result 1" spacing="0"/> </process> </operator></process>
Let’s assume we have the following situation: We get data from a machine, that count’s the seconds since it was switched on. Each entry in this log file has this time stamp. Unfortu-nately other data sources we are going to use don’t have this relative time stamp. So we have to transform the relative format into a regular date and time format. Since RapidMiner doesn’t provide an operator solving this particular problem, we decide to write a small script. This problem doesn’t seem to be worth the effort of building a complete extension, because we can’t believe there are many other such stupid machines around, that don’t have an integrated clock. We build a simple process, which should do the trick:Image 1: A simple process for applying a scriptAs a first step we are going to load the data and then directly apply our script. As a last step we will do some date adjustment, but we will come back to this later. After loading we have an ExampleSet consisting of a number of attributes, describing the machine’s state. They are called att1, att2 to att500. The time stamp is contained in an attribute named relative time. During scripting we might ignore the state’s attribute. We just want to focus on the one single attribute.
1. import com.rapidminer.tools.Ontology;2. 3. ExampleSet exampleSet = input[0];4. Attributes attributes = exampleSet.getAttributes();5. Attribute sourceAttribute = attributes.get("relative time");6. String newName = ("date(" + sourceAttribute.getName() + ")";7. Attribute targetAttribute = AttributeFactory.createAttribute(newName, Ontology.DATE_TIME);8. targetAttribute.setTableIndex(sourceAttribute.getTableIndex());9. attributes.addRegular(targetAttribute);10. attributes.remove(sourceAttribute);11. 12. for (Example example: exampleSet) {13. double timeStampValue = example.getValue(targetAttribute);14. example.setValue(targetAttribute, timeStampValue * 1000);15. }16. 17. return(exampleSet);