if (insts.attribute(m_timeStampName).isDate()) {
m_derivedPeriodicMakers = new ArrayList<Filter>();
// now add filters for each requested derived periodic value
if (m_am) {
// numeric binary
Add a = new Add();
a.setAttributeName("AM");
a.setInputFormat(insts);
result = Filter.useFilter(result, a);
m_derivedPeriodicMakers.add(a);
}
if (m_dayOfWeek) {
// nominal
Add a = new Add();
a.setAttributeName("DayOfWeek");
a.setNominalLabels("sun,mon,tue,wed,thu,fri,sat");
a.setInputFormat(result);
result = Filter.useFilter(result, a);
m_derivedPeriodicMakers.add(a);
}
if (m_dayOfMonth) {
// nominal
Add a = new Add();
a.setAttributeName("DayOfMonth");
a.setNominalLabels("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,"
+ "20,21,22,23,24,25,26,27,28,29,30,31");
a.setInputFormat(result);
result = Filter.useFilter(result, a);
m_derivedPeriodicMakers.add(a);
}
if (m_numDaysInMonth) {
Add a = new Add();
a.setAttributeName("NumDaysInMonth");
a.setInputFormat(insts);
result = Filter.useFilter(result, a);
m_derivedPeriodicMakers.add(a);
}
if (m_weekend) {
// numeric binary
Add a = new Add();
a.setAttributeName("Weekend");
a.setInputFormat(result);
result = Filter.useFilter(result, a);
m_derivedPeriodicMakers.add(a);
}
if (m_monthOfYear) {
// nominal
Add a = new Add();
a.setAttributeName("Month");
a.setNominalLabels("jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec");
a.setInputFormat(result);
result = Filter.useFilter(result, a);
m_derivedPeriodicMakers.add(a);
}
if (m_quarter) {
// nominal
Add a = new Add();
a.setAttributeName("Quarter");
a.setNominalLabels("Q1,Q2,Q3,Q4");
a.setInputFormat(result);
result = Filter.useFilter(result, a);
m_derivedPeriodicMakers.add(a);
}
// any custom date-derived periodics?
if (m_customPeriodics != null) {
for (String name : m_customPeriodics.keySet()) {
List<CustomPeriodicTest> l = m_customPeriodics.get(name);
// check to see if we should create a multi-label nominal
// attribute instead of a numeric binary attribute. If all
// test intervals have a non-null label then attribute will
// be nominal
boolean binary = false;
String labels = "";
Set<String> uniqueLabels = new HashSet<String>();
for (CustomPeriodicTest t : l) {
if (t.getLabel() == null || t.getLabel().length() == 0) {
binary = true;
break;
} else {
if (uniqueLabels.add(t.getLabel())) {
labels += t.getLabel() + ",";
}
}
}
Add a = new Add();
a.setAttributeName("c_" + name);
if (!binary) {
labels = labels.substring(0, labels.lastIndexOf(','));
a.setAttributeType(new SelectedTag("NOM", Add.TAGS_TYPE));
a.setNominalLabels(labels);
}
a.setInputFormat(result);
result = Filter.useFilter(result, a);
m_derivedPeriodicMakers.add(a);
}
}