/* * Example : * If we have two attributes : price,model (facet type : range, categorical) * and start,end and gap for price are 1,100 and 10. Then this function * produces an empty vector for model (because it's categorical) and a vector with the following * values for price: * -large_value, 1, 11, 21, 31, 41, ..., 91, 101 */ void RangeFacetHelper::generateListOfIdsAndNames(std::vector<std::pair<unsigned, std::string> > * idsAndNames){ if(generateListOfIdsAndNamesFlag == true || idsAndNames == NULL){ ASSERT(false); return; } TypedValue lowerBoundToAdd = start; std::vector<TypedValue> lowerBounds; // Example : start : 1, gap : 10 , end : 100 // first -large_value is added as the first category // then 1, 11, 21, ...and 91 are added in the loop. // and 101 is added after loop. lowerBounds.push_back(lowerBoundToAdd.minimumValue()); // to collect data smaller than start while (lowerBoundToAdd < end) { lowerBounds.push_back(lowerBoundToAdd); // data of normal categories lowerBoundToAdd = lowerBoundToAdd + gap; } lowerBounds.push_back(end); // to collect data greater than end // now set the number of buckets numberOfBuckets = lowerBounds.size(); // now fill the output for(int lowerBoundsIndex = 0; lowerBoundsIndex < lowerBounds.size() ; lowerBoundsIndex++){ string bucketName = lowerBounds.at(lowerBoundsIndex).toString(); /* * If the type of this facet attribute is time, we should translate the number of * seconds from Jan 1st 1970 (aka "epoch") to a human readable representation of time. * For example, if this value is 1381271294, the name of this bucket is 10/8/2013 3:28:14. */ if(attributeType == ATTRIBUTE_TYPE_TIME){ long timeValue = lowerBounds.at(lowerBoundsIndex).getTimeTypedValue(); bucketName = DateAndTimeHandler::convertSecondsFromEpochToDateTimeString(&timeValue); } idsAndNames->push_back(std::make_pair(lowerBoundsIndex , bucketName)); } // And set the flag to make sure this function is called only once. generateListOfIdsAndNamesFlag = false; }