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.Calendar;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,45 +15,63 @@ import org.json.JSONObject;
|
||||||
public class NumberedFilter extends Filter {
|
public class NumberedFilter extends Filter {
|
||||||
|
|
||||||
protected Double d;
|
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);
|
super(key, value);
|
||||||
this.d = n.doubleValue();
|
this.d = n.doubleValue();
|
||||||
|
this.orderingProperty = orderingProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NumberedFilter(Filter filter, Number n) {
|
public NumberedFilter(Filter filter, Number n, String orderingProperty) {
|
||||||
this(filter.key, filter.value, n);
|
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);
|
super(filter.key, filter.value);
|
||||||
|
|
||||||
|
this.d = new Double(0);
|
||||||
|
this.orderingProperty = orderingProperty;
|
||||||
|
|
||||||
for(Info info : timeSeries.values()){
|
for(Info info : timeSeries.values()){
|
||||||
JSONObject value = info.getValue();
|
JSONObject value = info.getValue();
|
||||||
|
if(this.d == null){
|
||||||
if(d == null){
|
this.d = value.getDouble(orderingProperty);
|
||||||
d = value.getDouble(orderingProperty);
|
|
||||||
}else{
|
}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;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param number the number to set
|
* @param d the d to set
|
||||||
*/
|
*/
|
||||||
public void setNumber(Number n) {
|
public void setDouble(Double d) {
|
||||||
this.d = n.doubleValue();
|
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} */
|
/** {@inheritDoc} */
|
||||||
public int compareTo(NumberedFilter numberedFilter) {
|
public int compareTo(NumberedFilter numberedFilter) {
|
||||||
int compareResult = this.d.compareTo(numberedFilter.d);
|
int compareResult = this.d.compareTo(numberedFilter.d);
|
||||||
|
|
|
@ -5,12 +5,12 @@ package org.gcube.accounting.analytics.persistence;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
|
||||||
import org.gcube.accounting.analytics.Filter;
|
import org.gcube.accounting.analytics.Filter;
|
||||||
import org.gcube.accounting.analytics.Info;
|
import org.gcube.accounting.analytics.Info;
|
||||||
|
import org.gcube.accounting.analytics.NumberedFilter;
|
||||||
import org.gcube.accounting.analytics.TemporalConstraint;
|
import org.gcube.accounting.analytics.TemporalConstraint;
|
||||||
import org.gcube.documentstore.records.AggregatedRecord;
|
import org.gcube.documentstore.records.AggregatedRecord;
|
||||||
|
|
||||||
|
@ -18,91 +18,125 @@ import org.gcube.documentstore.records.AggregatedRecord;
|
||||||
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
|
||||||
*/
|
*/
|
||||||
public abstract class AccountingPersistenceBackendQuery {
|
public abstract class AccountingPersistenceBackendQuery {
|
||||||
|
|
||||||
public static final int KEY_VALUES_LIMIT = 25;
|
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
|
* Query the persistence obtaining a Map where the date is the key and the
|
||||||
* the #Info is the value. The result is relative to an Usage Record Type,
|
* #Info is the value. The result is relative to an Usage Record Type,
|
||||||
* respect a TemporalConstraint and can be applied one or more filters.
|
* 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 aggregatedRecordClass
|
||||||
* @param filters list of filter to obtain the time series. If null or
|
* the Record Class of interest
|
||||||
* empty list get all data for the interested Record Class with the applying
|
* @param temporalConstraint
|
||||||
* temporal constraint. All Filter must have not null and not empty key and
|
* the TemporalConstraint (interval and aggregation)
|
||||||
* value.
|
* @param filters
|
||||||
* The filters are must be related to different keys and are in AND.
|
* list of filter to obtain the time series. If null or empty
|
||||||
* If the list contains more than one filter with the same key an Exception
|
* list get all data for the interested Record Class with the
|
||||||
* is thrown.
|
* 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
|
* @return the Map containing for each date in the required interval the
|
||||||
* requested data
|
* requested data
|
||||||
* @throws Exception if fails
|
* @throws Exception
|
||||||
|
* if fails
|
||||||
*/
|
*/
|
||||||
public abstract SortedMap<Calendar, Info> getTimeSeries(
|
public abstract SortedMap<Calendar, Info> getTimeSeries(
|
||||||
Class<? extends AggregatedRecord<?, ?>> aggregatedRecordClass,
|
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)
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||||
throws Exception;
|
throws Exception;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the list of possible values for a key for a certain usageRecord
|
* Return a SortedMap containing the TimeSeries for top values for a certain
|
||||||
* taking in account all Filters. The value for a certain key is identified
|
* key taking in account all Filters. The key is identified adding a Filter
|
||||||
* adding a Filter with a null value. Only one Filter with null value is
|
* with a null value. Only one Filter with null value is allowed otherwise
|
||||||
* allowed otherwise an Exception is thrown.
|
* an Exception is thrown. The values are ordered from the most occurred
|
||||||
* The values are ordered from the most occurred value.
|
* value.
|
||||||
* @param aggregatedRecordClass the Usage Record Class of interest
|
*
|
||||||
* @param temporalConstraint the TemporalConstraint (interval and aggregation)
|
* @param aggregatedRecordClass
|
||||||
* @param filters list of filter to obtain the time series. If null or
|
* the Usage Record Class of interest
|
||||||
* empty list get all data for the interested Record Class with the applying
|
* @param temporalConstraint
|
||||||
* temporal constraint. All Filter (except one) must have not null and not
|
* the TemporalConstraint (interval and aggregation)
|
||||||
* empty key and value. One Filter must have not null and not
|
* @param filters
|
||||||
* empty key and a null value.
|
* list of filter to obtain the time series. If null or empty
|
||||||
* The filters are must be related to different keys and are in AND.
|
* list get all data for the interested Record Class with the
|
||||||
* If the list contains more than one filter with the same key an Exception
|
* applying temporal constraint. All Filter (except one) must
|
||||||
* is thrown.
|
* have not null and not empty key and value. One Filter must
|
||||||
* If the list contains more than one filter with null value an Exception
|
* have not null and not empty key and a null value. The filters
|
||||||
* is thrown.
|
* are must be related to different keys and are in AND. If the
|
||||||
* @return a set containing the list of possible values
|
* list contains more than one filter with the same key an
|
||||||
* @throws Exception if fails
|
* 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 abstract SortedSet<Filter> getNextPossibleValues(
|
public SortedMap<NumberedFilter, SortedMap<Calendar, Info>> getTopValues(
|
||||||
Class<? extends AggregatedRecord<?, ?>> aggregatedRecordClass,
|
Class<? extends AggregatedRecord<?, ?>> aggregatedRecordClass,
|
||||||
TemporalConstraint temporalConstraint,
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||||
List<Filter> filters) throws Exception;
|
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 SortedSet containing the list of possible values
|
||||||
|
* @throws Exception
|
||||||
|
* if fails
|
||||||
|
*/
|
||||||
|
public SortedSet<NumberedFilter> getNextPossibleValues(
|
||||||
|
Class<? extends AggregatedRecord<?, ?>> aggregatedRecordClass,
|
||||||
|
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
|
* Close the connection to persistence
|
||||||
* @throws Exception if the close fails
|
*
|
||||||
|
* @throws Exception
|
||||||
|
* if the close fails
|
||||||
*/
|
*/
|
||||||
public abstract void close() throws Exception;
|
public abstract void close() throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,15 +5,16 @@ package org.gcube.accounting.analytics.persistence;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.gcube.accounting.analytics.Filter;
|
import org.gcube.accounting.analytics.Filter;
|
||||||
import org.gcube.accounting.analytics.Info;
|
import org.gcube.accounting.analytics.Info;
|
||||||
|
import org.gcube.accounting.analytics.NumberedFilter;
|
||||||
import org.gcube.accounting.analytics.TemporalConstraint;
|
import org.gcube.accounting.analytics.TemporalConstraint;
|
||||||
import org.gcube.accounting.datamodel.UsageRecord;
|
import org.gcube.accounting.datamodel.UsageRecord;
|
||||||
|
import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord;
|
||||||
import org.gcube.documentstore.records.AggregatedRecord;
|
import org.gcube.documentstore.records.AggregatedRecord;
|
||||||
import org.gcube.documentstore.records.Record;
|
import org.gcube.documentstore.records.Record;
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ public class AccountingPersistenceQuery {
|
||||||
return getQuerableKeys(instance);
|
return getQuerableKeys(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Calendar, Info> getTimeSeries(
|
public SortedMap<Calendar, Info> getTimeSeries(
|
||||||
Class<? extends AggregatedRecord<?,?>> aggregatedRecordClass,
|
Class<? extends AggregatedRecord<?,?>> aggregatedRecordClass,
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
@ -68,7 +69,17 @@ public class AccountingPersistenceQuery {
|
||||||
filters);
|
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,
|
Class<? extends AggregatedRecord<?,?>> aggregatedRecordClass,
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
@ -77,7 +88,7 @@ public class AccountingPersistenceQuery {
|
||||||
filters);
|
filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SortedSet<Filter> getNextPossibleValues(
|
public static SortedSet<NumberedFilter> getNextPossibleValues(
|
||||||
Class<? extends AggregatedRecord<?,?>> aggregatedRecordClass,
|
Class<? extends AggregatedRecord<?,?>> aggregatedRecordClass,
|
||||||
TemporalConstraint temporalConstraint, List<Filter> filters)
|
TemporalConstraint temporalConstraint, List<Filter> filters)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue