Added round to operation count weighted average
This commit is contained in:
parent
63b8fde61c
commit
776723567e
|
@ -128,13 +128,13 @@ public class Query {
|
|||
|
||||
// WEIGHTED AVERAGE
|
||||
case AggregatedServiceUsageRecord.DURATION:
|
||||
stringBuffer.append(", SUM(");
|
||||
stringBuffer.append(", ROUND(SUM(");
|
||||
stringBuffer.append(dbField);
|
||||
stringBuffer.append("*");
|
||||
appendTableField(AggregatedRecord.OPERATION_COUNT);
|
||||
stringBuffer.append(")/SUM(");
|
||||
appendTableField(AggregatedRecord.OPERATION_COUNT);
|
||||
stringBuffer.append(") AS ");
|
||||
stringBuffer.append(")) AS ");
|
||||
break;
|
||||
|
||||
case AggregatedServiceUsageRecord.MAX_INVOCATION_TIME:
|
||||
|
|
|
@ -6,13 +6,11 @@ package org.gcube.accounting.analytics.persistence.postgresql;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.gcube.accounting.analytics.Filter;
|
||||
import org.gcube.accounting.analytics.TemporalConstraint;
|
||||
import org.gcube.accounting.analytics.TemporalConstraint.AggregationMode;
|
||||
import org.gcube.accounting.analytics.exception.DuplicatedKeyFilterException;
|
||||
import org.gcube.accounting.analytics.exception.KeyException;
|
||||
import org.gcube.accounting.analytics.exception.ValueException;
|
||||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
||||
import org.junit.Test;
|
||||
|
@ -26,14 +24,27 @@ public class QueryTest extends ContextTest {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(QueryTest.class);
|
||||
|
||||
public static final String[] users = new String[]{"luca.frosini", "lucio.lelii", "francesco.frangiacrapa", "fabio.sinibaldi", "massimiliano.assante", "giancarlo.panichi", "leonardo.candela", "pasquale.pagano"};
|
||||
|
||||
private static final Random random;
|
||||
|
||||
static {
|
||||
random = new Random();
|
||||
}
|
||||
|
||||
public static String getRandomUser() {
|
||||
int randomNumber = random.nextInt(users.length);
|
||||
return users[randomNumber];
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNoContextTimeSeriesQuery() throws DuplicatedKeyFilterException, KeyException, ValueException, Exception {
|
||||
logger.debug("test");
|
||||
public void testGetNoContextTimeSeriesQuery() throws Exception {
|
||||
Calendar startTimeCalendar = Calendar.getInstance();
|
||||
startTimeCalendar.set(Calendar.YEAR, 2020);
|
||||
startTimeCalendar.set(Calendar.MONTH, Calendar.MARCH);
|
||||
startTimeCalendar.set(Calendar.DAY_OF_MONTH, 15);
|
||||
startTimeCalendar.set(Calendar.HOUR_OF_DAY, 16);
|
||||
startTimeCalendar.set(Calendar.MINUTE, 15);
|
||||
startTimeCalendar.set(Calendar.DAY_OF_MONTH, 1);
|
||||
startTimeCalendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
startTimeCalendar.set(Calendar.MINUTE, 0);
|
||||
|
||||
Calendar entTimeCalendar = Calendar.getInstance();
|
||||
entTimeCalendar.set(Calendar.MONTH, Calendar.MARCH);
|
||||
|
@ -42,7 +53,7 @@ public class QueryTest extends ContextTest {
|
|||
entTimeCalendar.set(Calendar.MINUTE, 17);
|
||||
|
||||
List<Filter> filters = new ArrayList<>();
|
||||
Filter filter = new Filter(UsageRecord.CONSUMER_ID, "name.surname");
|
||||
Filter filter = new Filter(UsageRecord.CONSUMER_ID, getRandomUser());
|
||||
filters.add(filter);
|
||||
|
||||
TemporalConstraint temporalConstraint = new TemporalConstraint(startTimeCalendar.getTimeInMillis(), entTimeCalendar.getTimeInMillis(), AggregationMode.MINUTELY);
|
||||
|
|
Loading…
Reference in New Issue