69: Create new Accounting Portlet
Task-Url: https://support.d4science.org/issues/69 Updated to fix UTC TimeZone git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/admin/accounting-manager@118933 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
0475946c05
commit
303f43218c
|
@ -30,6 +30,8 @@ import org.gcube.portlets.widgets.sessionchecker.client.CheckSession;
|
|||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.event.shared.EventBus;
|
||||
import com.google.gwt.event.shared.SimpleEventBus;
|
||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
|
||||
import com.google.gwt.i18n.client.LocaleInfo;
|
||||
import com.google.gwt.user.client.Cookies;
|
||||
import com.google.gwt.user.client.Timer;
|
||||
|
@ -235,11 +237,14 @@ public class AccountingManagerController {
|
|||
|
||||
private void createDefaultChart(AccountingType accountingType) {
|
||||
accountingMonitor = new AccountingMonitor();
|
||||
Date d = new Date();
|
||||
CalendarUtil.addMonthsToDate(d, -1);
|
||||
|
||||
SeriesRequest seriesRequest = new SeriesRequest(new AccountingPeriod(d,
|
||||
new Date(), AccountingPeriodMode.DAILY), null);
|
||||
Date now = new Date();
|
||||
DateTimeFormat dtf=DateTimeFormat.getFormat(PredefinedFormat.YEAR_MONTH_DAY);
|
||||
String currentDate=dtf.format(now);
|
||||
Date date=dtf.parse(currentDate);
|
||||
Date lastMonth=new Date(date.getTime());
|
||||
CalendarUtil.addMonthsToDate(lastMonth, -1);
|
||||
SeriesRequest seriesRequest = new SeriesRequest(new AccountingPeriod(lastMonth,
|
||||
date, AccountingPeriodMode.DAILY), null);
|
||||
this.accountingType = accountingType;
|
||||
|
||||
AccountingStateData accountingStateData = new AccountingStateData(
|
||||
|
|
|
@ -7,6 +7,7 @@ import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesSto
|
|||
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesStorageData;
|
||||
import org.gcube.portlets.admin.accountingmanager.shared.exception.AccountingManagerChartDrawException;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.github.highcharts4gwt.client.view.widget.HighchartsLayoutPanel;
|
||||
import com.github.highcharts4gwt.model.array.api.ArrayNumber;
|
||||
import com.github.highcharts4gwt.model.array.api.ArrayString;
|
||||
|
@ -15,6 +16,8 @@ import com.github.highcharts4gwt.model.factory.jso.JsoHighchartsOptionFactory;
|
|||
import com.github.highcharts4gwt.model.highcharts.option.api.ChartOptions;
|
||||
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesArea;
|
||||
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesColumn;
|
||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
|
||||
import com.sencha.gxt.widget.core.client.container.MarginData;
|
||||
import com.sencha.gxt.widget.core.client.container.SimpleContainer;
|
||||
|
||||
|
@ -26,6 +29,7 @@ import com.sencha.gxt.widget.core.client.container.SimpleContainer;
|
|||
*
|
||||
*/
|
||||
public class AccountingChart4Storage extends AccountingChartBuilder {
|
||||
|
||||
|
||||
private AccountingStateData accountingStateData;
|
||||
|
||||
|
@ -35,8 +39,8 @@ public class AccountingChart4Storage extends AccountingChartBuilder {
|
|||
|
||||
@Override
|
||||
public void buildChart() throws AccountingManagerChartDrawException {
|
||||
AccountingChartPanel accountingChartPanel=null;
|
||||
|
||||
AccountingChartPanel accountingChartPanel = null;
|
||||
|
||||
if (accountingStateData == null
|
||||
|| accountingStateData.getAccountingType() == null
|
||||
|| accountingStateData.getSeriesRequest() == null
|
||||
|
@ -44,47 +48,55 @@ public class AccountingChart4Storage extends AccountingChartBuilder {
|
|||
accountingChartSpec.setChart(accountingChartPanel);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!(accountingStateData
|
||||
.getSeriesResponse() instanceof SeriesStorage)){
|
||||
|
||||
if (!(accountingStateData.getSeriesResponse() instanceof SeriesStorage)) {
|
||||
accountingChartSpec.setChart(accountingChartPanel);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
SeriesStorage seriesStorage = (SeriesStorage) accountingStateData
|
||||
.getSeriesResponse();
|
||||
|
||||
double minRange = ChartTimeMeasure
|
||||
.calculateMinRange(accountingStateData.getSeriesRequest()
|
||||
.getAccountingPeriod());
|
||||
|
||||
double interval = ChartTimeMeasure
|
||||
.calculateInterval(accountingStateData.getSeriesRequest()
|
||||
.getAccountingPeriod());
|
||||
|
||||
Date dateStart = new Date(accountingStateData.getSeriesRequest()
|
||||
.getAccountingPeriod().getStartDate().getTime());
|
||||
dateStart.setTime(dateStart.getTime() + ChartTimeMeasure.timeZoneOffset()*ChartTimeMeasure.MINUTE);
|
||||
|
||||
double minRange = ChartTimeMeasure.calculateMinRange(accountingStateData
|
||||
.getSeriesRequest().getAccountingPeriod());
|
||||
|
||||
double interval= ChartTimeMeasure.calculateInterval(accountingStateData
|
||||
.getSeriesRequest().getAccountingPeriod());
|
||||
|
||||
Date dateStart=accountingStateData.getSeriesRequest().getAccountingPeriod().getStartDate();
|
||||
|
||||
Log.debug("BuildChart DateStart: "
|
||||
+ DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_FULL)
|
||||
.format(dateStart));
|
||||
|
||||
HighchartsOptionFactory highchartsFactory = new JsoHighchartsOptionFactory();
|
||||
highchartsFactory.createGlobalOptions().global().useUTC(true);
|
||||
|
||||
|
||||
|
||||
ChartOptions options = highchartsFactory.createChartOptions();
|
||||
options.chart().zoomType("xy");
|
||||
options.exporting().buttons().contextButton().enabled(true);
|
||||
options.title().text("Accounting Storage");
|
||||
|
||||
/*options.subtitle().text("Click and drag in the plot area to zoom in"); */
|
||||
|
||||
/*
|
||||
* options.subtitle().text("Click and drag in the plot area to zoom in");
|
||||
*/
|
||||
|
||||
ArrayString colors = options.colors();
|
||||
// colors.setValue(0, "#cc0038");
|
||||
// colors.setValue(1, "#32cd32");
|
||||
|
||||
|
||||
// xAxis
|
||||
options.xAxis().type("datetime").minRange(minRange);
|
||||
|
||||
// yAxis
|
||||
// options.yAxis().title().text("Exchange rate");
|
||||
// Highcharts.getOptions().colors[0]
|
||||
|
||||
|
||||
|
||||
String multiAxis = "[{" + " \"id\": \"OperationCount\","
|
||||
+ " \"labels\": { " + " \"format\": \"{value}\","
|
||||
+ " \"style\": { " + " \"color\": \""
|
||||
|
@ -120,7 +132,7 @@ public class AccountingChart4Storage extends AccountingChartBuilder {
|
|||
+ " }," + " \"opposite\": \"true\"" + "}]";
|
||||
|
||||
options.setFieldAsJsonObject("yAxis", multiAxis);
|
||||
|
||||
|
||||
// TODO does not seem to be working
|
||||
String fillcolor = "{" + "\"linearGradient\": {" + "\"x1\": 0,"
|
||||
+ "\"y1\": 0," + "\"x2\": 0," + "\"y2\": 1" + "},"
|
||||
|
@ -131,37 +143,33 @@ public class AccountingChart4Storage extends AccountingChartBuilder {
|
|||
.setFieldAsJsonObject("fillColor", fillcolor).marker()
|
||||
.radius(2).lineWidth(1).states().hover().lineWidth(1);
|
||||
|
||||
|
||||
|
||||
SeriesColumn seriesOperationCount = highchartsFactory.createSeriesColumn();
|
||||
SeriesColumn seriesOperationCount = highchartsFactory
|
||||
.createSeriesColumn();
|
||||
seriesOperationCount.name("Operation Count");
|
||||
seriesOperationCount.color(colors.get(1));
|
||||
seriesOperationCount.type("column");
|
||||
|
||||
ArrayNumber dataOperationCount = seriesOperationCount
|
||||
.dataAsArrayNumber();
|
||||
|
||||
seriesOperationCount.pointInterval(interval).pointStart(dateStart.getTime());
|
||||
|
||||
|
||||
seriesOperationCount.pointInterval(interval).pointStart(
|
||||
dateStart.getTime());
|
||||
|
||||
SeriesArea seriesDataVolume = highchartsFactory.createSeriesArea();
|
||||
seriesDataVolume.name("Data Volume");
|
||||
seriesDataVolume.color(colors.get(0));
|
||||
seriesDataVolume.yAxisAsString("DataVolume");
|
||||
|
||||
|
||||
ArrayNumber dataDataVolume = seriesDataVolume.dataAsArrayNumber();
|
||||
|
||||
|
||||
seriesDataVolume.pointInterval(interval).pointStart(
|
||||
dateStart.getTime());
|
||||
|
||||
seriesDataVolume.pointInterval(interval)
|
||||
.pointStart(dateStart.getTime());
|
||||
|
||||
for (SeriesStorageData seriesStorageData : seriesStorage.getSeries()) {
|
||||
dataOperationCount.push(seriesStorageData.getOperationCount());
|
||||
dataDataVolume.push(seriesStorageData.getDataVolume());
|
||||
}
|
||||
|
||||
|
||||
options.series().addToEnd(seriesOperationCount);
|
||||
options.series().addToEnd(seriesDataVolume);
|
||||
|
||||
|
@ -181,11 +189,11 @@ public class AccountingChart4Storage extends AccountingChartBuilder {
|
|||
HighchartsLayoutPanel highchartsLayoutPanel = new HighchartsLayoutPanel();
|
||||
|
||||
highchartsLayoutPanel.renderChart(options);
|
||||
|
||||
SimpleContainer container=new SimpleContainer();
|
||||
|
||||
SimpleContainer container = new SimpleContainer();
|
||||
container.add(highchartsLayoutPanel, new MarginData(0));
|
||||
|
||||
accountingChartPanel=new AccountingChartPanel(container);
|
||||
|
||||
accountingChartPanel = new AccountingChartPanel(container);
|
||||
|
||||
accountingChartSpec.setChart(accountingChartPanel);
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
package org.gcube.portlets.admin.accountingmanager.client.maindata.charts;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.gcube.portlets.admin.accountingmanager.shared.data.AccountingPeriod;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -11,6 +14,10 @@ import com.allen_sauer.gwt.log.client.Log;
|
|||
*
|
||||
*/
|
||||
public class ChartTimeMeasure {
|
||||
public static final long SECOND = 1000;
|
||||
public static final long MINUTE = 60*SECOND;
|
||||
public static final long HOUR = 60*MINUTE;
|
||||
public static final long DAY= 24*HOUR;
|
||||
|
||||
public static double calculateMinRange(AccountingPeriod accountingPeriod) {
|
||||
if (accountingPeriod.getPeriod() == null) {
|
||||
|
@ -21,19 +28,19 @@ public class ChartTimeMeasure {
|
|||
switch (accountingPeriod.getPeriod()) {
|
||||
case DAILY:
|
||||
// 1 day=24hour * 60min *60sec * 1000 millisec
|
||||
return 14 * 24 * 3600 * 1000;
|
||||
return 15 * DAY;
|
||||
case HOURLY:
|
||||
return 24 * 3600 * 1000;
|
||||
return 24 * HOUR;
|
||||
//case MILLISECONDLY:
|
||||
// return 10 * 100;
|
||||
case MINUTELY:
|
||||
return 10 * 60 * 1000;
|
||||
return 10 * MINUTE;
|
||||
case MONTHLY:
|
||||
return 6 * 28 * 24 * 3600 * 1000;
|
||||
return 6 * 28 * DAY;
|
||||
//case SECONDLY:
|
||||
// return 30 * 1000;
|
||||
case YEARLY:
|
||||
return 5 * 12 * 28 * 24 * 3600 * 1000;
|
||||
return 5 * 12 * 28 * DAY;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
|
@ -49,19 +56,19 @@ public class ChartTimeMeasure {
|
|||
|
||||
switch (accountingPeriod.getPeriod()) {
|
||||
case DAILY:
|
||||
return 24 * 3600 * 1000;
|
||||
return DAY;
|
||||
case HOURLY:
|
||||
return 3600 * 1000;
|
||||
return HOUR;
|
||||
//case MILLISECONDLY:
|
||||
// return 100;
|
||||
case MINUTELY:
|
||||
return 60 * 1000;
|
||||
return MINUTE;
|
||||
case MONTHLY:
|
||||
return 28 * 24 * 3600 * 1000;
|
||||
return 28 * DAY;
|
||||
//case SECONDLY:
|
||||
// return 1000;
|
||||
case YEARLY:
|
||||
return 12 * 28 * 24 * 3600 * 1000;
|
||||
return 12 * 28 * DAY;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
|
@ -70,4 +77,24 @@ public class ChartTimeMeasure {
|
|||
}
|
||||
|
||||
|
||||
public static long timeZoneOffset(){
|
||||
Date d = new Date();
|
||||
DateTimeFormat dtf = DateTimeFormat.getFormat("Z");
|
||||
String timeZone = dtf.format(d);
|
||||
|
||||
long timeZoneOffset = 0;
|
||||
try {
|
||||
|
||||
timeZoneOffset = Integer.parseInt(timeZone.substring(0, 3)) * 60
|
||||
+ Integer.parseInt(timeZone.substring(3, 5));
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
Log.error("Error parsing TimeZone: " + e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
return timeZoneOffset;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.gcube.portlets.admin.accountingmanager.client.state.AccountingStateDa
|
|||
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesService;
|
||||
import org.gcube.portlets.admin.accountingmanager.shared.data.response.SeriesServiceData;
|
||||
|
||||
import com.allen_sauer.gwt.log.client.Log;
|
||||
import com.github.highcharts4gwt.client.view.widget.HighchartsLayoutPanel;
|
||||
import com.github.highcharts4gwt.model.array.api.ArrayNumber;
|
||||
import com.github.highcharts4gwt.model.array.api.ArrayString;
|
||||
|
@ -18,6 +19,8 @@ import com.github.highcharts4gwt.model.highcharts.option.api.SeriesArea;
|
|||
import com.github.highcharts4gwt.model.highcharts.option.api.SeriesColumn;
|
||||
import com.google.gwt.event.logical.shared.SelectionEvent;
|
||||
import com.google.gwt.event.logical.shared.SelectionHandler;
|
||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||
import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
|
||||
import com.sencha.gxt.cell.core.client.ButtonCell.ButtonArrowAlign;
|
||||
import com.sencha.gxt.cell.core.client.ButtonCell.IconAlign;
|
||||
import com.sencha.gxt.core.client.util.Margins;
|
||||
|
@ -193,8 +196,14 @@ public class VariableAxisChart extends SimpleContainer {
|
|||
.calculateInterval(accountingStateData.getSeriesRequest()
|
||||
.getAccountingPeriod());
|
||||
|
||||
Date dateStart = accountingStateData.getSeriesRequest()
|
||||
.getAccountingPeriod().getStartDate();
|
||||
Date dateStart = new Date(accountingStateData.getSeriesRequest()
|
||||
.getAccountingPeriod().getStartDate().getTime());
|
||||
dateStart.setTime(dateStart.getTime() + ChartTimeMeasure.timeZoneOffset()*ChartTimeMeasure.MINUTE);
|
||||
|
||||
Log.debug("BuildChart DateStart: "
|
||||
+ DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_FULL)
|
||||
.format(dateStart));
|
||||
|
||||
|
||||
HighchartsOptionFactory highchartsFactory = new JsoHighchartsOptionFactory();
|
||||
options = highchartsFactory.createChartOptions();
|
||||
|
@ -391,8 +400,13 @@ public class VariableAxisChart extends SimpleContainer {
|
|||
.calculateInterval(accountingStateData.getSeriesRequest()
|
||||
.getAccountingPeriod());
|
||||
|
||||
Date dateStart = accountingStateData.getSeriesRequest()
|
||||
.getAccountingPeriod().getStartDate();
|
||||
Date dateStart = new Date(accountingStateData.getSeriesRequest()
|
||||
.getAccountingPeriod().getStartDate().getTime());
|
||||
dateStart.setTime(dateStart.getTime() + ChartTimeMeasure.timeZoneOffset()*ChartTimeMeasure.MINUTE);
|
||||
|
||||
Log.debug("BuildChart DateStart: "
|
||||
+ DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_FULL)
|
||||
.format(dateStart));
|
||||
|
||||
HighchartsOptionFactory highchartsFactory = new JsoHighchartsOptionFactory();
|
||||
options = highchartsFactory.createChartOptions();
|
||||
|
|
|
@ -91,7 +91,7 @@ public class AccountingCaller {
|
|||
throw new AccountingManagerServiceException(
|
||||
"Error creating series response!");
|
||||
}
|
||||
|
||||
logger.debug("SeriesResponse Created: "+seriesResponse);
|
||||
return seriesResponse;
|
||||
} catch (Throwable e) {
|
||||
logger.error("Error in GetSeries(): " + e.getLocalizedMessage());
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.gcube.portlets.admin.accountingmanager.server.amservice.response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.accounting.aggregation.AggregatedServiceUsageRecord;
|
||||
|
@ -39,7 +38,6 @@ public class SeriesResponse4Service extends SeriesResponseBuilder {
|
|||
|
||||
ArrayList<SeriesServiceData> series=new ArrayList<SeriesServiceData>();
|
||||
for (Info info : infos) {
|
||||
Date date = info.getDate();
|
||||
JSONObject jso = info.getValue();
|
||||
Long duration = jso.getLong(AggregatedServiceUsageRecord.DURATION);
|
||||
Long operationCount = jso
|
||||
|
@ -47,7 +45,7 @@ public class SeriesResponse4Service extends SeriesResponseBuilder {
|
|||
Long maxInvocationTime = jso.getLong(AggregatedServiceUsageRecord.MAX_INVOCATION_TIME);
|
||||
Long minInvocationTime = jso.getLong(AggregatedServiceUsageRecord.MIN_INVOCATION_TIME);
|
||||
|
||||
series.add(new SeriesServiceData(date, operationCount, duration, maxInvocationTime, minInvocationTime));
|
||||
series.add(new SeriesServiceData(info.getCalendar().getTime(), operationCount, duration, maxInvocationTime, minInvocationTime));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package org.gcube.portlets.admin.accountingmanager.server.amservice.response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.accounting.aggregation.AggregatedStorageUsageRecord;
|
||||
|
@ -39,12 +38,11 @@ public class SeriesResponse4Storage extends SeriesResponseBuilder {
|
|||
|
||||
ArrayList<SeriesStorageData> series=new ArrayList<SeriesStorageData>();
|
||||
for (Info info : infos) {
|
||||
Date date = info.getDate();
|
||||
JSONObject jso = info.getValue();
|
||||
Long dataVolume = jso.getLong(AggregatedStorageUsageRecord.DATA_VOLUME);
|
||||
Long operationCount = jso
|
||||
.getLong(AggregatedStorageUsageRecord.OPERATION_COUNT);
|
||||
series.add(new SeriesStorageData(date, dataVolume, operationCount));
|
||||
series.add(new SeriesStorageData(info.getCalendar().getTime(), dataVolume, operationCount));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
<set-property name="log_ConsoleLogger" value="ENABLED" />
|
||||
<set-property name="log_DivLogger" value="ENABLED" />
|
||||
<set-property name="log_GWTLogger" value="ENABLED" />
|
||||
<set-property name="log_SystemLogger" value="ENABLED" /> -->
|
||||
<set-property name="log_SystemLogger" value="ENABLED" /> -->
|
||||
<!-- Not in GWT 2.6 <set-property name="log_FirebugLogger" value="ENABLED"
|
||||
/> -->
|
||||
|
||||
|
@ -60,7 +60,7 @@
|
|||
<set-property name="log_ConsoleLogger" value="DISABLED" />
|
||||
<set-property name="log_DivLogger" value="DISABLED" />
|
||||
<set-property name="log_GWTLogger" value="DISABLED" />
|
||||
<set-property name="log_SystemLogger" value="DISABLED" />
|
||||
<set-property name="log_SystemLogger" value="DISABLED" />
|
||||
<!-- Not in GWT 2.6 <set-property name="log_FirebugLogger" value="DISABLED"
|
||||
/> -->
|
||||
|
||||
|
|
Loading…
Reference in New Issue