use of com.google.visualization.datasource.datatable.ColumnDescription in project uPortal by Jasig.
the class BasePortletLayoutStatisticsController method getColumnDescriptions.
/**
* Create column descriptions for the portlet report. The default column description is the
* group name, but those items that are singular will move to the report title and only those
* that have 2 or more values selected on the form will be in the column title. Format: P - G P
* G P - G where P is portlet name, G is group name
*
* @param reportColumnDiscriminator
* @param form The original query form
* @return
*/
@Override
protected List<ColumnDescription> getColumnDescriptions(PortletLayoutAggregationDiscriminator reportColumnDiscriminator, F form) {
int groupSize = form.getGroups().size();
int portletSize = form.getPortlets().size();
String portletName = reportColumnDiscriminator.getPortletMapping().getFname();
String groupName = reportColumnDiscriminator.getAggregatedGroup().getGroupName();
String description = null;
if (showFullColumnHeaderDescriptions(form) || (groupSize > 1 && portletSize > 1)) {
description = String.format("%s - %s", portletName, groupName);
} else {
// Default to group name, else portlet name
description = groupSize == 1 && portletSize > 1 ? portletName : groupName;
}
final List<ColumnDescription> columnDescriptions = new ArrayList<ColumnDescription>();
columnDescriptions.add(new ColumnDescription(description, ValueType.NUMBER, description));
return columnDescriptions;
}
use of com.google.visualization.datasource.datatable.ColumnDescription in project uPortal by Jasig.
the class BaseStatisticsReportController method buildAggregationReport.
/**
* Build the aggregation {@link DataTable}
*/
protected final DataTable buildAggregationReport(F form) throws TypeMismatchException {
// Pull data out of form for per-group fetching
final AggregationInterval interval = form.getInterval();
final DateMidnight start = form.getStart();
final DateMidnight end = form.getEnd();
final DateTime startDateTime = start.toDateTime();
// Use a query end of the end date at 23:59:59
final DateTime endDateTime = end.plusDays(1).toDateTime().minusSeconds(1);
// Get the list of DateTimes used on the X axis in the report
final List<DateTime> reportTimes = this.intervalHelper.getIntervalStartDateTimesBetween(interval, startDateTime, endDateTime, maxIntervals);
final Map<D, SortedSet<T>> groupedAggregations = createColumnDiscriminatorMap(form);
// Determine the ValueType of the date/time column. Use the most specific column type
// possible
final ValueType dateTimeColumnType;
if (interval.isHasTimePart()) {
// If start/end are the same day just display the time
if (startDateTime.toDateMidnight().equals(endDateTime.toDateMidnight())) {
dateTimeColumnType = ValueType.TIMEOFDAY;
} else // interval has time data and start/end are on different days, show full date time
{
dateTimeColumnType = ValueType.DATETIME;
}
} else // interval is date only
{
dateTimeColumnType = ValueType.DATE;
}
// Setup the date/time column description
final ColumnDescription dateTimeColumn;
switch(dateTimeColumnType) {
case TIMEOFDAY:
{
dateTimeColumn = new ColumnDescription("time", dateTimeColumnType, "Time");
break;
}
default:
{
dateTimeColumn = new ColumnDescription("date", dateTimeColumnType, "Date");
}
}
final DataTable table = new JsonDataTable();
table.addColumn(dateTimeColumn);
// Setup columns in the DataTable
final Set<D> columnGroups = groupedAggregations.keySet();
for (final D columnMapping : columnGroups) {
final Collection<ColumnDescription> columnDescriptions = this.getColumnDescriptions(columnMapping, form);
table.addColumns(columnDescriptions);
}
// Query for all aggregation data in the time range for all groups. Only the
// interval and discriminator data is used from the keys.
final Set<K> keys = createAggregationsQueryKeyset(columnGroups, form);
final BaseAggregationDao<T, K> baseAggregationDao = this.getBaseAggregationDao();
final Collection<T> aggregations = baseAggregationDao.getAggregations(startDateTime, endDateTime, keys, extractGroupsArray(columnGroups));
// set
for (final T aggregation : aggregations) {
final D discriminator = aggregation.getAggregationDiscriminator();
final SortedSet<T> results = groupedAggregations.get(discriminator);
results.add(aggregation);
}
// Build Map from discriminator column mapping to result iterator to allow putting results
// into
// the correct column AND the correct time slot in the column
Comparator<? super D> comparator = getDiscriminatorComparator();
final Map<D, PeekingIterator<T>> groupedAggregationIterators = new TreeMap<D, PeekingIterator<T>>((comparator));
for (final Entry<D, SortedSet<T>> groupedAggregationEntry : groupedAggregations.entrySet()) {
groupedAggregationIterators.put(groupedAggregationEntry.getKey(), Iterators.peekingIterator(groupedAggregationEntry.getValue().iterator()));
}
/*
* populate the data, filling in blank spots. The full list of interval DateTimes is used to create every row in the
* query range. Then the iterator
*/
for (final DateTime rowTime : reportTimes) {
// create the row
final TableRow row = new TableRow();
// add the date to the first cell
final Value dateTimeValue;
switch(dateTimeColumnType) {
case DATE:
{
dateTimeValue = new DateValue(rowTime.getYear(), rowTime.getMonthOfYear() - 1, rowTime.getDayOfMonth());
break;
}
case TIMEOFDAY:
{
dateTimeValue = new TimeOfDayValue(rowTime.getHourOfDay(), rowTime.getMinuteOfHour(), 0);
break;
}
default:
{
dateTimeValue = new DateTimeValue(rowTime.getYear(), rowTime.getMonthOfYear() - 1, rowTime.getDayOfMonth(), rowTime.getHourOfDay(), rowTime.getMinuteOfHour(), 0, 0);
break;
}
}
row.addCell(new TableCell(dateTimeValue));
for (final PeekingIterator<T> groupedAggregationIteratorEntry : groupedAggregationIterators.values()) {
List<Value> values = null;
if (groupedAggregationIteratorEntry.hasNext()) {
final T aggr = groupedAggregationIteratorEntry.peek();
if (rowTime.equals(aggr.getDateTime())) {
// Data is for the correct time slot, advance the iterator
groupedAggregationIteratorEntry.next();
values = createRowValues(aggr, form);
}
}
// Gap in the data, fill it in using a null aggregation
if (values == null) {
values = createRowValues(null, form);
}
// Add the values to the row
for (final Value value : values) {
row.addCell(value);
}
}
table.addRow(row);
}
return table;
}
use of com.google.visualization.datasource.datatable.ColumnDescription in project uPortal by Jasig.
the class DefaultStatisticsReportLabellingStrategy method getColumnDescriptions.
/**
* Create column descriptions for the portlet report. The column descriptions are essentially
* the opposite of the title description changes. Those items that have size > 1 (more than one
* value selected in the report criteria) are displayed in the column description. If all items
* have only 1 value selected, the first item will be the column description.
*
* @param items ordered array of items in the report. NOTE: item ordering must be the same as
* with getReportTitleAugmentation
* @param showAll true to include all item descriptions in the column headings. Useful if report
* is being written to CSV, XML, HTML, etc. for importing into another tool
* @param form statistics report form
* @return List of column descriptions for the report
*/
@Override
public List<ColumnDescription> getColumnDescriptions(TitleAndCount[] items, boolean showAll, BaseReportForm form) {
String description = null;
int multipleValues = 0;
for (TitleAndCount item : items) {
if (item.getCriteriaValuesSelected() > 1 || showAll) {
multipleValues++;
description = description == null ? item.getCriteriaItem() : description + displaySeparator + item.getCriteriaItem();
}
}
// first item the column descriptor.
if (multipleValues == 0 || items.length == 1) {
description = items[0].getCriteriaItem();
}
final List<ColumnDescription> columnDescriptions = new ArrayList<ColumnDescription>();
columnDescriptions.add(new ColumnDescription(description, ValueType.NUMBER, description));
return columnDescriptions;
}
Aggregations