Reorganizing library
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-analytics@125464 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
2210ea799f
commit
31e6f90591
|
@ -6,7 +6,6 @@ package org.gcube.accounting.analytics;
|
|||
import java.util.Calendar;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
|
@ -16,43 +15,61 @@ import org.json.JSONObject;
|
|||
public class NumberedFilter extends Filter {
|
||||
|
||||
protected Double d;
|
||||
protected String orderingProperty;
|
||||
|
||||
public NumberedFilter(String key, String value, Number n) {
|
||||
public NumberedFilter(String key, String value, Number n, String orderingProperty) {
|
||||
super(key, value);
|
||||
this.d = n.doubleValue();
|
||||
this.orderingProperty = orderingProperty;
|
||||
}
|
||||
|
||||
public NumberedFilter(Filter filter, Number n) {
|
||||
this(filter.key, filter.value, n);
|
||||
public NumberedFilter(Filter filter, Number n, String orderingProperty) {
|
||||
this(filter.key, filter.value, n, orderingProperty);
|
||||
}
|
||||
|
||||
public NumberedFilter(Filter filter, Map<Calendar, Info> timeSeries, String orderingProperty) throws JSONException {
|
||||
public NumberedFilter(Filter filter, Map<Calendar, Info> timeSeries, String orderingProperty) throws Exception {
|
||||
super(filter.key, filter.value);
|
||||
|
||||
this.d = new Double(0);
|
||||
this.orderingProperty = orderingProperty;
|
||||
|
||||
for(Info info : timeSeries.values()){
|
||||
JSONObject value = info.getValue();
|
||||
|
||||
if(d == null){
|
||||
d = value.getDouble(orderingProperty);
|
||||
if(this.d == null){
|
||||
this.d = value.getDouble(orderingProperty);
|
||||
}else{
|
||||
d = d + value.getDouble(orderingProperty);
|
||||
this.d = this.d + value.getDouble(orderingProperty);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number
|
||||
* @return the d
|
||||
*/
|
||||
public Number getNumber() {
|
||||
public Double getDouble() {
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param number the number to set
|
||||
* @param d the d to set
|
||||
*/
|
||||
public void setNumber(Number n) {
|
||||
this.d = n.doubleValue();
|
||||
public void setDouble(Double d) {
|
||||
this.d = d;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the orderingProperty
|
||||
*/
|
||||
public String getOrderingProperty() {
|
||||
return orderingProperty;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param orderingProperty the orderingProperty to set
|
||||
*/
|
||||
public void setOrderingProperty(String orderingProperty) {
|
||||
this.orderingProperty = orderingProperty;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
|
|
@ -5,12 +5,12 @@ package org.gcube.accounting.analytics.persistence;
|
|||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.gcube.accounting.analytics.Filter;
|
||||
import org.gcube.accounting.analytics.Info;
|
||||
import org.gcube.accounting.analytics.NumberedFilter;
|
||||
import org.gcube.accounting.analytics.TemporalConstraint;
|
||||
import org.gcube.documentstore.records.AggregatedRecord;
|
||||
|
||||
|
@ -21,87 +21,121 @@ public abstract class AccountingPersistenceBackendQuery {
|
|||
|
||||
public static final int KEY_VALUES_LIMIT = 25;
|
||||
|
||||
protected abstract void prepareConnection(AccountingPersistenceBackendQueryConfiguration configuration) throws Exception;
|
||||
protected abstract void prepareConnection(
|
||||
AccountingPersistenceBackendQueryConfiguration configuration)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Query the persistence obtaining a Map where the date is the key and
|
||||
* the #Info is the value. The result is relative to an Usage Record Type,
|
||||
* Query the persistence obtaining a Map where the date is the key and the
|
||||
* #Info is the value. The result is relative to an Usage Record Type,
|
||||
* respect a TemporalConstraint and can be applied one or more filters.
|
||||
* @param aggregatedRecordClass the Record Class of interest
|
||||
* @param temporalConstraint the TemporalConstraint (interval and aggregation)
|
||||
* @param filters list of filter to obtain the time series. If null or
|
||||
* empty list get all data for the interested Record Class with the applying
|
||||
* temporal constraint. All Filter must have not null and not empty key and
|
||||
* value.
|
||||
* The filters are must be related to different keys and are in AND.
|
||||
* If the list contains more than one filter with the same key an Exception
|
||||
* is thrown.
|
||||
*
|
||||
* @param aggregatedRecordClass
|
||||
* the Record Class of interest
|
||||
* @param temporalConstraint
|
||||
* the TemporalConstraint (interval and aggregation)
|
||||
* @param filters
|
||||
* list of filter to obtain the time series. If null or empty
|
||||
* list get all data for the interested Record Class with the
|
||||
* applying temporal constraint. All Filter must have not null
|
||||
* and not empty key and value. The filters are must be related
|
||||
* to different keys and are in AND. If the list contains more
|
||||
* than one filter with the same key an Exception is thrown.
|
||||
* @return the Map containing for each date in the required interval the
|
||||
* requested data
|
||||
* @throws Exception if fails
|
||||
* @throws Exception
|
||||
* if fails
|
||||
*/
|
||||
public abstract SortedMap<Calendar, Info> getTimeSeries(
|
||||
Class<? extends AggregatedRecord<?, ?>> aggregatedRecordClass,
|
||||
TemporalConstraint temporalConstraint,
|
||||
List<Filter> filters) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Return a SortedMap containing the TimeSeries for top values for a
|
||||
* certain key taking in account all Filters. The key is identified
|
||||
* adding a Filter with a null value. Only one Filter with null value is
|
||||
* allowed otherwise an Exception is thrown.
|
||||
* The values are ordered from the most occurred value.
|
||||
* @param aggregatedRecordClass the Usage Record Class of interest
|
||||
* @param temporalConstraint the TemporalConstraint (interval and aggregation)
|
||||
* @param filters list of filter to obtain the time series. If null or
|
||||
* empty list get all data for the interested Record Class with the applying
|
||||
* temporal constraint. All Filter (except one) must have not null and not
|
||||
* empty key and value. One Filter must have not null and not
|
||||
* empty key and a null value.
|
||||
* The filters are must be related to different keys and are in AND.
|
||||
* If the list contains more than one filter with the same key an Exception
|
||||
* is thrown.
|
||||
* If the list contains more than one filter with null value an Exception
|
||||
* is thrown.
|
||||
* @return a set containing the list of possible values
|
||||
* @throws Exception if fails
|
||||
*/
|
||||
public abstract SortedMap<Filter, Map<Calendar, Info>> getTopValues(
|
||||
Class<? extends AggregatedRecord<?, ?>> recordClass,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Return a SortedMap containing the TimeSeries for top values for a certain
|
||||
* key taking in account all Filters. The key is identified adding a Filter
|
||||
* with a null value. Only one Filter with null value is allowed otherwise
|
||||
* an Exception is thrown. The values are ordered from the most occurred
|
||||
* value.
|
||||
*
|
||||
* @param aggregatedRecordClass
|
||||
* the Usage Record Class of interest
|
||||
* @param temporalConstraint
|
||||
* the TemporalConstraint (interval and aggregation)
|
||||
* @param filters
|
||||
* list of filter to obtain the time series. If null or empty
|
||||
* list get all data for the interested Record Class with the
|
||||
* applying temporal constraint. All Filter (except one) must
|
||||
* have not null and not empty key and value. One Filter must
|
||||
* have not null and not empty key and a null value. The filters
|
||||
* are must be related to different keys and are in AND. If the
|
||||
* list contains more than one filter with the same key an
|
||||
* Exception is thrown. If the list contains more than one filter
|
||||
* with null value an Exception is thrown.
|
||||
* @return a SortedMap
|
||||
* @throws Exception
|
||||
* if fails
|
||||
*/
|
||||
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
||||
Class<? extends AggregatedRecord<?, ?>> aggregatedRecordClass,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||
throws Exception {
|
||||
String orderingProperty = AccountingPersistenceQuery
|
||||
.getDefaultOrderingProperties(aggregatedRecordClass);
|
||||
return getTopValues(aggregatedRecordClass, temporalConstraint, filters,
|
||||
orderingProperty);
|
||||
}
|
||||
|
||||
public abstract SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
||||
Class<? extends AggregatedRecord<?, ?>> aggregatedRecordClass,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String orderingProperty) throws Exception;
|
||||
|
||||
/**
|
||||
* Return the list of possible values for a key for a certain usageRecord
|
||||
* taking in account all Filters. The value for a certain key is identified
|
||||
* adding a Filter with a null value. Only one Filter with null value is
|
||||
* allowed otherwise an Exception is thrown.
|
||||
* The values are ordered from the most occurred value.
|
||||
* @param aggregatedRecordClass the Usage Record Class of interest
|
||||
* @param temporalConstraint the TemporalConstraint (interval and aggregation)
|
||||
* @param filters list of filter to obtain the time series. If null or
|
||||
* empty list get all data for the interested Record Class with the applying
|
||||
* temporal constraint. All Filter (except one) must have not null and not
|
||||
* empty key and value. One Filter must have not null and not
|
||||
* empty key and a null value.
|
||||
* The filters are must be related to different keys and are in AND.
|
||||
* If the list contains more than one filter with the same key an Exception
|
||||
* is thrown.
|
||||
* If the list contains more than one filter with null value an Exception
|
||||
* is thrown.
|
||||
* @return a set containing the list of possible values
|
||||
* @throws Exception if fails
|
||||
* allowed otherwise an Exception is thrown. The values are ordered from the
|
||||
* most occurred value.
|
||||
*
|
||||
* @param aggregatedRecordClass
|
||||
* the Usage Record Class of interest
|
||||
* @param temporalConstraint
|
||||
* the TemporalConstraint (interval and aggregation)
|
||||
* @param filters
|
||||
* list of filter to obtain the time series. If null or empty
|
||||
* list get all data for the interested Record Class with the
|
||||
* applying temporal constraint. All Filter (except one) must
|
||||
* have not null and not empty key and value. One Filter must
|
||||
* have not null and not empty key and a null value. The filters
|
||||
* are must be related to different keys and are in AND. If the
|
||||
* list contains more than one filter with the same key an
|
||||
* Exception is thrown. If the list contains more than one filter
|
||||
* with null value an Exception is thrown.
|
||||
* @return a SortedSet containing the list of possible values
|
||||
* @throws Exception
|
||||
* if fails
|
||||
*/
|
||||
public abstract SortedSet<Filter> getNextPossibleValues(
|
||||
public SortedSet<NumberedFilter> getNextPossibleValues(
|
||||
Class<? extends AggregatedRecord<?, ?>> aggregatedRecordClass,
|
||||
TemporalConstraint temporalConstraint,
|
||||
List<Filter> filters) throws Exception;
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||
throws Exception {
|
||||
String orderingProperty = AccountingPersistenceQuery
|
||||
.getDefaultOrderingProperties(aggregatedRecordClass);
|
||||
return getNextPossibleValues(aggregatedRecordClass, temporalConstraint,
|
||||
filters, orderingProperty);
|
||||
}
|
||||
|
||||
public abstract SortedSet<NumberedFilter> getNextPossibleValues(
|
||||
Class<? extends AggregatedRecord<?, ?>> aggregatedRecordClass,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters,
|
||||
String orderingProperty) throws Exception;
|
||||
|
||||
/**
|
||||
* Close the connection to persistence
|
||||
* @throws Exception if the close fails
|
||||
*
|
||||
* @throws Exception
|
||||
* if the close fails
|
||||
*/
|
||||
public abstract void close() throws Exception;
|
||||
|
||||
|
|
|
@ -5,15 +5,16 @@ package org.gcube.accounting.analytics.persistence;
|
|||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.gcube.accounting.analytics.Filter;
|
||||
import org.gcube.accounting.analytics.Info;
|
||||
import org.gcube.accounting.analytics.NumberedFilter;
|
||||
import org.gcube.accounting.analytics.TemporalConstraint;
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
|
||||
import org.gcube.documentstore.records.AggregatedRecord;
|
||||
import org.gcube.documentstore.records.Record;
|
||||
|
||||
|
@ -59,7 +60,7 @@ public class AccountingPersistenceQuery {
|
|||
return getQuerableKeys(instance);
|
||||
}
|
||||
|
||||
public Map<Calendar, Info> getTimeSeries(
|
||||
public SortedMap<Calendar, Info> getTimeSeries(
|
||||
Class<? extends AggregatedRecord<?,?>> aggregatedRecordClass,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||
throws Exception {
|
||||
|
@ -68,7 +69,17 @@ public class AccountingPersistenceQuery {
|
|||
filters);
|
||||
}
|
||||
|
||||
public static SortedMap<Filter, Map<Calendar, Info>> getTopValues(
|
||||
public static String getDefaultOrderingProperties(Class<? extends AggregatedRecord<?, ?>> recordClass){
|
||||
if(recordClass.isAssignableFrom(AggregatedStorageUsageRecord.class)){
|
||||
return AggregatedStorageUsageRecord.DATA_VOLUME;
|
||||
}
|
||||
return AggregatedRecord.OPERATION_COUNT;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
||||
Class<? extends AggregatedRecord<?,?>> aggregatedRecordClass,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||
throws Exception {
|
||||
|
@ -77,7 +88,7 @@ public class AccountingPersistenceQuery {
|
|||
filters);
|
||||
}
|
||||
|
||||
public static SortedSet<Filter> getNextPossibleValues(
|
||||
public static SortedSet<NumberedFilter> getNextPossibleValues(
|
||||
Class<? extends AggregatedRecord<?,?>> aggregatedRecordClass,
|
||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||
throws Exception {
|
||||
|
|
Loading…
Reference in New Issue