diff --git a/.classpath b/.classpath
index b4bde20..0aec32c 100644
--- a/.classpath
+++ b/.classpath
@@ -1,12 +1,12 @@
-
+
-
+
@@ -35,5 +35,5 @@
-
+
diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
index d64210d..076f017 100644
--- a/.settings/org.eclipse.wst.common.component
+++ b/.settings/org.eclipse.wst.common.component
@@ -1,5 +1,5 @@
-
+
diff --git a/changelog.md b/changelog.md
new file mode 100644
index 0000000..f6dcaa1
--- /dev/null
+++ b/changelog.md
@@ -0,0 +1,56 @@
+# Changelog
+
+All notable changes to this project will be documented in this file.
+This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+
+
+## [v1.0.0] - 2020-05-28
+
+### Added
+
+**Features**
+
+[#17249] Added PDF support
+
+
+## [v0.4.0] - 2019-11-07
+
+### Added
+
+**Features**
+
+[#17252] Enabled DEA Analysis
+
+
+## [v0.3.0] - 2019-07-07
+
+### Added
+
+**Features**
+
+[#17247] Add numbers to correlation charts
+
+[#17225] Change Speedometer to Performeter
+
+[#17570] Added synoptic tables for Pre-grow and Hatchery
+
+
+
+## [v0.2.0] - 2019-06-07
+
+### Added
+
+**Features**
+
+[#17166] Release Synoptic table functionality
+
+
+
+## [v0.1.0] - 2019-05-07
+
+### Added
+
+**Features**
+
+first release
+
diff --git a/changelog.xml b/changelog.xml
index cc23cee..db5a64f 100644
--- a/changelog.xml
+++ b/changelog.xml
@@ -1,21 +1,25 @@
+
+ [#17249] Added PDF support
+
- [Task #17252] Enabled DEA Analysis
+ [#17252] Enabled DEA Analysis
- [Task #17247] Add numbers to correlation charts
- [Task #17225] Change Speedometer to Performeter
- [Task #17570] Added synoptic tables for Pre-grow and Hatchery
+ [#17247] Add numbers to correlation charts
+ [#17225] Change Speedometer to Performeter
+ [#17570] Added synoptic tables for Pre-grow and Hatchery
- [Task #17165]
- []Task #17166] Release Synoptic table functionality
+ [#17166] Release Synoptic table functionality
org.gcube.portlets.user
performfish-analytics-portlet
war
- 0.7.0-SNAPSHOT
+ 1.0.0-SNAPSHOT
PerformFish Analytics Portlet
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/annualcontrollers/PerformFishAnnualAnalyticsController.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/annualcontrollers/PerformFishAnnualAnalyticsController.java
index c9ce875..09e9657 100644
--- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/annualcontrollers/PerformFishAnnualAnalyticsController.java
+++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/annualcontrollers/PerformFishAnnualAnalyticsController.java
@@ -30,14 +30,14 @@ import org.gcube.portlets.user.performfishanalytics.client.event.SelectedPopulat
import org.gcube.portlets.user.performfishanalytics.client.event.SubmitRequestEvent;
import org.gcube.portlets.user.performfishanalytics.client.event.SubmitRequestEventHandler;
import org.gcube.portlets.user.performfishanalytics.client.resources.PerformFishResources;
-import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon;
-import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.AnalyticsAnnualPanelResult;
+import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.BoxPlotAnnualPanelResult;
+import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.CorrelationAnnualPanelResult;
import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.DeaAnnualPanelResult;
-import org.gcube.portlets.user.performfishanalytics.client.viewbinder.AnalyticsPanelResult;
-import org.gcube.portlets.user.performfishanalytics.client.viewbinder.ShowResult;
+import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.ScatterAnnualPanelResult;
+import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.SpeedometerAnnualPanelResult;
+import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.SynopticTableAnnualPanelResult;
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.SubmitRequestPanel;
import org.gcube.portlets.user.performfishanalytics.shared.KPI;
-import org.gcube.portlets.user.performfishanalytics.shared.OutputFile;
import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile;
import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVRow;
import org.gcube.portlets.user.performfishanalytics.shared.dataminer.DataMinerResponse;
@@ -45,26 +45,12 @@ import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.Pe
import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse;
import com.github.gwtbootstrap.client.ui.Alert;
-import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Tab;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
-import com.github.gwtbootstrap.client.ui.constants.IconType;
-import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.shared.GWT;
-import com.google.gwt.dom.client.Style.Unit;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager;
-import com.google.gwt.resources.client.TextResource;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.ui.ComplexPanel;
-import com.google.gwt.user.client.ui.FlexTable;
-import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.HTMLPanel;
-import com.google.gwt.user.client.ui.HorizontalPanel;
-import com.google.gwt.user.client.ui.Panel;
-import com.google.gwt.user.client.ui.VerticalPanel;
// TODO: Auto-generated Javadoc
/**
@@ -91,11 +77,7 @@ public class PerformFishAnnualAnalyticsController {
// the table AnnualTable_internal.csv returned by PerformFish Service
private String theFocusValue = null;
- private Map boxPlotOrderBy = new HashMap();
-
- private Map synopticOrderBy = new HashMap();
-
-
+ private static int requestId = 0;
/**
* Instantiates a new perform fish analytics controller.
@@ -141,6 +123,8 @@ public class PerformFishAnnualAnalyticsController {
callAlgorithmEvent.getInputKPI(), callAlgorithmEvent.getOutputKPI());
}
});
+
+
eventBus.addHandler(SelectedPopulationTypeEvent.TYPE, new SelectedPopulationTypeEventHandler() {
@@ -169,7 +153,6 @@ public class PerformFishAnnualAnalyticsController {
@Override
public void onFieldFormChanged(PerformFishFieldFormChangedEvent performFishFieldFormChangedEvent) {
- // viewAnnualController.setReloadPerformFishServiceData(true);
boolean isValidForm = viewAnnualController.validatePerformFishInputFields();
if (isValidForm) {
@@ -190,116 +173,9 @@ public class PerformFishAnnualAnalyticsController {
@Override
public void onLoadFocusEvent(LoadFocusEvent loadFocusEvent) {
-
- final Map> mapParameters = new HashMap>();
- String farmId = decryptParameters.getParameters()
- .get(PerformFishAnalyticsConstant.PERFORM_FISH_FARMID_PARAM);
- String batchType = decryptParameters.getParameters()
- .get(PerformFishAnalyticsConstant.PERFORM_FISH_BATCH_TYPE_PARAM);
-
- // String batchType =
- // viewAnnualController.getForm().getBatchType();
-
- // List listYear =
- // viewAnnualController.getForm().getYear();
-
- mapParameters.put(PerformFishAnalyticsConstant.PERFORM_FISH_FARMID_PARAM, Arrays.asList(farmId));
- mapParameters.put(PerformFishAnalyticsConstant.PERFORM_FISH_BATCH_TYPE_PARAM, Arrays.asList(batchType));
-
- PerformFishAnalyticsServiceAsync.Util.getInstance().submitRequestToPerformFishService(mapParameters,
- new AsyncCallback() {
-
- @Override
- public void onFailure(Throwable caught) {
- // modal.hide();
- Window.alert(caught.getMessage());
- }
-
- @Override
- public void onSuccess(PerformFishResponse performFishResponse) {
- thePerformFishResponse = performFishResponse;
- GWT.log("PerformFish Response: " + performFishResponse);
-
- final String pfTableName = PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AnnualTable_internal
- .getPerformFishTable();
-
- String fileURL = performFishResponse.getMapParameters().get(pfTableName);
-
- GWT.log(pfTableName + " is: " + fileURL);
-
- // Managing the Perform Fish Service Response
- if (fileURL == null) {
- viewAnnualController.showAlert(
- "No table found by searching for name: "
- + PerformFishAnalyticsConstant.BATCHES_TABLE_INTERNAL,
- AlertType.ERROR);
- } else {
-
- PerformFishAnalyticsServiceAsync.Util.getInstance().readCSVFile(fileURL,
- new AsyncCallback() {
-
- @Override
- public void onFailure(Throwable caught) {
- Window.alert(caught.getMessage());
-
- }
-
- @Override
- public void onSuccess(CSVFile result) {
-
- if (result == null) {
- viewAnnualController.showAlert(
- "The focus was not found in the table " + pfTableName,
- AlertType.ERROR);
- return;
- }
-
- int indexOfFARM = result.getHeaderRow().getListValues().indexOf(
- PerformFishAnalyticsConstant.POPULATION_LEVEL.FARM.name());
-
- GWT.log("The index of column "
- + PerformFishAnalyticsConstant.POPULATION_LEVEL.FARM.name()
- + " is " + indexOfFARM);
-
- if (indexOfFARM > -1) {
- List rows = result.getValueRows();
-
- if (rows == null || rows.isEmpty()) {
- viewAnnualController
- .showAlert("No valid focus was found in the table "
- + pfTableName, AlertType.ERROR);
- return;
- }
-
- String focusValue = null;
- // IN THE COLUMN WITH
- // HEADER 'FARM' THE
- // FOCUS VALUE IS THE
- // SAME FOR ALL ROWS
- for (CSVRow row : rows) {
- focusValue = row.getListValues().get(indexOfFARM);
- if (focusValue != null && !focusValue.isEmpty())
- break;
- }
-
- if (focusValue == null) {
- viewAnnualController
- .showAlert("No valid focus was found in the table "
- + pfTableName, AlertType.ERROR);
- return;
- }
-
- theFocusValue = focusValue;
- GWT.log("Loaded the focus value: " + theFocusValue);
- }
- }
- });
-
- }
- }
- });
-
+ manageLoadFocus();
}
+
});
//
@@ -338,83 +214,122 @@ public class PerformFishAnnualAnalyticsController {
}
+ private void manageLoadFocus() {
+ final Map> mapParameters = new HashMap>();
+ String farmId = decryptParameters.getParameters().get(PerformFishAnalyticsConstant.PERFORM_FISH_FARMID_PARAM);
+ String batchType = decryptParameters.getParameters()
+ .get(PerformFishAnalyticsConstant.PERFORM_FISH_BATCH_TYPE_PARAM);
+
+ // String batchType =
+ // viewAnnualController.getForm().getBatchType();
+
+ // List listYear =
+ // viewAnnualController.getForm().getYear();
+
+ mapParameters.put(PerformFishAnalyticsConstant.PERFORM_FISH_FARMID_PARAM, Arrays.asList(farmId));
+ mapParameters.put(PerformFishAnalyticsConstant.PERFORM_FISH_BATCH_TYPE_PARAM, Arrays.asList(batchType));
+
+ PerformFishAnalyticsServiceAsync.Util.getInstance().submitRequestToPerformFishService(mapParameters,
+ new AsyncCallback() {
+
+ @Override
+ public void onFailure(Throwable caught) {
+ // modal.hide();
+ Window.alert(caught.getMessage());
+ }
+
+ @Override
+ public void onSuccess(PerformFishResponse performFishResponse) {
+ thePerformFishResponse = performFishResponse;
+ GWT.log("PerformFish Response: " + performFishResponse);
+
+ final String pfTableName = PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AnnualTable_internal
+ .getPerformFishTable();
+
+ String fileURL = performFishResponse.getMapParameters().get(pfTableName);
+
+ GWT.log(pfTableName + " is: " + fileURL);
+
+ // Managing the Perform Fish Service Response
+ if (fileURL == null) {
+ viewAnnualController.showAlert("No table found by searching for name: "
+ + PerformFishAnalyticsConstant.BATCHES_TABLE_INTERNAL, AlertType.ERROR);
+ } else {
+
+ PerformFishAnalyticsServiceAsync.Util.getInstance().readCSVFile(fileURL,
+ new AsyncCallback() {
+
+ @Override
+ public void onFailure(Throwable caught) {
+ Window.alert(caught.getMessage());
+
+ }
+
+ @Override
+ public void onSuccess(CSVFile result) {
+
+ if (result == null) {
+ viewAnnualController.showAlert(
+ "The focus was not found in the table " + pfTableName,
+ AlertType.ERROR);
+ return;
+ }
+
+ int indexOfFARM = result.getHeaderRow().getListValues()
+ .indexOf(PerformFishAnalyticsConstant.POPULATION_LEVEL.FARM.name());
+
+ GWT.log("The index of column "
+ + PerformFishAnalyticsConstant.POPULATION_LEVEL.FARM.name() + " is "
+ + indexOfFARM);
+
+ if (indexOfFARM > -1) {
+ List rows = result.getValueRows();
+
+ if (rows == null || rows.isEmpty()) {
+ viewAnnualController.showAlert(
+ "No valid focus was found in the table " + pfTableName,
+ AlertType.ERROR);
+ return;
+ }
+
+ String focusValue = null;
+ // IN THE COLUMN WITH
+ // HEADER 'FARM' THE
+ // FOCUS VALUE IS THE
+ // SAME FOR ALL ROWS
+ for (CSVRow row : rows) {
+ focusValue = row.getListValues().get(indexOfFARM);
+ if (focusValue != null && !focusValue.isEmpty())
+ break;
+ }
+
+ if (focusValue == null) {
+ viewAnnualController.showAlert(
+ "No valid focus was found in the table " + pfTableName,
+ AlertType.ERROR);
+ return;
+ }
+
+ theFocusValue = focusValue;
+ GWT.log("Loaded the focus value: " + theFocusValue);
+ }
+ }
+ });
+
+ }
+ }
+ });
+ }
+
/**
* Call algorithm synoptic table farm.
*/
protected void callAlgorithmSynopticTableFarm() {
- final DataMinerAlgorithms algorithm = DataMinerAlgorithms.PERFORMFISH_SYNOPTIC_TABLE_FARM;
- final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
- final String tabTitle = "Synoptic Table";
- final String tabDescr = PerformFishResources.INSTANCE.synopticTable().getText();
-
- final Tab tab = viewAnnualController.createTab(
- tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1),
- tabDescr, submitRequestPanel);
-
- StringBuilder dataInputsFormatter = new StringBuilder();
- Map performFishResponseMap = thePerformFishResponse.getMapParameters();
- dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
- PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.LethalIncidentsTable);
- dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
- PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AnnualTable);
- dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
- PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntibioticsTable);
- dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
- PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntiparasiticTable);
-
- String yearsValue = "";
- for (String year : viewAnnualController.getSelectedYears()) {
- yearsValue += year + "#";
- }
- yearsValue = yearsValue.substring(0, yearsValue.length() - 1);
-
- dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_ALLYEARS_PARAM + "=" + yearsValue + ";");
-
- // dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_ALLYEARS_PARAM+"="+
- // PerformFishAnalyticsConstant.DM_VALUE_ALL +";");
- // dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_ALLYEARS_PARAM+"=2016;");
-
- String dataInParameters = dataInputsFormatter.toString();
- GWT.log("Calling DM service with client input parameters: " + dataInParameters);
-
- Map> mapParameters = new HashMap>();
- mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters));
-
- final HTMLPanel panelContainer = submitRequestPanel.getContainerPanel();
- final LoaderIcon loaderIcon = new LoaderIcon("Submitting request to " + algorithm.getTitle() + "...");
- loaderIcon.setVisible(true);
- panelContainer.setVisible(true);
- panelContainer.add(loaderIcon);
- Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
- @Override
- public void execute() {
- loaderIcon.setFocus(true);
- }
- });
-
- PerformFishAnalyticsServiceAsync.Util.getInstance().callDMServiceToLoadSynopticAnnualTable(
- thePerformFishResponse, mapParameters, new AsyncCallback() {
-
- @Override
- public void onSuccess(DataMinerResponse dmResponse) {
- loaderIcon.setVisible(false);
- checkTabSpinner(submitRequestPanel, tab);
- // field_unary_algorithm.setVisible(true);
- GWT.log("I'm displaying: " + dmResponse);
- displayOutputFilesAsStaticEntities(dmResponse, algorithm, null, null, null, panelContainer,
- false,tabTitle, tabDescr);
- }
-
- @Override
- public void onFailure(Throwable caught) {
- loaderIcon.setVisible(false);
- checkTabSpinner(submitRequestPanel, tab);
- displayOutputFilesAsStaticEntities(null, algorithm, null, null, null, panelContainer, true,tabTitle, tabDescr);
-
- }
- });
-
+ requestId++;
+ @SuppressWarnings("unused")
+ SynopticTableAnnualPanelResult synopticTablePanelResult = new SynopticTableAnnualPanelResult(requestId,
+ viewAnnualController, thePerformFishResponse);
}
/**
@@ -653,12 +568,13 @@ public class PerformFishAnnualAnalyticsController {
final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
submitRequestPanel.showLoader(true,
"Submitting " + DataMinerAlgorithms.CORRELATION.getTitle() + " request to DM Service...");
- String tabTitle = DataMinerAlgorithms.CORRELATION.getTitle();
+ final String tabTitle = DataMinerAlgorithms.CORRELATION.getTitle();
+ final String tabDescription = PerformFishResources.INSTANCE.farm_CORRELATION().getText();
final Tab tab = viewAnnualController.createTab(
- tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1),
- PerformFishResources.INSTANCE.farm_CORRELATION().getText(), submitRequestPanel);
+ tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1), tabDescription, submitRequestPanel);
+ requestId++;
PerformFishAnalyticsServiceAsync.Util.getInstance().callingDataMinerPerformFishAnnualCorrelationAnalysis(
dmInputParameters.getPerformFishResponse(), mapParameters, new AsyncCallback() {
@@ -666,21 +582,15 @@ public class PerformFishAnnualAnalyticsController {
public void onSuccess(DataMinerResponse dmResponse) {
submitRequestPanel.showLoader(false, null);
checkTabSpinner(submitRequestPanel, tab);
- AnalyticsAnnualPanelResult analyticsPanelResult = new AnalyticsAnnualPanelResult(eventBus);
- // analyticsPanelResult.addSelectedAreas(performFishRequestParameters.get(PerformFishAnalyticsConstant.PERFORM_FISH_AREA_PARAM));
+ CorrelationAnnualPanelResult analyticsPanelResult = new CorrelationAnnualPanelResult(requestId,
+ tabTitle, tabDescription);
analyticsPanelResult.addSelectedKPIs(inputKPI);
-
- // TODO COMMENTED NOW
analyticsPanelResult.addListBatchIds(Arrays.asList(theFocusValue));
-
analyticsPanelResult.addParameters(PerformFishAnalyticsConstant.DATA_INPUTS, mapParameters,
viewAnnualController.getForm().getBatchType());
analyticsPanelResult.addResults(dmResponse);
submitRequestPanel.addWidget(analyticsPanelResult);
- // viewController.geTabPanelView().addResult(resultPanel,
- // "Analysis
- // #"+(viewController.geTabPanelView().countTab()+1));
- // modal.hide();
+
}
@Override
@@ -689,18 +599,15 @@ public class PerformFishAnnualAnalyticsController {
submitRequestPanel.showLoader(false, null);
checkTabSpinner(submitRequestPanel, tab);
try {
- AnalyticsPanelResult analyticsPanelResult = new AnalyticsPanelResult();
- // analyticsPanelResult.addSelectedAreas(performFishRequestParameters.get(PerformFishAnalyticsConstant.PERFORM_FISH_AREA_PARAM));
- analyticsPanelResult.addSelectedKPIs(viewAnnualController.getSelectedKPIs());
-
- // TODO COMMENTED NOW
- analyticsPanelResult.addListFocusIds(Arrays.asList(theFocusValue));
-
+ CorrelationAnnualPanelResult analyticsPanelResult = new CorrelationAnnualPanelResult(
+ requestId, tabTitle, tabDescription);
+ analyticsPanelResult.addSelectedKPIs(inputKPI);
+ analyticsPanelResult.addListBatchIds(Arrays.asList(theFocusValue));
analyticsPanelResult.addParameters(PerformFishAnalyticsConstant.DATA_INPUTS, mapParameters,
viewAnnualController.getForm().getBatchType());
submitRequestPanel.addWidget(analyticsPanelResult);
} catch (Exception e) {
- // TODO: handle exception
+ GWT.log(e.getLocalizedMessage(), e);
}
Alert error = new Alert(caught.getMessage());
@@ -726,218 +633,32 @@ public class PerformFishAnnualAnalyticsController {
private void callAlgorithm(DataMinerAlgorithms algorithm, String focusID, List inputKPI,
final List outputKPI) {
- // List listBatchID = viewController.getSelectedBatchID();
- //
- // if(listBatchID==null || listBatchID.size()==0)
- // Window.alert("Something seems wrong, no selected BatchID, try
- // again");
-
- SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
- // submitRequestPanel.getElement().addClassName("ext-horizontal-panel");
-
- // TO MANAGE ALGORITHMS DESCRIPTION
- TextResource algDescr = null;
+ requestId++;
switch (algorithm) {
case BOXPLOT:
- algDescr = PerformFishResources.INSTANCE.farm_BOXPLOT();
- break;
- case CORRELATION:
- algDescr = PerformFishResources.INSTANCE.farm_CORRELATION();
- break;
- case DEA_ANALYSIS:
- break;
- case DEA_CHART:
- break;
- case PERFORMFISH_SYNOPTIC_TABLE_FARM:
- break;
- case PERFORMFISH_SYNOPTICTABLE_BATCH:
- break;
- case SCATTER:
- algDescr = PerformFishResources.INSTANCE.farm_SCATTER();
+ @SuppressWarnings("unused")
+ BoxPlotAnnualPanelResult boxPlotAnnualPanelResult = new BoxPlotAnnualPanelResult(requestId,
+ viewAnnualController, thePerformFishResponse, algorithm, focusID, inputKPI, outputKPI);
break;
case SPEEDOMETER:
- algDescr = PerformFishResources.INSTANCE.farm_SPEEDOMETER();
+ @SuppressWarnings("unused")
+ SpeedometerAnnualPanelResult speedometerAnnualPanelResult = new SpeedometerAnnualPanelResult(requestId,
+ viewAnnualController, thePerformFishResponse, algorithm, focusID, inputKPI, outputKPI);
+
break;
- case PERFORMFISH_SYNOPTICTABLE_BATCH_HATCHERY:
- break;
- case PERFORMFISH_SYNOPTICTABLE_BATCH_PREGROW:
+ case SCATTER:
+ @SuppressWarnings("unused")
+ ScatterAnnualPanelResult scatterAnnualPanelResult = new ScatterAnnualPanelResult(requestId,
+ viewAnnualController, thePerformFishResponse, algorithm, focusID, inputKPI, outputKPI);
break;
default:
break;
- }
-
-
- String algDesrTxt = algDescr != null ? algDescr.getText() : null;
-
- String tabTitle = algorithm.getTitle();
- String tabDescr = algDesrTxt;
-
-
- Tab tab = viewAnnualController.createTab(tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1),
- algDesrTxt, submitRequestPanel);
-
- switch (algorithm) {
- case BOXPLOT:
- case SPEEDOMETER:
-
- submitRequestPanel.setTotalRequests(inputKPI.size());
- for (KPI kpi : inputKPI) {
- String title = "KPI: " + kpi.getName();
- HTML toBigTitle = new HTML(title);
- toBigTitle.getElement().addClassName("to-big-title");
- submitRequestPanel.addWidget(toBigTitle);
- HorizontalPanel hp = new HorizontalPanel();
- hp.getElement().addClassName("ext-horizontal-panel");
-
- DataMinerInputParameters dmInputParams = new DataMinerInputParameters(thePerformFishResponse,
- viewAnnualController.getSelectedYears(), Arrays.asList(kpi), null, algorithm, focusID);
- callDataMinerServiceForChart(dmInputParams, submitRequestPanel, hp, tab, tabTitle, tabDescr);
- // resultPanel.add(hp);
- submitRequestPanel.addWidget(hp);
- }
- break;
- case SCATTER:
-
- if (inputKPI.get(0) == null || inputKPI.get(1) == null) {
- submitRequestPanel
- .setTheTitle("Sorry, something seems wrong, the selected KPIs are not valid. Please try again");
- checkTabSpinner(submitRequestPanel, tab);
- return;
- // Window.alert("Something seems wrong, no selected BatchID, try
- // again");
- }
-
- String titleScatter = "KPI: " + inputKPI.get(0).getName() + " vs " + inputKPI.get(1).getName();
- submitRequestPanel.setTheTitle(titleScatter);
-
- default: {
- DataMinerInputParameters dmInputParams = new DataMinerInputParameters(thePerformFishResponse,
- viewAnnualController.getSelectedYears(), inputKPI, outputKPI, algorithm, focusID);
- callDataMinerServiceForChart(dmInputParams, submitRequestPanel, submitRequestPanel.getContainerPanel(),
- tab,tabTitle, tabDescr);
- // callDataMinerServiceForChart(thePerformFishResponse,
- // POPULATION_LEVEL.BATCH, inputKPI, outputKPI, algorithm, focusID,
- // submitRequestPanel, submitRequestPanel.getContainerPanel(), tab);
- }
}
}
-
- /**
- * Call data miner service for chart.
- *
- * @param dmInputParameters
- * the dm input parameters
- * @param requestPanel
- * the request panel
- * @param panelContainer
- * the panel
- * @param tab
- * the tab
- * @param tabDescr
- * @param tabTitle
- */
- private void callDataMinerServiceForChart(final DataMinerInputParameters dmInputParameters,
- final SubmitRequestPanel requestPanel, final ComplexPanel panelContainer, final Tab tab, final String tabTitle, final String tabDescr) {
-
- GWT.log("Building DM request with input parameters: " + dmInputParameters);
-
- StringBuilder dataInputsFormatter = new StringBuilder();
- dataInputsFormatter
- .append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM + "=" + dmInputParameters.getChartType() + ";");
-
- String yearsValue = "";
- for (String year : dmInputParameters.getSelectedYears()) {
- yearsValue += year + "|";
- }
- yearsValue = yearsValue.substring(0, yearsValue.length() - 1);
-
- dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_YEARS_PARAM + "=" + yearsValue + ";");
- dataInputsFormatter
- .append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM + "=" + dmInputParameters.getFocusID() + ";");
- // dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM+"=ID;");
-
- if (dmInputParameters.getInputKPI() != null && dmInputParameters.getInputKPI().size() > 0) {
- String kpiCodes = "";
- for (KPI kpi : dmInputParameters.getInputKPI()) {
- kpiCodes += kpi.getCode() + "|";
- }
- // remove last |
- kpiCodes = kpiCodes.substring(0, kpiCodes.length() - 1);
-
- GWT.log("Input KPICodes: " + kpiCodes);
- // ADDING KPIs code
- dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_INPUT_KPI_PARAM + "=" + kpiCodes + ";");
-
- }
-
- if (dmInputParameters.getOutputKPI() != null && dmInputParameters.getOutputKPI().size() > 0) {
- String kpiCodes = "";
- for (KPI kpi : dmInputParameters.getOutputKPI()) {
- kpiCodes += kpi.getCode() + "|";
- }
- // remove last |
- kpiCodes = kpiCodes.substring(0, kpiCodes.length() - 1);
-
- GWT.log("Output KPICodes: " + kpiCodes);
- // ADDING KPIs code
- dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_OUTPUT_KPI_PARAM + "=" + kpiCodes + ";");
- }
-
- Map performFishResponseMap = dmInputParameters.getPerformFishResponse().getMapParameters();
-
- dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
- PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.LethalIncidentsTable);
- dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
- PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AnnualTable);
- dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
- PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntibioticsTable);
- dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
- PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntiparasiticTable);
-
- String dataInParameters = dataInputsFormatter.toString();
- GWT.log("Calling DM service with client input parameters: " + dataInParameters);
-
- Map> mapParameters = new HashMap>();
- mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters));
-
- final LoaderIcon loaderIcon = new LoaderIcon(
- "Submitting request to " + dmInputParameters.getChartType().getTitle() + " Analysis...");
- loaderIcon.setVisible(true);
- panelContainer.setVisible(true);
- panelContainer.add(loaderIcon);
- Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
- @Override
- public void execute() {
- loaderIcon.setFocus(true);
- }
- });
-
- PerformFishAnalyticsServiceAsync.Util.getInstance().callingDataMinerPerformFishAnnualAnalysis(mapParameters,
- new AsyncCallback() {
-
- @Override
- public void onSuccess(DataMinerResponse dmResponse) {
- loaderIcon.setVisible(false);
- checkTabSpinner(requestPanel, tab);
- // field_unary_algorithm.setVisible(true);
- GWT.log("I'm displaying: " + dmResponse);
- displayOutputFilesAsStaticEntities(dmResponse, dmInputParameters.getChartType(),
- dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
- dmInputParameters.getFocusID(), panelContainer, false,tabTitle, tabDescr);
- }
-
- @Override
- public void onFailure(Throwable caught) {
- loaderIcon.setVisible(false);
- checkTabSpinner(requestPanel, tab);
- displayOutputFilesAsStaticEntities(null, dmInputParameters.getChartType(),
- dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
- dmInputParameters.getFocusID(), panelContainer, true,tabTitle, tabDescr);
-
- }
- });
- }
+
+
+
/**
* Append DM input table.
@@ -980,392 +701,4 @@ public class PerformFishAnnualAnalyticsController {
}
}
- /**
- * Display output files as static entities.
- *
- * @param dmResponse
- * the dm response
- * @param chartType
- * the chart type
- * @param inputKPIs
- * the input kp is
- * @param outputKPIs
- * the output kp is
- * @param focusID
- * the focus id
- * @param container
- * the container
- * @param displayError
- * the display error
- * @param tabDescr
- * @param tabTitle
- */
- private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
- final DataMinerAlgorithms chartType, List inputKPIs, List outputKPIs, final String focusID,
- final Panel container, boolean displayError, final String tabTitle, final String tabDescr) {
-
- String title = displayError ? "No results " : "";
-
- if (displayError) {
- Alert alert = new Alert(title);
- alert.setType(AlertType.ERROR);
- alert.setClose(false);
- alert.getElement().getStyle().setMargin(10, Unit.PX);
- container.add(alert);
- return;
- }
-
-
- VerticalPanel vp = new VerticalPanel();
- final HorizontalPanel res = new HorizontalPanel();
-
-
- Button savePDFButton = new Button();
- savePDFButton.getElement().getStyle().setMargin(10, Unit.PX);
- savePDFButton.setIcon(IconType.PRINT);
- savePDFButton.addClickHandler(new ClickHandler() {
-
- @Override
- public void onClick(ClickEvent event) {
- saveFilePDF(res,tabTitle,tabTitle,tabDescr,dmResponse.getListOutput().size());
- }
- });
-
- vp.add(savePDFButton);
- vp.add(res);
- container.add(vp);
-
- final String toTitle = title;
- int outputNumber = 0;
-
- for (final OutputFile outputFile : dmResponse.getListOutput()) {
- outputNumber++;
- final String outputId = "OutputId_" + outputNumber;
-
- switch (outputFile.getDataType()) {
- case IMAGE:
- PerformFishAnalyticsServiceAsync.Util.getInstance().getImageFile(outputFile,
- new AsyncCallback() {
-
- @Override
- public void onFailure(Throwable caught) {
- // showAlert(caught.getMessage(),
- // AlertType.ERROR, true,
- // uib_vp_deanalanlysis_request_container);
- Window.alert(caught.getMessage());
-
- }
-
- @Override
- public void onSuccess(String base64Content) {
-
- String title = toTitle;
- switch (chartType) {
- case BOXPLOT:
- // title = chartType.getName()+" - on all
- // batches
";
- // title += "Blue dots indicate the selected
- // batch(es): "+focusID;
- title = chartType.getTitle() + " - on all farm data
";
- title += "Blue dots indicate the selected farm: " + focusID;
-
- ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
- showResult.showImage(base64Content);
- displayingOrderedBoxPlot(dmResponse, title, container, showResult);
- return;
- case CORRELATION:
- break;
- case DEA_ANALYSIS:
- break;
- case SCATTER:
- break;
- case SPEEDOMETER:
- title = chartType.getTitle() + "
";
- title += "Selected Farm: " + focusID + "
";
- title += "Normalized with respect to all farm data in the VRE";
- break;
- case DEA_CHART:
- break;
- case PERFORMFISH_SYNOPTICTABLE_BATCH:
- break;
- case PERFORMFISH_SYNOPTICTABLE_BATCH_HATCHERY:
- break;
- case PERFORMFISH_SYNOPTICTABLE_BATCH_PREGROW:
- break;
- case PERFORMFISH_SYNOPTIC_TABLE_FARM:
- break;
- default:
- break;
- }
-
- ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
- showResult.showImage(base64Content);
- container.add(showResult);
-
- }
- });
- break;
- case CSV:
-
- PerformFishAnalyticsServiceAsync.Util.getInstance().getCSVFile(outputFile, true,
- new AsyncCallback() {
-
- @Override
- public void onFailure(Throwable caught) {
- // showAlert(caught.getMessage(),
- // AlertType.ERROR, true,
- // uib_vp_deanalanlysis_request_container);
- Window.alert(caught.getMessage());
- }
-
- @Override
- public void onSuccess(CSVFile result) {
- GWT.log("Displaying: " + result);
- String cssTableStyle = "simpletable";
- String title = toTitle;
- switch (chartType) {
- case BOXPLOT:
- if (result.getFileName().contains("_user")) {
- title = "My Batch(es)";
- return;
- } else {
- title = "All farm data in the VRE (including mine)";
- }
- title += "
";
- title += "Data aggregation is performed by considering farms as base units";
-
- ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
- showResult.showCSVFile(result, cssTableStyle);
- displayingOrderedBoxPlot(dmResponse, title, container, showResult);
- return;
- case CORRELATION:
- break;
- case DEA_ANALYSIS:
- break;
- case SCATTER:
- break;
- case SPEEDOMETER:
- break;
- case DEA_CHART:
- break;
- case PERFORMFISH_SYNOPTIC_TABLE_FARM:
- if (!result.getFileName().contains("legend")) {
- cssTableStyle = "synoptictable-farm";
- } else {
- cssTableStyle = "simpletable-synoptic";
- }
- ShowResult showResultSin = new ShowResult(outputId, title,
- outputFile.getDataType());
- showResultSin.showCSVFile(result, cssTableStyle);
- displayingOrderedSynopticTable(dmResponse, result.getFileName(), container,
- showResultSin);
-
- return;
- case PERFORMFISH_SYNOPTICTABLE_BATCH:
- break;
- case PERFORMFISH_SYNOPTICTABLE_BATCH_HATCHERY:
- break;
- case PERFORMFISH_SYNOPTICTABLE_BATCH_PREGROW:
- break;
- default:
- break;
- }
-
- ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
- showResult.showCSVFile(result, cssTableStyle);
- container.add(showResult);
- }
- });
- break;
-
- default:
- break;
- }
-
- }
-
- }
-
- /**
- * Displaying ordered synoptic table.
- *
- * @param dmResponse
- * the dm response
- * @param fileName
- * the file name
- * @param container
- * the container
- * @param showResult
- * the show result
- */
- private void displayingOrderedSynopticTable(final DataMinerResponse dmResponse, String fileName,
- final Panel container, ShowResult showResult) {
- int hashcode = dmResponse.hashCode();
- GWT.log("The hascode is: " + hashcode);
- FlexTable flex = synopticOrderBy.get(hashcode);
-
- if (flex == null) {
- GWT.log("The flextable is null");
- flex = new FlexTable();
- synopticOrderBy.put(hashcode, flex);
- container.add(flex);
- }
-
- if (fileName.toLowerCase().contains("legend")) {
- flex.setWidget(0, 0, showResult);
- } else {
- flex.setWidget(flex.getRowCount() + 1, 0, showResult);
- }
- }
-
- /**
- * Displaying ordered box plot.
- *
- * @param dmResponse
- * the dm response
- * @param title
- * the title
- * @param container
- * the container
- * @param showResult
- * the show result
- */
- private void displayingOrderedBoxPlot(final DataMinerResponse dmResponse, String title, final Panel container,
- ShowResult showResult) {
- int hashcode = dmResponse.hashCode();
- GWT.log("The hascode is: " + hashcode);
- FlexTable flex = boxPlotOrderBy.get(hashcode);
-
- if (flex == null) {
- GWT.log("The flextable is null");
- flex = new FlexTable();
- boxPlotOrderBy.put(hashcode, flex);
- container.add(flex);
- }
-
- if (title.startsWith("My")) {
- flex.setWidget(0, 0, showResult);
- } else if (title.startsWith("All")) {
- flex.setWidget(0, 1, showResult);
- } else {
- flex.setWidget(0, 2, showResult);
- }
- }
-
- private static native void saveFilePDF(HorizontalPanel chart, String filename, String tabTitle, String tabDescr, int outputNumber)/*-{
- var that = this;
- console.log('saveFilePDF()');
-
- var tTitle=tabTitle;
- var tDescr=tabDescr;
- var result = chart;
- console.log(chart);
-
- var pdoc = new jsPDF("p", "mm", "a4");
- pdoc.setProperties({
- title : 'PerformFish '+tTitle,
- subject : ' Results',
- author : 'PerformFish',
- keywords : 'PerformFish',
- creator : 'D4Science'
- });
-
- var lMargin = 15; //left margin in mm
- var rMargin = 15; //right margin in mm
- var tMargin = 15; //top margin in mm
- var bMargin = 15; //bottom margin in mm
- var pdfWidthInMM = 210; // width of A4 in mm
- var pdfHeightInMM = 297; // height of A4 in mm
- var pageCenter = pdfWidthInMM / 2;
-
- pdoc.setFontSize(24);
- var title = "PerformFish "+tTitle;
- var titleHeight = pdoc.getLineHeight(title) / pdoc.internal.scaleFactor
- var xPos = lMargin;
- var yPos = tMargin;
- pdoc.text(title, pageCenter, yPos, 'center');
- yPos += titleHeight;
-
- pdoc.setFontSize(10);
- var lineHeight = pdoc.getLineHeight(tDescr)
- / pdoc.internal.scaleFactor
- var splittedAnalysisDescription = pdoc.splitTextToSize(
- tDescr, (pdfWidthInMM - lMargin - rMargin));
- var lines = splittedAnalysisDescription.length // splitted text is a string array
- var analysisDescriptionHeight = lines * lineHeight
-
- pdoc.text(splittedAnalysisDescription, xPos, yPos, 'left');
- yPos += analysisDescriptionHeight;
-
- //yPos += 2;
- //pdoc.text("Analysis:", xPos, yPos, 'left');
- yPos += 6;
-
-
- for (var i = 1; i <= outputNumber; i++) {
-
- var outputId = 'OutputId_'+ i;
- console.log('OutputId: ' + outputId);
-
- var resultOutputNumber = $doc.getElementById(outputId);
-
- console.log('OutputId_: ' + resultOutputNumber.innerHTML);
- var resultType = resultOutputNumber.className;
-
- console.log('resultOutputNumber className: ' + resultType);
-
- if (typeof resultType !== 'undefined' && resultType !== null
- && resultType !== '') {
-
- if (resultType == 'csv') {
- console.log('Result Type csv: ' + i);
- // foo could get resolved and it's defined
-
- var childrenTable = resultOutputNumber.children;
- var secondDiv = childrenTable[0].rows[1].cells[0];
- var secondTable = secondDiv.children[0].children[0];
-
- console.log('CSV SecondTable: ' + secondTable);
-
- pdoc.autoTable({
- theme : 'grid',
- startY : yPos,
- pageBreak : 'auto',
- bodyStyles : {
- fontSize : 9
- },
- html : secondTable
- });
-
- yPos = pdoc.previousAutoTable.finalY + 6;
- } else {
- if (resultType == 'image') {
- console.log('Result Type image: ' + i);
- var childrenTable = resultOutputNumber.children;
- var secondDiv = childrenTable[0].rows[1].cells[0];
- var imageElement = secondDiv.getElementsByTagName(
- 'img').item(0);
- console.log('Image element: ' + imageElement);
- pdoc.addImage(imageElement, lMargin, yPos);
- console.log('Image Height: ' + imageElement.height);
- yPos += (imageElement.height * 0.26458333);
-
- } else {
- console.log('Result Type unknow: ' + i);
- }
-
- }
- } else {
- console.log('Result Type is undefined:' + i);
- }
-
- }
-
-
- console.log('Done');
-
- pdoc.save(filename);
-
- }-*/;
-
}
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/controllers/PerformFishAnalyticsController.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/controllers/PerformFishAnalyticsController.java
index 84930e8..a9f927e 100644
--- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/controllers/PerformFishAnalyticsController.java
+++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/controllers/PerformFishAnalyticsController.java
@@ -33,7 +33,7 @@ import org.gcube.portlets.user.performfishanalytics.client.event.SubmitRequestEv
import org.gcube.portlets.user.performfishanalytics.client.event.SubmitRequestEventHandler;
import org.gcube.portlets.user.performfishanalytics.client.resources.PerformFishResources;
import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon;
-import org.gcube.portlets.user.performfishanalytics.client.viewbinder.AnalyticsPanelResult;
+import org.gcube.portlets.user.performfishanalytics.client.viewbinder.CorrelationPanelResult;
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.BoxPlotPanelResult;
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.DeaPanelResult;
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.ScatterPanelResult;
@@ -366,8 +366,9 @@ public class PerformFishAnalyticsController {
final Map> performFishRequestParameters) {
GWT.log("Read perform fish response: " + performFishResponse);
+ requestId++;
@SuppressWarnings("unused")
- SynopticTablePanelResult synopticTablePanelResult = new SynopticTablePanelResult(requestId++, viewController,
+ SynopticTablePanelResult synopticTablePanelResult = new SynopticTablePanelResult(requestId, viewController,
performFishResponse, performFishRequestParameters);
}
@@ -490,12 +491,15 @@ public class PerformFishAnalyticsController {
submitRequestPanel.showLoader(true,
"Submitting " + DataMinerAlgorithms.CORRELATION.getTitle() + " request to DM Service...");
- String tabTitle = DataMinerAlgorithms.CORRELATION.getTitle();
+ final String tabTitle = DataMinerAlgorithms.CORRELATION.getTitle();
+ final String tabDescr = PerformFishResources.INSTANCE.batch_CORRELATION().getText();
final Tab tab = viewController.createTab(tabTitle + " #" + (viewController.currentNumberOfTab() + 1),
- PerformFishResources.INSTANCE.batch_CORRELATION().getText(), submitRequestPanel);
+ tabDescr, submitRequestPanel);
final List selectedKPI = new ArrayList(viewController.getSelectedKPIs());
final List batchIDs = new ArrayList(viewController.getListBatchesID());
+
+ requestId++;
PerformFishAnalyticsServiceAsync.Util.getInstance().callingDataMinerPerformFishCorrelationAnalysis(
performFishResponse, mapParameters, new AsyncCallback() {
@@ -503,7 +507,7 @@ public class PerformFishAnalyticsController {
public void onSuccess(DataMinerResponse dmResponse) {
submitRequestPanel.showLoader(false, null);
checkTabSpinner(submitRequestPanel, tab);
- AnalyticsPanelResult analyticsPanelResult = new AnalyticsPanelResult();
+ CorrelationPanelResult analyticsPanelResult = new CorrelationPanelResult(requestId,tabTitle, tabDescr);
analyticsPanelResult.addSelectedAreas(
performFishRequestParameters.get(PerformFishAnalyticsConstant.PERFORM_FISH_AREA_PARAM));
analyticsPanelResult.addSelectedKPIs(selectedKPI);
@@ -524,7 +528,7 @@ public class PerformFishAnalyticsController {
submitRequestPanel.showLoader(false, null);
checkTabSpinner(submitRequestPanel, tab);
try {
- AnalyticsPanelResult analyticsPanelResult = new AnalyticsPanelResult();
+ CorrelationPanelResult analyticsPanelResult = new CorrelationPanelResult(requestId, tabTitle, tabDescr);
analyticsPanelResult.addSelectedAreas(performFishRequestParameters
.get(PerformFishAnalyticsConstant.PERFORM_FISH_AREA_PARAM));
analyticsPanelResult.addSelectedKPIs(selectedKPI);
@@ -563,22 +567,23 @@ public class PerformFishAnalyticsController {
if (selectedBatchID == null || selectedBatchID.isEmpty())
Window.alert("Something seems wrong, no selected BatchID, try again");
-
+
+ requestId++;
switch (algorithm) {
case BOXPLOT:
@SuppressWarnings("unused")
- BoxPlotPanelResult boxPlotPanelResult = new BoxPlotPanelResult(requestId++, viewController, algorithm,
+ BoxPlotPanelResult boxPlotPanelResult = new BoxPlotPanelResult(requestId, viewController, algorithm,
focusID, inputKPI, outputKPI);
break;
case SPEEDOMETER:
@SuppressWarnings("unused")
- SpeedometerPanelResult speedometerPanelResult = new SpeedometerPanelResult(requestId++, viewController,
+ SpeedometerPanelResult speedometerPanelResult = new SpeedometerPanelResult(requestId, viewController,
algorithm, focusID, inputKPI, outputKPI);
break;
case SCATTER:
@SuppressWarnings("unused")
- ScatterPanelResult scatterPanelResult = new ScatterPanelResult(requestId++, viewController, algorithm,
+ ScatterPanelResult scatterPanelResult = new ScatterPanelResult(requestId, viewController, algorithm,
focusID, inputKPI, outputKPI);
break;
default:
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/resources/Batch_CORRELATION b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/resources/Batch_CORRELATION
index 1f4bb8e..3a9e4c9 100644
--- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/resources/Batch_CORRELATION
+++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/resources/Batch_CORRELATION
@@ -1,4 +1,4 @@
The correlation matrix is a table displaying the correlation between pairs of KPIs.
-Correlation coefficients are calculated using the Person parametric correlation test and coloured according to the value in red (significant positive correlation), yellow (significant negative correlation), and in light blue (non-significant correlation).
+Correlation coefficients are calculated using the Pearson parametric correlation test and coloured according to the value in red (significant positive correlation), yellow (significant negative correlation), and in light blue (non-significant correlation).
The Student t-test is used to determine the ranges of correlation for Pearson coefficients.
The analysis is performed on all batches data.
\ No newline at end of file
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/resources/Farm_CORRELATION b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/resources/Farm_CORRELATION
index c37e097..713dab2 100644
--- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/resources/Farm_CORRELATION
+++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/resources/Farm_CORRELATION
@@ -1,4 +1,4 @@
The correlation matrix is a table displaying the correlation between pairs of KPIs.
-Correlation coefficients are calculated using the Person parametric correlation test and coloured according to the value in red (significant positive correlation), yellow (significant negative correlation), and in light blue (non-significant correlation).
+Correlation coefficients are calculated using the Pearson parametric correlation test and coloured according to the value in red (significant positive correlation), yellow (significant negative correlation), and in light blue (non-significant correlation).
The Student t-test is used to determine the ranges of correlation for Pearson coefficients.
The analysis is performed on all farm data.
\ No newline at end of file
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/BoxPlotAnnualPanelResult.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/BoxPlotAnnualPanelResult.java
new file mode 100644
index 0000000..8f47935
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/BoxPlotAnnualPanelResult.java
@@ -0,0 +1,591 @@
+package org.gcube.portlets.user.performfishanalytics.client.viewannualbinder;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.gcube.portlets.user.performfishanalytics.client.DataMinerAlgorithms;
+import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant;
+import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE;
+import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync;
+import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.DataMinerInputParameters;
+import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.PerformFishAnnualAnalyticsViewController;
+import org.gcube.portlets.user.performfishanalytics.client.resources.PerformFishResources;
+import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon;
+import org.gcube.portlets.user.performfishanalytics.client.viewbinder.ShowResult;
+import org.gcube.portlets.user.performfishanalytics.client.viewbinder.SubmitRequestPanel;
+import org.gcube.portlets.user.performfishanalytics.shared.FileContentType;
+import org.gcube.portlets.user.performfishanalytics.shared.KPI;
+import org.gcube.portlets.user.performfishanalytics.shared.OutputFile;
+import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile;
+import org.gcube.portlets.user.performfishanalytics.shared.dataminer.DataMinerResponse;
+import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse;
+
+import com.github.gwtbootstrap.client.ui.Alert;
+import com.github.gwtbootstrap.client.ui.Button;
+import com.github.gwtbootstrap.client.ui.Tab;
+import com.github.gwtbootstrap.client.ui.constants.AlertType;
+import com.github.gwtbootstrap.client.ui.constants.IconType;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.shared.GWT;
+import com.google.gwt.dom.client.Style.Unit;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.resources.client.TextResource;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.ComplexPanel;
+import com.google.gwt.user.client.ui.FlexTable;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Panel;
+
+public class BoxPlotAnnualPanelResult {
+
+ private Map boxPlotOrderBy = new HashMap();
+
+ private PerformFishAnnualAnalyticsViewController viewAnnualController;
+ private int outputIteration = 0;
+ private int outputNumber = 2;
+ private int requestId = 0;
+
+ private Button savePDFButton;
+
+ public BoxPlotAnnualPanelResult(int reqId, PerformFishAnnualAnalyticsViewController viewAnnualController,
+ PerformFishResponse thePerformFishResponse, final DataMinerAlgorithms algorithm, String focusID,
+ List inputKPI, final List outputKPI) {
+ GWT.log("RequestID: " + reqId);
+ requestId = reqId;
+ this.viewAnnualController = viewAnnualController;
+ TextResource algDescr = PerformFishResources.INSTANCE.farm_BOXPLOT();
+
+ String algDesrTxt = algDescr != null ? algDescr.getText() : null;
+
+ // TODO
+ final String tabTitle = algorithm.getTitle();
+ final String tabDescr = algDesrTxt;
+
+ final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
+ Tab tab = viewAnnualController.createTab(tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1),
+ algDesrTxt, submitRequestPanel);
+
+ HorizontalPanel res = new HorizontalPanel();
+
+ savePDFButton = new Button();
+ savePDFButton.getElement().getStyle().setMargin(10, Unit.PX);
+ savePDFButton.setIcon(IconType.PRINT);
+ savePDFButton.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+ saveFilePDF(algorithm.getId(), tabTitle, tabTitle, tabDescr, requestId, outputIteration, outputNumber);
+ // dmResponse.getListOutput().size()
+ }
+ });
+ savePDFButton.setVisible(false);
+
+ res.add(savePDFButton);
+ submitRequestPanel.addWidget(res);
+ int oIteration = 0;
+
+ submitRequestPanel.setTotalRequests(inputKPI.size());
+ for (KPI kpi : inputKPI) {
+ oIteration++;
+ String title = "KPI: " + kpi.getName();
+ HTML toBigTitle = new HTML(title);
+ toBigTitle.getElement().setId("KPI_BoxPlotAnnual_" + requestId + "_" + oIteration);
+ toBigTitle.getElement().addClassName("to-big-title");
+ submitRequestPanel.addWidget(toBigTitle);
+ HorizontalPanel hp = new HorizontalPanel();
+ hp.getElement().addClassName("ext-horizontal-panel");
+
+ DataMinerInputParameters dmInputParams = new DataMinerInputParameters(thePerformFishResponse,
+ viewAnnualController.getSelectedYears(), Arrays.asList(kpi), null, algorithm, focusID);
+ callDataMinerServiceForChart(dmInputParams, submitRequestPanel, hp, tab, oIteration);
+ // resultPanel.add(hp);
+ submitRequestPanel.addWidget(hp);
+ }
+ outputIteration = oIteration;
+ GWT.log("outputInteration: " + outputIteration);
+ }
+
+ /**
+ * Call data miner service for chart.
+ *
+ * @param dmInputParameters
+ * the dm input parameters
+ * @param requestPanel
+ * the request panel
+ * @param panelContainer
+ * the panel
+ * @param tab
+ * the tab
+ * @param tabDescr
+ * @param tabTitle
+ */
+ private void callDataMinerServiceForChart(final DataMinerInputParameters dmInputParameters,
+ final SubmitRequestPanel requestPanel, final ComplexPanel panelContainer, final Tab tab,
+ final int oIteration) {
+
+ GWT.log("Building DM request with input parameters: " + dmInputParameters);
+
+ StringBuilder dataInputsFormatter = new StringBuilder();
+ dataInputsFormatter
+ .append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM + "=" + dmInputParameters.getChartType() + ";");
+
+ String yearsValue = "";
+ for (String year : dmInputParameters.getSelectedYears()) {
+ yearsValue += year + "|";
+ }
+ yearsValue = yearsValue.substring(0, yearsValue.length() - 1);
+
+ dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_YEARS_PARAM + "=" + yearsValue + ";");
+ dataInputsFormatter
+ .append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM + "=" + dmInputParameters.getFocusID() + ";");
+ // dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM+"=ID;");
+
+ if (dmInputParameters.getInputKPI() != null && dmInputParameters.getInputKPI().size() > 0) {
+ String kpiCodes = "";
+ for (KPI kpi : dmInputParameters.getInputKPI()) {
+ kpiCodes += kpi.getCode() + "|";
+ }
+ // remove last |
+ kpiCodes = kpiCodes.substring(0, kpiCodes.length() - 1);
+
+ GWT.log("Input KPICodes: " + kpiCodes);
+ // ADDING KPIs code
+ dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_INPUT_KPI_PARAM + "=" + kpiCodes + ";");
+
+ }
+
+ if (dmInputParameters.getOutputKPI() != null && dmInputParameters.getOutputKPI().size() > 0) {
+ String kpiCodes = "";
+ for (KPI kpi : dmInputParameters.getOutputKPI()) {
+ kpiCodes += kpi.getCode() + "|";
+ }
+ // remove last |
+ kpiCodes = kpiCodes.substring(0, kpiCodes.length() - 1);
+
+ GWT.log("Output KPICodes: " + kpiCodes);
+ // ADDING KPIs code
+ dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_OUTPUT_KPI_PARAM + "=" + kpiCodes + ";");
+ }
+
+ Map performFishResponseMap = dmInputParameters.getPerformFishResponse().getMapParameters();
+
+ dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
+ PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.LethalIncidentsTable);
+ dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
+ PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AnnualTable);
+ dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
+ PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntibioticsTable);
+ dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
+ PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntiparasiticTable);
+
+ String dataInParameters = dataInputsFormatter.toString();
+ GWT.log("Calling DM service with client input parameters: " + dataInParameters);
+
+ Map> mapParameters = new HashMap>();
+ mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters));
+
+ final LoaderIcon loaderIcon = new LoaderIcon(
+ "Submitting request to " + dmInputParameters.getChartType().getTitle() + " Analysis...");
+ loaderIcon.setVisible(true);
+ panelContainer.setVisible(true);
+ panelContainer.add(loaderIcon);
+ Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
+ @Override
+ public void execute() {
+ loaderIcon.setFocus(true);
+ }
+ });
+
+ PerformFishAnalyticsServiceAsync.Util.getInstance().callingDataMinerPerformFishAnnualAnalysis(mapParameters,
+ new AsyncCallback() {
+
+ @Override
+ public void onSuccess(DataMinerResponse dmResponse) {
+ loaderIcon.setVisible(false);
+ checkTabSpinner(requestPanel, tab);
+ // field_unary_algorithm.setVisible(true);
+ GWT.log("I'm displaying: " + dmResponse);
+ displayOutputFilesAsStaticEntities(dmResponse, dmInputParameters.getChartType(),
+ dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
+ dmInputParameters.getFocusID(), panelContainer, false, oIteration);
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ loaderIcon.setVisible(false);
+ checkTabSpinner(requestPanel, tab);
+ displayOutputFilesAsStaticEntities(null, dmInputParameters.getChartType(),
+ dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
+ dmInputParameters.getFocusID(), panelContainer, true, oIteration);
+
+ }
+ });
+ }
+
+ /**
+ * Append DM input table.
+ *
+ * @param performFishResponseMap
+ * the perform fish response map
+ * @param dataInputsFormatter
+ * the data inputs formatter
+ * @param table
+ * the table
+ * @return the string builder
+ */
+ private StringBuilder appendDMInputTable(Map performFishResponseMap,
+ StringBuilder dataInputsFormatter, PFSERVICE_TO_DM_MAPPING_TABLE table) {
+
+ String toDMInputTable = performFishResponseMap.get(table.getPerformFishTable());
+
+ if (toDMInputTable != null && !toDMInputTable.isEmpty()) {
+ dataInputsFormatter.append(table.getDataMinerTable() + "=" + toDMInputTable + ";");
+ }
+
+ return dataInputsFormatter;
+ }
+
+ private String getOutputId(int oIteration, String title) {
+ if (title.startsWith("My")) {
+ return null;
+ } else if (title.startsWith("All")) {
+ String outputId = "OutputId_" + requestId + "_" + oIteration + "_" + 1;
+ return outputId;
+ } else {
+ String outputId = "OutputId_" + requestId + "_" + oIteration + "_" + 2;
+ return outputId;
+ }
+
+ }
+
+ private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
+ final DataMinerAlgorithms chartType, List inputKPIs, List outputKPIs, final String focusID,
+ final Panel container, boolean displayError, final int oIteration) {
+
+ String title = displayError ? "No results " : "";
+
+ if (displayError) {
+ Alert alert = new Alert(title);
+ alert.setType(AlertType.ERROR);
+ alert.setClose(false);
+ alert.getElement().getStyle().setMargin(10, Unit.PX);
+ container.add(alert);
+ return;
+ }
+
+ savePDFButton.setVisible(true);
+ final String toTitle = title;
+
+ for (OutputFile outputFile : dmResponse.getListOutput()) {
+ final FileContentType fileContentType = outputFile.getDataType();
+ switch (outputFile.getDataType()) {
+ case IMAGE:
+
+ PerformFishAnalyticsServiceAsync.Util.getInstance().getImageFile(outputFile,
+ new AsyncCallback() {
+
+ @Override
+ public void onFailure(Throwable caught) {
+ // showAlert(caught.getMessage(),
+ // AlertType.ERROR, true,
+ // uib_vp_deanalanlysis_request_container);
+ Window.alert(caught.getMessage());
+
+ }
+
+ @Override
+ public void onSuccess(String base64Content) {
+
+ String title = toTitle;
+
+ title = chartType.getTitle() + " - on all farm data
";
+ title += "Blue dots indicate the selected farm: " + focusID;
+
+ String outputId = getOutputId(oIteration, title);
+ ShowResult showResult = new ShowResult(outputId, title, fileContentType);
+ showResult.showImage(base64Content);
+ displayingOrderedBoxPlot(dmResponse, title, container, showResult);
+
+ }
+ });
+ break;
+ case CSV:
+
+ PerformFishAnalyticsServiceAsync.Util.getInstance().getCSVFile(outputFile, true,
+ new AsyncCallback() {
+
+ @Override
+ public void onFailure(Throwable caught) {
+ // showAlert(caught.getMessage(),
+ // AlertType.ERROR, true,
+ // uib_vp_deanalanlysis_request_container);
+ Window.alert(caught.getMessage());
+ }
+
+ @Override
+ public void onSuccess(CSVFile result) {
+ GWT.log("Displaying: " + result);
+
+ String cssTableStyle = "simpletable";
+
+ String title = toTitle;
+
+ if (result.getFileName().contains("_user")) {
+ title = "My Batch(es)";
+ return;
+ } else {
+ title = "All farm data in the VRE (including mine)";
+ }
+ title += "
";
+ title += "Data aggregation is performed by considering farms as base units";
+
+ String outputId = getOutputId(oIteration, title);
+ ShowResult showResult = new ShowResult(outputId, title, fileContentType);
+ showResult.showCSVFile(result, cssTableStyle);
+ displayingOrderedBoxPlot(dmResponse, title, container, showResult);
+
+ }
+ });
+ break;
+
+ default:
+ break;
+ }
+
+ }
+
+ }
+
+ private void displayingOrderedBoxPlot(final DataMinerResponse dmResponse, String title, final Panel container,
+ ShowResult showResult) {
+ int hashcode = dmResponse.hashCode();
+ GWT.log("The hascode is: " + hashcode);
+ FlexTable flex = boxPlotOrderBy.get(hashcode);
+
+ if (flex == null) {
+ GWT.log("The flextable is null");
+ flex = new FlexTable();
+ boxPlotOrderBy.put(hashcode, flex);
+ container.add(flex);
+ }
+
+ if (title.startsWith("My")) {
+ flex.setWidget(0, 0, showResult);
+ } else if (title.startsWith("All")) {
+ flex.setWidget(0, 1, showResult);
+ } else {
+ flex.setWidget(0, 2, showResult);
+ }
+ }
+
+ /**
+ * Remove the spinner if all DM responses are returned.
+ *
+ * @param requestPanel
+ * the request panel
+ * @param tab
+ * the tab
+ */
+ private void checkTabSpinner(SubmitRequestPanel requestPanel, Tab tab) {
+ requestPanel.incrementCompletedRequests();
+ int completed = requestPanel.getCompletedRequests();
+ int total = requestPanel.getTotalRequests();
+
+ if (completed >= total) {
+ viewAnnualController.noSpinner(tab);
+ }
+ }
+
+ private static native void saveFilePDF(String chartType, String filename, String tabTitle, String tabDescr,
+ int requestId, int outputIteration, int outputNumber)/*-{
+ var that = this;
+ console.log('saveFilePDF()');
+ console.log('requestId: ' + requestId);
+ console.log('OutputIteration: ' + outputIteration);
+ console.log('OutputNumber:' + outputNumber);
+
+ var tTitle = tabTitle;
+ var tDescr = tabDescr;
+
+ var pdoc = new jsPDF("p", "mm", "a4");
+ pdoc.setProperties({
+ title : 'PerformFish ' + tTitle,
+ subject : ' Results',
+ author : 'PerformFish',
+ keywords : 'PerformFish',
+ creator : 'D4Science'
+ });
+
+ var lMargin = 15; //left margin in mm
+ var rMargin = 15; //right margin in mm
+ var tMargin = 15; //top margin in mm
+ var bMargin = 15; //bottom margin in mm
+ var pdfWidthInMM = 210; // width of A4 in mm
+ var pdfHeightInMM = 297; // height of A4 in mm
+ var pageCenter = pdfWidthInMM / 2;
+
+ pdoc.setFontSize(24);
+ var title = "PerformFish " + tTitle;
+ var titleHeight = pdoc.getLineHeight(title) / pdoc.internal.scaleFactor
+ var xPos = lMargin;
+ var yPos = tMargin;
+ pdoc.text(title, pageCenter, yPos, 'center');
+ yPos += titleHeight;
+
+ pdoc.setFontSize(10);
+ var lineHeight = pdoc.getLineHeight(tDescr) / pdoc.internal.scaleFactor
+ var splittedAnalysisDescription = pdoc.splitTextToSize(tDescr,
+ (pdfWidthInMM - lMargin - rMargin));
+ var lines = splittedAnalysisDescription.length // splitted text is a string array
+ var analysisDescriptionHeight = lines * lineHeight
+
+ pdoc.text(splittedAnalysisDescription, xPos, yPos, 'left');
+ yPos += analysisDescriptionHeight;
+
+ //yPos += 2;
+ //pdoc.text("Analysis:", xPos, yPos, 'left');
+ yPos += 6;
+
+ for (var i = 1; i <= outputIteration; i++) {
+
+ var kpiId = 'KPI_BoxPlotAnnual_' + requestId + '_' + i;
+ console.log('kpiId: ' + kpiId);
+
+ var kpiName = $doc.getElementById(kpiId);
+
+ yPos += 2;
+ pdoc.setFontSize(14);
+ pdoc.setFontType("bold");
+
+ var kpiText = kpiName.textContent;
+ var kpiHeight = pdoc.getLineHeight(kpiText)
+ / pdoc.internal.scaleFactor;
+ var splittedKpiName = pdoc.splitTextToSize(kpiText, (pdfWidthInMM
+ - lMargin - rMargin));
+ var kpiLines = splittedKpiName.length; // splitted text is a string array
+ var kpiLinesHeight = kpiLines * kpiHeight;
+ pdoc.text(splittedKpiName, xPos, yPos, 'left');
+ yPos += kpiLinesHeight;
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
+ for (var j = 1; j <= outputNumber; j++) {
+
+ var outputId = 'OutputId_' + requestId + '_' + i + '_' + j;
+ console.log('OutputId: ' + outputId);
+
+ var resultOutputNumber = $doc.getElementById(outputId);
+
+ console.log('OutputId_: ' + resultOutputNumber.innerHTML);
+ var resultType = resultOutputNumber.className;
+
+ console.log('resultOutputNumber className: ' + resultType);
+
+ if (typeof resultType !== 'undefined' && resultType !== null
+ && resultType !== '') {
+
+ if (resultType == 'csv') {
+ console.log('Result Type csv: ' + i);
+ // foo could get resolved and it's defined
+
+ var childrenTable = resultOutputNumber.children;
+ var titleCurrentTable = childrenTable[0].rows[0].cells[0];
+ console.log('Title current table: '
+ + titleCurrentTable.textContent);
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text(titleCurrentTable.textContent, xPos, yPos,
+ 'left');
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
+ var secondDiv = childrenTable[0].rows[1].cells[0];
+ var secondTable = secondDiv.children[0].children[0];
+
+ console.log('CSV SecondTable: ' + secondTable);
+
+ pdoc.autoTable({
+ theme : 'grid',
+ startY : yPos,
+ pageBreak : 'auto',
+ bodyStyles : {
+ fontSize : 9
+ },
+ html : secondTable
+ });
+
+ yPos = pdoc.previousAutoTable.finalY + 6;
+ } else {
+ if (resultType == 'image') {
+ console.log('Result Type image: ' + i);
+ var childrenTable = resultOutputNumber.children;
+
+ var titleCurrentImage = childrenTable[0].rows[0].cells[0];
+ console.log('Title current image: '
+ + titleCurrentImage.textContent);
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text(titleCurrentImage.textContent, xPos,
+ yPos, 'left');
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
+ var secondDiv = childrenTable[0].rows[1].cells[0];
+ var imageElement = secondDiv.getElementsByTagName(
+ 'img').item(0);
+ console.log('Image element: ' + imageElement);
+ pdoc.addImage(imageElement, lMargin, yPos);
+ console.log('Image Height: ' + imageElement.height);
+ yPos += (imageElement.height * 0.26458333);
+
+ } else {
+ console.log('Result Type unknow: ' + i);
+ }
+
+ }
+ } else {
+ console.log('Result Type is undefined:' + i);
+ }
+
+ }
+
+ if (i < outputIteration) {
+ pdoc.addPage();
+ yPos = tMargin; // Restart position
+ } else {
+
+ }
+
+ }
+
+
+ var numberOfPages=pdoc.internal.getNumberOfPages()
+ console.log('NumberOfPages: ' + numberOfPages);
+ for (var k = 1; k <= numberOfPages; k++) {
+ pdoc.setPage(k);
+ console.log('CurrentPage: ' + k);
+ var footner = 'Page ' + k + "/"+numberOfPages;
+ pdoc.text(footner, pageCenter, pdfHeightInMM - 7, 'center');
+
+ }
+
+ console.log('Done');
+
+ pdoc.save(filename);
+
+ }-*/;
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnalyticsAnnualPanelResult.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/CorrelationAnnualPanelResult.java
similarity index 71%
rename from src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnalyticsAnnualPanelResult.java
rename to src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/CorrelationAnnualPanelResult.java
index 224f8cd..ed11fd4 100644
--- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnalyticsAnnualPanelResult.java
+++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/CorrelationAnnualPanelResult.java
@@ -10,7 +10,7 @@ import java.util.Map;
import org.gcube.portlets.user.performfishanalytics.client.DataMinerAlgorithms;
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync;
-import org.gcube.portlets.user.performfishanalytics.client.controllers.PerformFishAnalyticsController;
+import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.PerformFishAnnualAnalyticsController;
import org.gcube.portlets.user.performfishanalytics.client.event.CallAlgorithmEvent;
import org.gcube.portlets.user.performfishanalytics.client.view.util.CorrelationValueToColourUtil;
import org.gcube.portlets.user.performfishanalytics.shared.FileContentType;
@@ -32,7 +32,6 @@ import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.AttachEvent;
-import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -51,13 +50,13 @@ import com.google.gwt.user.client.ui.Widget;
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jan 29, 2019
*/
-public class AnalyticsAnnualPanelResult extends Composite {
+public class CorrelationAnnualPanelResult extends Composite {
/**
*
*/
- private static AnalyticsPanelResultUiBinder uiBinder = GWT.create(AnalyticsPanelResultUiBinder.class);
+ private static CorrelationPanelResultUiBinder uiBinder = GWT.create(CorrelationPanelResultUiBinder.class);
/**
* The Interface AnalyticsPanelResultUiBinder.
@@ -65,7 +64,7 @@ public class AnalyticsAnnualPanelResult extends Composite {
* @author Francesco Mangiacrapa at ISTI-CNR
* (francesco.mangiacrapa@isti.cnr.it) Jan 30, 2019
*/
- interface AnalyticsPanelResultUiBinder extends UiBinder {
+ interface CorrelationPanelResultUiBinder extends UiBinder {
}
@UiField
@@ -114,19 +113,17 @@ public class AnalyticsAnnualPanelResult extends Composite {
private List selectedAreas;
- // private HandlerManager theEventBus;
-
private Map csvGenerated = new HashMap();
- private AnalyticsAnnualPanelResult analyticsPanelResult;
+ private CorrelationAnnualPanelResult analyticsPanelResult;
- private static int callNumber;
+ private int outputNumber;
+ private int requestId = 0;
- private static Map outputNumbers = new HashMap();
-
- private String analysisDescription;
-
- public AnalyticsAnnualPanelResult(HandlerManager eventBus) {
+ public CorrelationAnnualPanelResult(int reqId, final String tabTitle,
+ final String tabDescription) {
+ GWT.log("RequestID: " + reqId);
+ requestId = reqId;
initWidget(uiBinder.createAndBindUi(this));
// this.theEventBus = eventBus;
@@ -138,26 +135,10 @@ public class AnalyticsAnnualPanelResult extends Composite {
@Override
public void onClick(ClickEvent event) {
- saveFilePDF(analyticsPanelResult, "AnalysisResult.pdf");
+ saveFilePDF(analyticsPanelResult, tabTitle, tabTitle, tabDescription, requestId, outputNumber);
}
});
- /*
- * uib_save_pdf_2.setIcon(IconType.PRINT);
- * uib_save_pdf_2.addClickHandler(new ClickHandler() {
- *
- * @Override public void onClick(ClickEvent event) {
- * saveFilePDF(analyticsPanelResult, "AnalysisResult.pdf"); } });
- */
-
- }
-
- public String getAnalysisDescription() {
- return analysisDescription;
- }
-
- public void setAnalysisDescription(String analysisDescription) {
- this.analysisDescription = analysisDescription;
}
/**
@@ -256,6 +237,7 @@ public class AnalyticsAnnualPanelResult extends Composite {
public void addParameters(String keyToGet, Map> parameters, String toShowBatchTypeValue) {
final FlexTable flexTable = new FlexTable();
+ flexTable.getElement().setId("CorrelationParameterInputKPIs");
flexTable.setStyleName("colgrouptable");
try {
@@ -289,8 +271,8 @@ public class AnalyticsAnnualPanelResult extends Composite {
KPINames += kpi.getName() + ", ";
}
KPINames = KPINames.substring(0, KPINames.length() - 2);
- flexTable.setWidget(2, 0, new HTML("KPIs:"));
- flexTable.setWidget(2, 1, new HTML(KPINames));
+ flexTable.setWidget(1, 0, new HTML("KPIs:"));
+ flexTable.setWidget(1, 1, new HTML(KPINames));
} catch (Exception e) {
// silent
@@ -311,6 +293,13 @@ public class AnalyticsAnnualPanelResult extends Composite {
}
}
+ private String getOutputId() {
+ outputNumber++;
+ String outputId = "OutputId_" + requestId + "_" + outputNumber;
+ GWT.log("Generated OutputId: " + outputId);
+ return outputId;
+ }
+
/**
* Adds the results.
*
@@ -321,7 +310,8 @@ public class AnalyticsAnnualPanelResult extends Composite {
this.dmResponse = dmResponse;
- for (final OutputFile outputFile : dmResponse.getListOutput()) {
+ outputNumber = 0;
+ for (OutputFile outputFile : dmResponse.getListOutput()) {
if (outputFile.getDataType().equals(FileContentType.CSV)) {
PerformFishAnalyticsServiceAsync.Util.getInstance().getCSVFile(outputFile, true,
@@ -373,7 +363,9 @@ public class AnalyticsAnnualPanelResult extends Composite {
HorizontalPanel hp = new HorizontalPanel();
final FlexTable flexTable = new FlexTable();
+
flexTable.setStyleName("fixedtable");
+ flexTable.getElement().setId(getOutputId());
flexTable.getElement().getStyle().setMarginBottom(10, Unit.PX);
flexTable.setWidget(0, 0, new Label(""));
@@ -453,7 +445,7 @@ public class AnalyticsAnnualPanelResult extends Composite {
}
}
});
-
+ buttonHTML.getElement().getStyle().setBackgroundColor(theColor);
flexTable.setWidget(rowIndex, j, buttonHTML);
}
@@ -462,6 +454,7 @@ public class AnalyticsAnnualPanelResult extends Composite {
hp.add(flexTable);
final FlexTable flexLegend = new FlexTable();
+ flexLegend.getElement().setId(getOutputId());
flexLegend.setStyleName("simpletable");
Map map = CorrelationValueToColourUtil.getMap();
flexLegend.setWidget(0, 0, new Label("Legend"));
@@ -470,6 +463,7 @@ public class AnalyticsAnnualPanelResult extends Composite {
for (String key : map.keySet()) {
final String rgbColor = map.get(key);
final HTML theLegendColor = new HTML("");
+ theLegendColor.getElement().getStyle().setBackgroundColor(rgbColor);
flexLegend.setWidget(i, 0, theLegendColor);
flexLegend.setWidget(i, 1, new HTML(key));
theLegendColor.addAttachHandler(new AttachEvent.Handler() {
@@ -567,17 +561,21 @@ public class AnalyticsAnnualPanelResult extends Composite {
GWT.log("Called ScatterChart at rowIndex: " + rowIndex + ", columnIndex: " + columnIndex);
List selectedKPI = getKPIForIndexes(rowIndex, columnIndex);
GWT.log("Selected KPI: " + selectedKPI);
- PerformFishAnalyticsController.eventBus
+ PerformFishAnnualAnalyticsController.eventBus
.fireEvent(new CallAlgorithmEvent(DataMinerAlgorithms.SCATTER, focusID, selectedKPI, null));
}
- private static native void saveFilePDF(AnalyticsAnnualPanelResult chart, String filename)/*-{
+ private static native void saveFilePDF(CorrelationAnnualPanelResult chart, String filename, String tabTitle,
+ String tabDescr, int requestId, int outputNumber)/*-{
var that = this;
console.log('saveFilePDF()');
+ var tTitle = tabTitle;
+ var tDescr = tabDescr;
+
var pdoc = new jsPDF("p", "mm", "a4");
pdoc.setProperties({
- title : 'PerformFish Analysis',
+ title : 'PerformFish ' + tTitle,
subject : ' Results',
author : 'PerformFish',
keywords : 'PerformFish',
@@ -593,131 +591,196 @@ public class AnalyticsAnnualPanelResult extends Composite {
var pageCenter = pdfWidthInMM / 2;
pdoc.setFontSize(24);
- var title = "PerformFish Analysis";
+ var title = "PerformFish " + tTitle;
var titleHeight = pdoc.getLineHeight(title) / pdoc.internal.scaleFactor
var xPos = lMargin;
var yPos = tMargin;
pdoc.text(title, pageCenter, yPos, 'center');
yPos += titleHeight;
- var analysisDescription = chart.@org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.AnalyticsAnnualPanelResult::analysisDescription;
-
pdoc.setFontSize(10);
- var lineHeight = pdoc.getLineHeight(deaDescription)
- / pdoc.internal.scaleFactor
- var splittedAnalysisDescription = pdoc.splitTextToSize(
- analysisDescription, (pdfWidthInMM - lMargin - rMargin));
+ var lineHeight = pdoc.getLineHeight(tDescr) / pdoc.internal.scaleFactor
+ var splittedAnalysisDescription = pdoc.splitTextToSize(tDescr,
+ (pdfWidthInMM - lMargin - rMargin));
var lines = splittedAnalysisDescription.length // splitted text is a string array
var analysisDescriptionHeight = lines * lineHeight
pdoc.text(splittedAnalysisDescription, xPos, yPos, 'left');
yPos += analysisDescriptionHeight;
- yPos += 2;
- pdoc.text("Analysis:", xPos, yPos, 'left');
- yPos += 6;
+ yPos += 4;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text("Parameters:", xPos, yPos, 'left');
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+ yPos += 4;
- var callNumber = @org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.AnalyticsAnnualPanelResult::callNumber;
- console.log('CallNumber: ' + callNumber);
+ var correlationParametersInputKPIs = $doc
+ .getElementById('CorrelationParameterInputKPIs');
- for (var n = 1; n <= callNumber; n++) {
- var deaAnalysisResultParametersInputKPIs = $doc
- .getElementById('DeaAnalysisResultParameterInputKPIs_' + n).innerHTML;
+ console.log('InputKPIs: ' + correlationParametersInputKPIs);
- console.log('InputKPIs: ' + deaAnalysisResultParametersInputKPIs);
- var deaAnalysisResultParametersOutputKPIs = $doc
- .getElementById('DeaAnalysisResultParameterOutputKPIs_' + n).innerHTML;
- console.log('OuputKPIs: ' + deaAnalysisResultParametersOutputKPIs);
-
- pdoc.autoTable({
- theme : 'plain',
- startY : yPos,
- pageBreak : 'auto',
- columnStyles : {
- 0 : {
- halign : 'left',
- fillColor : [ 211, 225, 241 ]
- }
- },
- head : null,
- body : [
- [ 'Selected Input KPIs',
- deaAnalysisResultParametersInputKPIs ],
- [ 'Selected Output KPIs',
- deaAnalysisResultParametersOutputKPIs ] ]
- });
-
- yPos = pdoc.previousAutoTable.finalY + 6;
-
- var deaAnalysisResults = $doc.getElementById('DeaAnalysisResults');
-
- var deaAnalysisResult = $doc.getElementById('DeaAnalysisResult_'
- + n);
-
- console.log("DeaAnalysisResult: " + n);
-
- var outputNumber = @org.gcube.portlets.user.performfishanalytics.client.viewbinder.DeaPanelResult::getOutputNumber(Ljava/lang/String;)('DeaAnalysisResult_'+ n);
- console.log('OutputNumber: ' + outputNumber);
-
- for (var i = 1; i <= outputNumber; i++) {
-
- var deaOutputId = 'DeaAnalysisResult_' + n + '_' + i;
- console.log('DeaOutputId: ' + deaOutputId);
-
- var deaOutputNumber = $doc.getElementById(deaOutputId);
-
- console.log('DeaOutputNumber: ' + deaOutputNumber.innerHTML);
- var resultType = deaOutputNumber.className;
-
- console.log('DeaOutputNumber className: ' + resultType);
-
- if (typeof resultType !== 'undefined' && resultType !== null
- && resultType !== '') {
-
- if (resultType == 'csv') {
- console.log('Result Type csv: ' + i);
- // foo could get resolved and it's defined
-
- var childrenTable = deaOutputNumber.children;
- var secondDiv = childrenTable[0].rows[1].cells[0];
- var secondTable = secondDiv.children[0].children[0];
-
- console.log('CSV SecondTable: ' + secondTable);
-
- pdoc.autoTable({
- theme : 'grid',
- startY : yPos,
- pageBreak : 'auto',
- bodyStyles : {
- fontSize : 9
- },
- html : secondTable
- });
-
- yPos = pdoc.previousAutoTable.finalY + 6;
- } else {
- if (resultType == 'image') {
- console.log('Result Type image: ' + i);
- var childrenTable = deaOutputNumber.children;
- var secondDiv = childrenTable[0].rows[1].cells[0];
- var imageElement = secondDiv.getElementsByTagName(
- 'img').item(0);
- console.log('Image element: ' + imageElement);
- pdoc.addImage(imageElement, lMargin, yPos);
- console.log('Image Height: ' + imageElement.height);
- yPos += (imageElement.height * 0.26458333);
-
- } else {
- console.log('Result Type unknow: ' + i);
- }
-
- }
- } else {
- console.log('Result Type is undefined:' + i);
+ pdoc.autoTable({
+ theme : 'plain',
+ startY : yPos,
+ pageBreak : 'auto',
+ columnStyles : {
+ 0 : {
+ halign : 'left',
+ fillColor : [ 211, 225, 241 ]
}
+ },
+ html : correlationParametersInputKPIs
+ });
+
+ //head : null,
+ // body : [
+ // [ 'Parameters',
+ // correlationParametersInputKPIs ]
+ // ]
+
+ yPos = pdoc.previousAutoTable.finalY + 6;
+
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text("CORRELATION Matrix:", xPos, yPos, 'left');
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+ yPos += 4;
+
+ console.log('OutputNumber: ' + outputNumber);
+
+ for (var i = 1; i <= outputNumber; i++) {
+
+ var outputId = 'OutputId_' + requestId + '_' + i;
+ console.log('OutputId: ' + outputId);
+
+ var resultElement = $doc.getElementById(outputId);
+
+ console.log('Result Element: ' + resultElement);
+ var resultType = resultElement.className;
+
+ console.log('Result Element className: ' + resultType);
+
+ if (typeof resultType !== 'undefined' && resultType !== null
+ && resultType !== '') {
+
+ if (resultType == 'fixedtable' || resultType == 'simpletable') {
+ console.log('Result Type csv: ' + i);
+ console.log('Result Content: ' + resultElement.innerHTML);
+
+ var checkColor = function(data) {
+ if (data.section === 'body') {
+ console.log(data);
+ if (typeof data.cell !== 'undefined'
+ && data.cell !== null) {
+ if (typeof data.cell.raw !== 'undefined'
+ && data.cell.raw !== null) {
+ console.log(data.cell.raw.innerHTML);
+ var positive = 'rgb(255, 68, 45)';
+ var negative = 'rgb(173, 216, 230)';
+ var nonsignificant = 'rgb(230, 223, 0)';
+
+ if (data.cell.raw.innerHTML
+ .indexOf(positive) >= 0) {
+ data.cell.styles.fillColor = [ 255, 68,
+ 45 ];
+ } else {
+ if (data.cell.raw.innerHTML
+ .indexOf(negative) >= 0) {
+ data.cell.styles.fillColor = [ 173,
+ 216, 230 ];
+ } else {
+ if (data.cell.raw.innerHTML
+ .indexOf(nonsignificant) >= 0) {
+ data.cell.styles.fillColor = [
+ 230, 223, 0 ];
+ } else {
+
+ }
+
+ }
+
+ }
+ }
+ }
+
+ }
+ };
+
+ pdoc.autoTable({
+ theme : 'grid',
+ startY : yPos,
+ pageBreak : 'auto',
+ bodyStyles : {
+ fontSize : 9
+ },
+ didParseCell : checkColor,
+ html : resultElement
+ });
+
+ yPos = pdoc.previousAutoTable.finalY + 6;
+ } else {
+ if (resultType == 'image') {
+ console.log('Result Type image: ' + i);
+ var childrenTable = outputNumber.children;
+ var secondDiv = childrenTable[0].rows[1].cells[0];
+ var imageElement = secondDiv
+ .getElementsByTagName('img').item(0);
+ console.log('Image element: ' + imageElement);
+ pdoc.addImage(imageElement, lMargin, yPos);
+ console.log('Image Height: ' + imageElement.height);
+ yPos += (imageElement.height * 0.26458333);
+
+ } else {
+ console.log('Result Type unknow: ' + i);
+ }
+
+ }
+ } else {
+ console.log('Result Type is undefined:' + i);
}
+
+ if (i == outputNumber) {
+
+ } else {
+ if (pdfHeightInMM - yPos < pdfHeightInMM / 7) {
+ pdoc.addPage();
+ yPos = tMargin; // Restart position
+ }
+ }
+
}
+
+ var focusIDElement = $doc
+ .getElementById('field_list_focus_id_correlation');
+ console.log('FocusID Element: ' + focusIDElement);
+ var selectedIndex = focusIDElement.selectedIndex;
+ if (selectedIndex > -1) {
+ var value = focusIDElement[selectedIndex].innerText;
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+ pdoc.text("Focus ID: "+value, xPos, yPos, 'left');
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+ yPos += 4;
+
+ }
+
+ var numberOfPages = pdoc.internal.getNumberOfPages()
+ console.log('NumberOfPages: ' + numberOfPages);
+ for (var k = 1; k <= numberOfPages; k++) {
+ pdoc.setPage(k);
+ console.log('CurrentPage: ' + k);
+ var footner = 'Page ' + k + "/" + numberOfPages;
+ pdoc.text(footner, pageCenter, pdfHeightInMM - 7, 'center');
+
+ }
+
console.log('Done');
pdoc.save(filename);
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnalyticsAnnualPanelResult.ui.xml b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/CorrelationAnnualPanelResult.ui.xml
similarity index 100%
rename from src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnalyticsAnnualPanelResult.ui.xml
rename to src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/CorrelationAnnualPanelResult.ui.xml
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/ScatterAnnualPanelResult.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/ScatterAnnualPanelResult.java
new file mode 100644
index 0000000..ae4242d
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/ScatterAnnualPanelResult.java
@@ -0,0 +1,548 @@
+package org.gcube.portlets.user.performfishanalytics.client.viewannualbinder;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.gcube.portlets.user.performfishanalytics.client.DataMinerAlgorithms;
+import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant;
+import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE;
+import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync;
+import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.DataMinerInputParameters;
+import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.PerformFishAnnualAnalyticsViewController;
+import org.gcube.portlets.user.performfishanalytics.client.resources.PerformFishResources;
+import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon;
+import org.gcube.portlets.user.performfishanalytics.client.viewbinder.ShowResult;
+import org.gcube.portlets.user.performfishanalytics.client.viewbinder.SubmitRequestPanel;
+import org.gcube.portlets.user.performfishanalytics.shared.FileContentType;
+import org.gcube.portlets.user.performfishanalytics.shared.KPI;
+import org.gcube.portlets.user.performfishanalytics.shared.OutputFile;
+import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile;
+import org.gcube.portlets.user.performfishanalytics.shared.dataminer.DataMinerResponse;
+import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse;
+
+import com.github.gwtbootstrap.client.ui.Alert;
+import com.github.gwtbootstrap.client.ui.Button;
+import com.github.gwtbootstrap.client.ui.Tab;
+import com.github.gwtbootstrap.client.ui.constants.AlertType;
+import com.github.gwtbootstrap.client.ui.constants.IconType;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.shared.GWT;
+import com.google.gwt.dom.client.Style.Unit;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.resources.client.TextResource;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.ComplexPanel;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Panel;
+
+public class ScatterAnnualPanelResult {
+
+ private PerformFishAnnualAnalyticsViewController viewAnnualController;
+ private int requestId;
+ private int outputIteration = 1;
+ private int outputNumber = 1;
+ private Button savePDFButton;
+
+ public ScatterAnnualPanelResult(int reqId, PerformFishAnnualAnalyticsViewController viewAnnualController,
+ PerformFishResponse thePerformFishResponse, final DataMinerAlgorithms algorithm, String focusID,
+ List inputKPI, final List outputKPI) {
+ GWT.log("RequestID: " + reqId);
+ requestId = reqId;
+ this.viewAnnualController = viewAnnualController;
+ TextResource algDescr = PerformFishResources.INSTANCE.farm_SCATTER();
+ String algDesrTxt = algDescr != null ? algDescr.getText() : null;
+
+ // TODO
+ final String tabTitle = algorithm.getTitle();
+ final String tabDescr = algDesrTxt;
+
+ final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
+
+ Tab tab = viewAnnualController.createTab(tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1),
+ algDesrTxt, submitRequestPanel);
+
+ HorizontalPanel res = new HorizontalPanel();
+
+ savePDFButton = new Button();
+ savePDFButton.getElement().getStyle().setMargin(10, Unit.PX);
+ savePDFButton.setIcon(IconType.PRINT);
+ savePDFButton.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+ saveFilePDF(algorithm.getId(), tabTitle, tabTitle, tabDescr, requestId, outputIteration, outputNumber);
+ // dmResponse.getListOutput().size()
+ }
+ });
+ savePDFButton.setVisible(false);
+
+ res.add(savePDFButton);
+ submitRequestPanel.addWidget(res);
+
+ if (inputKPI.get(0) == null || inputKPI.get(1) == null) {
+ submitRequestPanel
+ .setTheTitle("Sorry, something seems wrong, the selected KPIs are not valid. Please try again");
+ checkTabSpinner(submitRequestPanel, tab);
+ return;
+ // Window.alert("Something seems wrong, no selected BatchID, try
+ // again");
+ }
+
+ String title = "KPI: " + inputKPI.get(0).getName() + " vs " + inputKPI.get(1).getName();
+
+ HTML toBigTitle = new HTML(title);
+ toBigTitle.getElement().setId("KPI_ScatterAnnual_" + requestId + "_" + outputIteration);
+ toBigTitle.getElement().addClassName("to-big-title");
+ submitRequestPanel.addWidget(toBigTitle);
+ HorizontalPanel hp = new HorizontalPanel();
+ hp.getElement().addClassName("ext-horizontal-panel");
+
+ DataMinerInputParameters dmInputParams = new DataMinerInputParameters(thePerformFishResponse,
+ viewAnnualController.getSelectedYears(), inputKPI, outputKPI, algorithm, focusID);
+ callDataMinerServiceForChart(dmInputParams, submitRequestPanel, hp, tab, outputIteration);
+ submitRequestPanel.addWidget(hp);
+
+ }
+
+ /**
+ * Call data miner service for chart.
+ *
+ * @param dmInputParameters
+ * the dm input parameters
+ * @param requestPanel
+ * the request panel
+ * @param panelContainer
+ * the panel
+ * @param tab
+ * the tab
+ * @param tabDescr
+ * @param tabTitle
+ */
+ private void callDataMinerServiceForChart(final DataMinerInputParameters dmInputParameters,
+ final SubmitRequestPanel requestPanel, final ComplexPanel panelContainer, final Tab tab,
+ final int oIteration) {
+
+ GWT.log("Building DM request with input parameters: " + dmInputParameters);
+
+ StringBuilder dataInputsFormatter = new StringBuilder();
+ dataInputsFormatter
+ .append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM + "=" + dmInputParameters.getChartType() + ";");
+
+ String yearsValue = "";
+ for (String year : dmInputParameters.getSelectedYears()) {
+ yearsValue += year + "|";
+ }
+ yearsValue = yearsValue.substring(0, yearsValue.length() - 1);
+
+ dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_YEARS_PARAM + "=" + yearsValue + ";");
+ dataInputsFormatter
+ .append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM + "=" + dmInputParameters.getFocusID() + ";");
+ // dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM+"=ID;");
+
+ if (dmInputParameters.getInputKPI() != null && dmInputParameters.getInputKPI().size() > 0) {
+ String kpiCodes = "";
+ for (KPI kpi : dmInputParameters.getInputKPI()) {
+ kpiCodes += kpi.getCode() + "|";
+ }
+ // remove last |
+ kpiCodes = kpiCodes.substring(0, kpiCodes.length() - 1);
+
+ GWT.log("Input KPICodes: " + kpiCodes);
+ // ADDING KPIs code
+ dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_INPUT_KPI_PARAM + "=" + kpiCodes + ";");
+
+ }
+
+ if (dmInputParameters.getOutputKPI() != null && dmInputParameters.getOutputKPI().size() > 0) {
+ String kpiCodes = "";
+ for (KPI kpi : dmInputParameters.getOutputKPI()) {
+ kpiCodes += kpi.getCode() + "|";
+ }
+ // remove last |
+ kpiCodes = kpiCodes.substring(0, kpiCodes.length() - 1);
+
+ GWT.log("Output KPICodes: " + kpiCodes);
+ // ADDING KPIs code
+ dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_OUTPUT_KPI_PARAM + "=" + kpiCodes + ";");
+ }
+
+ Map performFishResponseMap = dmInputParameters.getPerformFishResponse().getMapParameters();
+
+ dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
+ PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.LethalIncidentsTable);
+ dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
+ PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AnnualTable);
+ dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
+ PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntibioticsTable);
+ dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
+ PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntiparasiticTable);
+
+ String dataInParameters = dataInputsFormatter.toString();
+ GWT.log("Calling DM service with client input parameters: " + dataInParameters);
+
+ Map> mapParameters = new HashMap>();
+ mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters));
+
+ final LoaderIcon loaderIcon = new LoaderIcon(
+ "Submitting request to " + dmInputParameters.getChartType().getTitle() + " Analysis...");
+ loaderIcon.setVisible(true);
+ panelContainer.setVisible(true);
+ panelContainer.add(loaderIcon);
+ Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
+ @Override
+ public void execute() {
+ loaderIcon.setFocus(true);
+ }
+ });
+
+ PerformFishAnalyticsServiceAsync.Util.getInstance().callingDataMinerPerformFishAnnualAnalysis(mapParameters,
+ new AsyncCallback() {
+
+ @Override
+ public void onSuccess(DataMinerResponse dmResponse) {
+ loaderIcon.setVisible(false);
+ checkTabSpinner(requestPanel, tab);
+ // field_unary_algorithm.setVisible(true);
+ GWT.log("I'm displaying: " + dmResponse);
+ displayOutputFilesAsStaticEntities(dmResponse, dmInputParameters.getChartType(),
+ dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
+ dmInputParameters.getFocusID(), panelContainer, false, oIteration);
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ loaderIcon.setVisible(false);
+ checkTabSpinner(requestPanel, tab);
+ displayOutputFilesAsStaticEntities(null, dmInputParameters.getChartType(),
+ dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
+ dmInputParameters.getFocusID(), panelContainer, true, oIteration);
+
+ }
+ });
+ }
+
+ /**
+ * Append DM input table.
+ *
+ * @param performFishResponseMap
+ * the perform fish response map
+ * @param dataInputsFormatter
+ * the data inputs formatter
+ * @param table
+ * the table
+ * @return the string builder
+ */
+ private StringBuilder appendDMInputTable(Map performFishResponseMap,
+ StringBuilder dataInputsFormatter, PFSERVICE_TO_DM_MAPPING_TABLE table) {
+
+ String toDMInputTable = performFishResponseMap.get(table.getPerformFishTable());
+
+ if (toDMInputTable != null && !toDMInputTable.isEmpty()) {
+ dataInputsFormatter.append(table.getDataMinerTable() + "=" + toDMInputTable + ";");
+ }
+
+ return dataInputsFormatter;
+ }
+
+ private String getOutputId(int oIteration, String title) {
+ String outputId = "OutputId_" + requestId + "_" + oIteration + "_" + 1;
+ return outputId;
+
+ }
+
+ private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
+ final DataMinerAlgorithms chartType, List inputKPIs, List outputKPIs, final String focusID,
+ final Panel container, boolean displayError, final int oIteration) {
+
+ String title = displayError ? "No results " : "";
+
+ if (displayError) {
+ Alert alert = new Alert(title);
+ alert.setType(AlertType.ERROR);
+ alert.setClose(false);
+ alert.getElement().getStyle().setMargin(10, Unit.PX);
+ container.add(alert);
+ return;
+ }
+
+ savePDFButton.setVisible(true);
+
+ final String toTitle = title;
+
+ for (OutputFile outputFile : dmResponse.getListOutput()) {
+
+ final FileContentType fileContentType = outputFile.getDataType();
+
+ switch (outputFile.getDataType()) {
+ case IMAGE:
+ PerformFishAnalyticsServiceAsync.Util.getInstance().getImageFile(outputFile,
+ new AsyncCallback() {
+
+ @Override
+ public void onFailure(Throwable caught) {
+ // showAlert(caught.getMessage(),
+ // AlertType.ERROR, true,
+ // uib_vp_deanalanlysis_request_container);
+ Window.alert(caught.getMessage());
+
+ }
+
+ @Override
+ public void onSuccess(String base64Content) {
+ String title = toTitle;
+
+ String outputId = getOutputId(oIteration, title);
+ ShowResult showResult = new ShowResult(outputId, title, fileContentType);
+ showResult.showImage(base64Content);
+ container.add(showResult);
+
+ }
+ });
+ break;
+ case CSV:
+ PerformFishAnalyticsServiceAsync.Util.getInstance().getCSVFile(outputFile, true,
+ new AsyncCallback() {
+
+ @Override
+ public void onFailure(Throwable caught) {
+ // showAlert(caught.getMessage(),
+ // AlertType.ERROR, true,
+ // uib_vp_deanalanlysis_request_container);
+ Window.alert(caught.getMessage());
+ }
+
+ @Override
+ public void onSuccess(CSVFile result) {
+ GWT.log("Displaying: " + result);
+
+ String cssTableStyle = "simpletable";
+
+ String title = toTitle;
+
+ String outputId = getOutputId(oIteration, title);
+ ShowResult showResult = new ShowResult(outputId, title, fileContentType);
+ showResult.showCSVFile(result, cssTableStyle);
+ container.add(showResult);
+ }
+ });
+ break;
+
+ default:
+ break;
+ }
+
+ }
+
+ }
+
+ /**
+ * Remove the spinner if all DM responses are returned.
+ *
+ * @param requestPanel
+ * the request panel
+ * @param tab
+ * the tab
+ */
+ private void checkTabSpinner(SubmitRequestPanel requestPanel, Tab tab) {
+ requestPanel.incrementCompletedRequests();
+ int completed = requestPanel.getCompletedRequests();
+ int total = requestPanel.getTotalRequests();
+
+ if (completed >= total) {
+ viewAnnualController.noSpinner(tab);
+ }
+ }
+
+ private static native void saveFilePDF(String chartType, String filename, String tabTitle, String tabDescr,
+ int requestId, int outputIteration, int outputNumber)/*-{
+ var that = this;
+ console.log('saveFilePDF()');
+ console.log('requestId: ' + requestId);
+ console.log('OutputIteration: ' + outputIteration);
+ console.log('OutputNumber:' + outputNumber);
+
+ var tTitle = tabTitle;
+ var tDescr = tabDescr;
+
+ var pdoc = new jsPDF("p", "mm", "a4");
+ pdoc.setProperties({
+ title : 'PerformFish ' + tTitle,
+ subject : ' Results',
+ author : 'PerformFish',
+ keywords : 'PerformFish',
+ creator : 'D4Science'
+ });
+
+ var lMargin = 15; //left margin in mm
+ var rMargin = 15; //right margin in mm
+ var tMargin = 15; //top margin in mm
+ var bMargin = 15; //bottom margin in mm
+ var pdfWidthInMM = 210; // width of A4 in mm
+ var pdfHeightInMM = 297; // height of A4 in mm
+ var pageCenter = pdfWidthInMM / 2;
+
+ pdoc.setFontSize(24);
+ var title = "PerformFish " + tTitle;
+ var titleHeight = pdoc.getLineHeight(title) / pdoc.internal.scaleFactor;
+ var xPos = lMargin;
+ var yPos = tMargin;
+ pdoc.text(title, pageCenter, yPos, 'center');
+ yPos += titleHeight;
+
+ pdoc.setFontSize(10);
+ var lineHeight = pdoc.getLineHeight(tDescr) / pdoc.internal.scaleFactor;
+ var splittedAnalysisDescription = pdoc.splitTextToSize(tDescr,
+ (pdfWidthInMM - lMargin - rMargin));
+ var lines = splittedAnalysisDescription.length;// splitted text is a string array
+ var analysisDescriptionHeight = lines * lineHeight;
+
+ pdoc.text(splittedAnalysisDescription, xPos, yPos, 'left');
+ yPos += analysisDescriptionHeight;
+
+ //yPos += 2;
+ //pdoc.text("Analysis:", xPos, yPos, 'left');
+ yPos += 6;
+
+ for (var i = 1; i <= outputIteration; i++) {
+
+ var kpiId = 'KPI_ScatterAnnual_' + requestId + '_' + i;
+ console.log('kpiId: ' + kpiId);
+
+ var kpiName = $doc.getElementById(kpiId);
+
+ yPos += 2;
+ pdoc.setFontSize(14);
+ pdoc.setFontType("bold");
+
+ var kpiText = kpiName.textContent;
+ var kpiHeight = pdoc.getLineHeight(kpiText)
+ / pdoc.internal.scaleFactor;
+ var splittedKpiName = pdoc.splitTextToSize(kpiText, (pdfWidthInMM
+ - lMargin - rMargin));
+ var kpiLines = splittedKpiName.length; // splitted text is a string array
+ var kpiLinesHeight = kpiLines * kpiHeight;
+ pdoc.text(splittedKpiName, xPos, yPos, 'left');
+ yPos += kpiLinesHeight;
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
+ for (var j = 1; j <= outputNumber; j++) {
+
+ var outputId = 'OutputId_' + requestId + '_' + i + '_' + j;
+ console.log('OutputId: ' + outputId);
+
+ var resultOutputNumber = $doc.getElementById(outputId);
+
+ console.log('OutputId_: ' + resultOutputNumber.innerHTML);
+ var resultType = resultOutputNumber.className;
+
+ console.log('resultOutputNumber className: ' + resultType);
+
+ if (typeof resultType !== 'undefined' && resultType !== null
+ && resultType !== '') {
+
+ if (resultType == 'csv') {
+ console.log('Result Type csv: ' + i);
+ // foo could get resolved and it's defined
+
+ var childrenTable = resultOutputNumber.children;
+ var titleCurrentTable = childrenTable[0].rows[0].cells[0];
+ console.log('Title current table: '
+ + titleCurrentTable.textContent);
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text(titleCurrentTable.textContent, xPos, yPos,
+ 'left');
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
+ var secondDiv = childrenTable[0].rows[1].cells[0];
+ var secondTable = secondDiv.children[0].children[0];
+
+ console.log('CSV SecondTable: ' + secondTable);
+
+ pdoc.autoTable({
+ theme : 'grid',
+ startY : yPos,
+ pageBreak : 'auto',
+ bodyStyles : {
+ fontSize : 9
+ },
+ html : secondTable
+ });
+
+ yPos = pdoc.previousAutoTable.finalY + 6;
+ } else {
+ if (resultType == 'image') {
+ console.log('Result Type image: ' + i);
+ var childrenTable = resultOutputNumber.children;
+
+ var titleCurrentImage = childrenTable[0].rows[0].cells[0];
+ console.log('Title current image: '
+ + titleCurrentImage.textContent);
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text(titleCurrentImage.textContent, xPos,
+ yPos, 'left');
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
+ var secondDiv = childrenTable[0].rows[1].cells[0];
+ var imageElement = secondDiv.getElementsByTagName(
+ 'img').item(0);
+ console.log('Image element: ' + imageElement);
+ pdoc.addImage(imageElement, lMargin, yPos);
+ console.log('Image Height: ' + imageElement.height);
+ yPos += (imageElement.height * 0.26458333);
+
+ } else {
+ console.log('Result Type unknow: ' + i);
+ }
+
+ }
+ } else {
+ console.log('Result Type is undefined:' + i);
+ }
+
+ }
+
+ if (i == outputNumber) {
+
+ } else {
+ if (pdfHeightInMM - yPos < pdfHeightInMM / 4) {
+ pdoc.addPage();
+ yPos = tMargin; // Restart position
+ }
+ }
+
+ }
+
+ var numberOfPages=pdoc.internal.getNumberOfPages()
+ console.log('NumberOfPages: ' + numberOfPages);
+ for (var k = 1; k <= numberOfPages; k++) {
+ pdoc.setPage(k);
+ console.log('CurrentPage: ' + k);
+ var footner = 'Page ' + k + "/"+numberOfPages;
+ pdoc.text(footner, pageCenter, pdfHeightInMM - 7, 'center');
+
+ }
+
+ console.log('Done');
+
+ pdoc.save(filename);
+
+ }-*/;
+}
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/SpeedometerAnnualPanelResult.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/SpeedometerAnnualPanelResult.java
new file mode 100644
index 0000000..575835e
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/SpeedometerAnnualPanelResult.java
@@ -0,0 +1,578 @@
+package org.gcube.portlets.user.performfishanalytics.client.viewannualbinder;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.gcube.portlets.user.performfishanalytics.client.DataMinerAlgorithms;
+import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant;
+import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE;
+import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync;
+import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.DataMinerInputParameters;
+import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.PerformFishAnnualAnalyticsViewController;
+import org.gcube.portlets.user.performfishanalytics.client.resources.PerformFishResources;
+import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon;
+import org.gcube.portlets.user.performfishanalytics.client.viewbinder.ShowResult;
+import org.gcube.portlets.user.performfishanalytics.client.viewbinder.SubmitRequestPanel;
+import org.gcube.portlets.user.performfishanalytics.shared.FileContentType;
+import org.gcube.portlets.user.performfishanalytics.shared.KPI;
+import org.gcube.portlets.user.performfishanalytics.shared.OutputFile;
+import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile;
+import org.gcube.portlets.user.performfishanalytics.shared.dataminer.DataMinerResponse;
+import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse;
+
+import com.github.gwtbootstrap.client.ui.Alert;
+import com.github.gwtbootstrap.client.ui.Button;
+import com.github.gwtbootstrap.client.ui.Tab;
+import com.github.gwtbootstrap.client.ui.constants.AlertType;
+import com.github.gwtbootstrap.client.ui.constants.IconType;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.shared.GWT;
+import com.google.gwt.dom.client.Style.Unit;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.resources.client.TextResource;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.ComplexPanel;
+import com.google.gwt.user.client.ui.FlexTable;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Panel;
+
+public class SpeedometerAnnualPanelResult {
+
+ private Map boxPlotOrderBy = new HashMap();
+
+ private PerformFishAnnualAnalyticsViewController viewAnnualController;
+ private int requestId = 0;
+ private int outputIteration = 0;
+ private int outputNumber = 1;
+
+ private Button savePDFButton;
+
+ public SpeedometerAnnualPanelResult(int reqId, PerformFishAnnualAnalyticsViewController viewAnnualController,
+ PerformFishResponse thePerformFishResponse, final DataMinerAlgorithms algorithm, String focusID,
+ List inputKPI, final List outputKPI) {
+ GWT.log("RequestID: " + reqId);
+ requestId = reqId;
+ this.viewAnnualController = viewAnnualController;
+ TextResource algDescr = PerformFishResources.INSTANCE.farm_SPEEDOMETER();
+
+ String algDesrTxt = algDescr != null ? algDescr.getText() : null;
+
+ // TODO
+ final String tabTitle = algorithm.getTitle();
+ final String tabDescr = algDesrTxt;
+
+ final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
+ Tab tab = viewAnnualController.createTab(tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1),
+ algDesrTxt, submitRequestPanel);
+
+ HorizontalPanel res = new HorizontalPanel();
+
+ savePDFButton = new Button();
+ savePDFButton.getElement().getStyle().setMargin(10, Unit.PX);
+ savePDFButton.setIcon(IconType.PRINT);
+ savePDFButton.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+ saveFilePDF(algorithm.getId(), tabTitle, tabTitle, tabDescr, requestId, outputIteration, outputNumber);
+ // dmResponse.getListOutput().size()
+ }
+ });
+ savePDFButton.setVisible(false);
+
+ res.add(savePDFButton);
+ submitRequestPanel.addWidget(res);
+ int oIteration = 0;
+
+ submitRequestPanel.setTotalRequests(inputKPI.size());
+ for (KPI kpi : inputKPI) {
+ oIteration++;
+ String title = "KPI: " + kpi.getName();
+ HTML toBigTitle = new HTML(title);
+ toBigTitle.getElement().setId("KPI_SpeedometerAnnual_" + requestId + "_" + oIteration);
+ toBigTitle.getElement().addClassName("to-big-title");
+ submitRequestPanel.addWidget(toBigTitle);
+ HorizontalPanel hp = new HorizontalPanel();
+ hp.getElement().addClassName("ext-horizontal-panel");
+
+ DataMinerInputParameters dmInputParams = new DataMinerInputParameters(thePerformFishResponse,
+ viewAnnualController.getSelectedYears(), Arrays.asList(kpi), null, algorithm, focusID);
+ callDataMinerServiceForChart(dmInputParams, submitRequestPanel, hp, tab, oIteration);
+ // resultPanel.add(hp);
+ submitRequestPanel.addWidget(hp);
+ }
+ outputIteration = oIteration;
+
+ }
+
+ /**
+ * Call data miner service for chart.
+ *
+ * @param dmInputParameters
+ * the dm input parameters
+ * @param requestPanel
+ * the request panel
+ * @param panelContainer
+ * the panel
+ * @param tab
+ * the tab
+ * @param tabDescr
+ * @param tabTitle
+ */
+ private void callDataMinerServiceForChart(final DataMinerInputParameters dmInputParameters,
+ final SubmitRequestPanel requestPanel, final ComplexPanel panelContainer, final Tab tab,
+ final int oIteration) {
+
+ GWT.log("Building DM request with input parameters: " + dmInputParameters);
+
+ StringBuilder dataInputsFormatter = new StringBuilder();
+ dataInputsFormatter
+ .append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM + "=" + dmInputParameters.getChartType() + ";");
+
+ String yearsValue = "";
+ for (String year : dmInputParameters.getSelectedYears()) {
+ yearsValue += year + "|";
+ }
+ yearsValue = yearsValue.substring(0, yearsValue.length() - 1);
+
+ dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_YEARS_PARAM + "=" + yearsValue + ";");
+ dataInputsFormatter
+ .append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM + "=" + dmInputParameters.getFocusID() + ";");
+ // dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM+"=ID;");
+
+ if (dmInputParameters.getInputKPI() != null && dmInputParameters.getInputKPI().size() > 0) {
+ String kpiCodes = "";
+ for (KPI kpi : dmInputParameters.getInputKPI()) {
+ kpiCodes += kpi.getCode() + "|";
+ }
+ // remove last |
+ kpiCodes = kpiCodes.substring(0, kpiCodes.length() - 1);
+
+ GWT.log("Input KPICodes: " + kpiCodes);
+ // ADDING KPIs code
+ dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_INPUT_KPI_PARAM + "=" + kpiCodes + ";");
+
+ }
+
+ if (dmInputParameters.getOutputKPI() != null && dmInputParameters.getOutputKPI().size() > 0) {
+ String kpiCodes = "";
+ for (KPI kpi : dmInputParameters.getOutputKPI()) {
+ kpiCodes += kpi.getCode() + "|";
+ }
+ // remove last |
+ kpiCodes = kpiCodes.substring(0, kpiCodes.length() - 1);
+
+ GWT.log("Output KPICodes: " + kpiCodes);
+ // ADDING KPIs code
+ dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_OUTPUT_KPI_PARAM + "=" + kpiCodes + ";");
+ }
+
+ Map performFishResponseMap = dmInputParameters.getPerformFishResponse().getMapParameters();
+
+ dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
+ PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.LethalIncidentsTable);
+ dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
+ PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AnnualTable);
+ dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
+ PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntibioticsTable);
+ dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
+ PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntiparasiticTable);
+
+ String dataInParameters = dataInputsFormatter.toString();
+ GWT.log("Calling DM service with client input parameters: " + dataInParameters);
+
+ Map> mapParameters = new HashMap>();
+ mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters));
+
+ final LoaderIcon loaderIcon = new LoaderIcon(
+ "Submitting request to " + dmInputParameters.getChartType().getTitle() + " Analysis...");
+ loaderIcon.setVisible(true);
+ panelContainer.setVisible(true);
+ panelContainer.add(loaderIcon);
+ Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
+ @Override
+ public void execute() {
+ loaderIcon.setFocus(true);
+ }
+ });
+
+ PerformFishAnalyticsServiceAsync.Util.getInstance().callingDataMinerPerformFishAnnualAnalysis(mapParameters,
+ new AsyncCallback() {
+
+ @Override
+ public void onSuccess(DataMinerResponse dmResponse) {
+ loaderIcon.setVisible(false);
+ checkTabSpinner(requestPanel, tab);
+ // field_unary_algorithm.setVisible(true);
+ GWT.log("I'm displaying: " + dmResponse);
+ displayOutputFilesAsStaticEntities(dmResponse, dmInputParameters.getChartType(),
+ dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
+ dmInputParameters.getFocusID(), panelContainer, false, oIteration);
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ loaderIcon.setVisible(false);
+ checkTabSpinner(requestPanel, tab);
+ displayOutputFilesAsStaticEntities(null, dmInputParameters.getChartType(),
+ dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
+ dmInputParameters.getFocusID(), panelContainer, true, oIteration);
+
+ }
+ });
+ }
+
+ /**
+ * Append DM input table.
+ *
+ * @param performFishResponseMap
+ * the perform fish response map
+ * @param dataInputsFormatter
+ * the data inputs formatter
+ * @param table
+ * the table
+ * @return the string builder
+ */
+ private StringBuilder appendDMInputTable(Map performFishResponseMap,
+ StringBuilder dataInputsFormatter, PFSERVICE_TO_DM_MAPPING_TABLE table) {
+
+ String toDMInputTable = performFishResponseMap.get(table.getPerformFishTable());
+
+ if (toDMInputTable != null && !toDMInputTable.isEmpty()) {
+ dataInputsFormatter.append(table.getDataMinerTable() + "=" + toDMInputTable + ";");
+ }
+
+ return dataInputsFormatter;
+ }
+
+ private String getOutputId(int oIteration, String title) {
+ String outputId = "OutputId_" + requestId + "_" + oIteration + "_" + 1;
+ return outputId;
+
+ }
+
+ private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
+ final DataMinerAlgorithms chartType, List inputKPIs, List outputKPIs, final String focusID,
+ final Panel container, boolean displayError, final int oIteration) {
+
+ String title = displayError ? "No results " : "";
+
+ if (displayError) {
+ Alert alert = new Alert(title);
+ alert.setType(AlertType.ERROR);
+ alert.setClose(false);
+ alert.getElement().getStyle().setMargin(10, Unit.PX);
+ container.add(alert);
+ return;
+ }
+
+ savePDFButton.setVisible(true);
+
+ final String toTitle = title;
+
+ for (OutputFile outputFile : dmResponse.getListOutput()) {
+ final FileContentType fileContentType = outputFile.getDataType();
+
+ switch (outputFile.getDataType()) {
+ case IMAGE:
+ PerformFishAnalyticsServiceAsync.Util.getInstance().getImageFile(outputFile,
+ new AsyncCallback() {
+
+ @Override
+ public void onFailure(Throwable caught) {
+ // showAlert(caught.getMessage(),
+ // AlertType.ERROR, true,
+ // uib_vp_deanalanlysis_request_container);
+ Window.alert(caught.getMessage());
+
+ }
+
+ @Override
+ public void onSuccess(String base64Content) {
+
+ String title = toTitle;
+
+ title = chartType.getTitle() + "
";
+ title += "Selected Farm: " + focusID + "
";
+ title += "Normalized with respect to all farm data in the VRE";
+
+ String outputId = getOutputId(oIteration, title);
+ ShowResult showResult = new ShowResult(outputId, title, fileContentType);
+ showResult.showImage(base64Content);
+ container.add(showResult);
+
+ }
+ });
+ break;
+ case CSV:
+ PerformFishAnalyticsServiceAsync.Util.getInstance().getCSVFile(outputFile, true,
+ new AsyncCallback() {
+
+ @Override
+ public void onFailure(Throwable caught) {
+ // showAlert(caught.getMessage(),
+ // AlertType.ERROR, true,
+ // uib_vp_deanalanlysis_request_container);
+ Window.alert(caught.getMessage());
+ }
+
+ @Override
+ public void onSuccess(CSVFile result) {
+ GWT.log("Displaying: " + result);
+
+ String cssTableStyle = "simpletable";
+
+ String title = toTitle;
+
+ String outputId = getOutputId(oIteration, title);
+ ShowResult showResult = new ShowResult(outputId, title, fileContentType);
+ showResult.showCSVFile(result, cssTableStyle);
+ container.add(showResult);
+
+ }
+ });
+ break;
+
+ default:
+ break;
+ }
+
+ }
+
+ }
+
+ private void displayingOrderedBoxPlot(final DataMinerResponse dmResponse, String title, final Panel container,
+ ShowResult showResult) {
+ int hashcode = dmResponse.hashCode();
+ GWT.log("The hascode is: " + hashcode);
+ FlexTable flex = boxPlotOrderBy.get(hashcode);
+
+ if (flex == null) {
+ GWT.log("The flextable is null");
+ flex = new FlexTable();
+ boxPlotOrderBy.put(hashcode, flex);
+ container.add(flex);
+ }
+
+ if (title.startsWith("My")) {
+ flex.setWidget(0, 0, showResult);
+ } else if (title.startsWith("All")) {
+ flex.setWidget(0, 1, showResult);
+ } else {
+ flex.setWidget(0, 2, showResult);
+ }
+ }
+
+ /**
+ * Remove the spinner if all DM responses are returned.
+ *
+ * @param requestPanel
+ * the request panel
+ * @param tab
+ * the tab
+ */
+ private void checkTabSpinner(SubmitRequestPanel requestPanel, Tab tab) {
+ requestPanel.incrementCompletedRequests();
+ int completed = requestPanel.getCompletedRequests();
+ int total = requestPanel.getTotalRequests();
+
+ if (completed >= total) {
+ viewAnnualController.noSpinner(tab);
+ }
+ }
+
+ private static native void saveFilePDF(String chartType, String filename, String tabTitle, String tabDescr,
+ int requestId, int outputIteration, int outputNumber)/*-{
+ var that = this;
+ console.log('saveFilePDF()');
+ console.log('requestId: ' + requestId);
+ console.log('OutputIteration: ' + outputIteration);
+ console.log('OutputNumber:' + outputNumber);
+
+ var tTitle = tabTitle;
+ var tDescr = tabDescr;
+
+ var pdoc = new jsPDF("p", "mm", "a4");
+ pdoc.setProperties({
+ title : 'PerformFish ' + tTitle,
+ subject : ' Results',
+ author : 'PerformFish',
+ keywords : 'PerformFish',
+ creator : 'D4Science'
+ });
+
+ var lMargin = 15; //left margin in mm
+ var rMargin = 15; //right margin in mm
+ var tMargin = 15; //top margin in mm
+ var bMargin = 15; //bottom margin in mm
+ var pdfWidthInMM = 210; // width of A4 in mm
+ var pdfHeightInMM = 297; // height of A4 in mm
+ var pageCenter = pdfWidthInMM / 2;
+
+ pdoc.setFontSize(24);
+ var title = "PerformFish " + tTitle;
+ var titleHeight = pdoc.getLineHeight(title) / pdoc.internal.scaleFactor
+ var xPos = lMargin;
+ var yPos = tMargin;
+ pdoc.text(title, pageCenter, yPos, 'center');
+ yPos += titleHeight;
+
+ pdoc.setFontSize(10);
+ var lineHeight = pdoc.getLineHeight(tDescr) / pdoc.internal.scaleFactor
+ var splittedAnalysisDescription = pdoc.splitTextToSize(tDescr,
+ (pdfWidthInMM - lMargin - rMargin));
+ var lines = splittedAnalysisDescription.length // splitted text is a string array
+ var analysisDescriptionHeight = lines * lineHeight
+
+ pdoc.text(splittedAnalysisDescription, xPos, yPos, 'left');
+ yPos += analysisDescriptionHeight;
+
+ //yPos += 2;
+ //pdoc.text("Analysis:", xPos, yPos, 'left');
+ yPos += 6;
+
+ for (var i = 1; i <= outputIteration; i++) {
+
+ var kpiId = 'KPI_SpeedometerAnnual_' + requestId + '_' + i;
+ console.log('kpiId: ' + kpiId);
+
+ var kpiName = $doc.getElementById(kpiId);
+
+ yPos += 2;
+ pdoc.setFontSize(14);
+ pdoc.setFontType("bold");
+
+ var kpiText = kpiName.textContent;
+ var kpiHeight = pdoc.getLineHeight(kpiText)
+ / pdoc.internal.scaleFactor;
+ var splittedKpiName = pdoc.splitTextToSize(kpiText, (pdfWidthInMM
+ - lMargin - rMargin));
+ var kpiLines = splittedKpiName.length; // splitted text is a string array
+ var kpiLinesHeight = kpiLines * kpiHeight;
+ pdoc.text(splittedKpiName, xPos, yPos, 'left');
+ yPos += kpiLinesHeight;
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
+
+ for (var j = 1; j <= outputNumber; j++) {
+
+ var outputId = 'OutputId_' + requestId + '_' + i + '_' + j;
+ console.log('OutputId: ' + outputId);
+
+ var resultOutputNumber = $doc.getElementById(outputId);
+
+ console.log('OutputId_: ' + resultOutputNumber.innerHTML);
+ var resultType = resultOutputNumber.className;
+
+ console.log('resultOutputNumber className: ' + resultType);
+
+ if (typeof resultType !== 'undefined' && resultType !== null
+ && resultType !== '') {
+
+ if (resultType == 'csv') {
+ console.log('Result Type csv: ' + i);
+ // foo could get resolved and it's defined
+
+ var childrenTable = resultOutputNumber.children;
+ var titleCurrentTable = childrenTable[0].rows[0].cells[0];
+ console.log('Title current table: '
+ + titleCurrentTable.textContent);
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text(titleCurrentTable.textContent, xPos, yPos,
+ 'left');
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
+ var secondDiv = childrenTable[0].rows[1].cells[0];
+ var secondTable = secondDiv.children[0].children[0];
+
+ console.log('CSV SecondTable: ' + secondTable);
+
+ pdoc.autoTable({
+ theme : 'grid',
+ startY : yPos,
+ pageBreak : 'auto',
+ bodyStyles : {
+ fontSize : 9
+ },
+ html : secondTable
+ });
+
+ yPos = pdoc.previousAutoTable.finalY + 6;
+ } else {
+ if (resultType == 'image') {
+ console.log('Result Type image: ' + i);
+ var childrenTable = resultOutputNumber.children;
+
+ var titleCurrentImage = childrenTable[0].rows[0].cells[0];
+ console.log('Title current image: '
+ + titleCurrentImage.textContent);
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text(titleCurrentImage.textContent, xPos,
+ yPos, 'left');
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
+ var secondDiv = childrenTable[0].rows[1].cells[0];
+ var imageElement = secondDiv.getElementsByTagName(
+ 'img').item(0);
+ console.log('Image element: ' + imageElement);
+ pdoc.addImage(imageElement, lMargin, yPos);
+ console.log('Image Height: ' + imageElement.height);
+ yPos += (imageElement.height * 0.26458333);
+
+ } else {
+ console.log('Result Type unknow: ' + i);
+ }
+
+ }
+ } else {
+ console.log('Result Type is undefined:' + i);
+ }
+
+ }
+
+ if (i == outputNumber) {
+
+ } else {
+ if (pdfHeightInMM - yPos < pdfHeightInMM / 4) {
+ pdoc.addPage();
+ yPos = tMargin; // Restart position
+ }
+ }
+
+ }
+
+ var numberOfPages=pdoc.internal.getNumberOfPages()
+ console.log('NumberOfPages: ' + numberOfPages);
+ for (var k = 1; k <= numberOfPages; k++) {
+ pdoc.setPage(k);
+ console.log('CurrentPage: ' + k);
+ var footner = 'Page ' + k + "/"+numberOfPages;
+ pdoc.text(footner, pageCenter, pdfHeightInMM - 7, 'center');
+
+ }
+
+ console.log('Done');
+
+ pdoc.save(filename);
+
+ }-*/;
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/SynopticTableAnnualPanelResult.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/SynopticTableAnnualPanelResult.java
new file mode 100644
index 0000000..75c1b37
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/SynopticTableAnnualPanelResult.java
@@ -0,0 +1,561 @@
+package org.gcube.portlets.user.performfishanalytics.client.viewannualbinder;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.gcube.portlets.user.performfishanalytics.client.DataMinerAlgorithms;
+import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant;
+import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE;
+import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync;
+import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.PerformFishAnnualAnalyticsViewController;
+import org.gcube.portlets.user.performfishanalytics.client.resources.PerformFishResources;
+import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon;
+import org.gcube.portlets.user.performfishanalytics.client.viewbinder.ShowResult;
+import org.gcube.portlets.user.performfishanalytics.client.viewbinder.SubmitRequestPanel;
+import org.gcube.portlets.user.performfishanalytics.shared.FileContentType;
+import org.gcube.portlets.user.performfishanalytics.shared.KPI;
+import org.gcube.portlets.user.performfishanalytics.shared.OutputFile;
+import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile;
+import org.gcube.portlets.user.performfishanalytics.shared.dataminer.DataMinerResponse;
+import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse;
+
+import com.github.gwtbootstrap.client.ui.Alert;
+import com.github.gwtbootstrap.client.ui.Button;
+import com.github.gwtbootstrap.client.ui.Tab;
+import com.github.gwtbootstrap.client.ui.constants.AlertType;
+import com.github.gwtbootstrap.client.ui.constants.IconType;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.shared.GWT;
+import com.google.gwt.dom.client.Style.Unit;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.FlexTable;
+import com.google.gwt.user.client.ui.HTMLPanel;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Panel;
+
+public class SynopticTableAnnualPanelResult {
+
+ private Map synopticOrderBy = new HashMap();
+
+ private PerformFishAnnualAnalyticsViewController viewAnnualController;
+ private int requestId;
+ private int outputIteration = 1;
+ private int outputNumber = 0;
+
+ private Button savePDFButton;
+
+ public SynopticTableAnnualPanelResult(int reqId, PerformFishAnnualAnalyticsViewController viewAnnualController,
+ PerformFishResponse performFishResponse) {
+ GWT.log("RequestID: " + reqId);
+ requestId = reqId;
+ this.viewAnnualController = viewAnnualController;
+
+ final DataMinerAlgorithms algorithm = DataMinerAlgorithms.PERFORMFISH_SYNOPTIC_TABLE_FARM;
+ final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
+ final String tabTitle = "Synoptic Table";
+ final String tabDescr = PerformFishResources.INSTANCE.synopticTable().getText();
+ final Tab tab = viewAnnualController.createTab(
+ tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1), tabDescr, submitRequestPanel);
+
+ // TODO
+ HorizontalPanel res = new HorizontalPanel();
+
+ savePDFButton = new Button();
+ savePDFButton.getElement().getStyle().setMargin(10, Unit.PX);
+ savePDFButton.setIcon(IconType.PRINT);
+ savePDFButton.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+ saveFilePDF(algorithm.getId(), tabTitle, tabTitle, tabDescr, requestId, outputIteration, outputNumber);
+ // dmResponse.getListOutput().size()
+ }
+ });
+ savePDFButton.setVisible(false);
+
+ res.add(savePDFButton);
+ submitRequestPanel.addWidget(res);
+
+ StringBuilder dataInputsFormatter = new StringBuilder();
+ Map performFishResponseMap = performFishResponse.getMapParameters();
+ dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
+ PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.LethalIncidentsTable);
+ dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
+ PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AnnualTable);
+ dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
+ PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntibioticsTable);
+ dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
+ PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntiparasiticTable);
+
+ String yearsValue = "";
+ for (String year : viewAnnualController.getSelectedYears()) {
+ yearsValue += year + "#";
+ }
+ yearsValue = yearsValue.substring(0, yearsValue.length() - 1);
+
+ dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_ALLYEARS_PARAM + "=" + yearsValue + ";");
+
+ String dataInParameters = dataInputsFormatter.toString();
+ GWT.log("Calling DM service with client input parameters: " + dataInParameters);
+
+ Map> mapParameters = new HashMap>();
+ mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters));
+
+ final HTMLPanel panelContainer = submitRequestPanel.getContainerPanel();
+ final LoaderIcon loaderIcon = new LoaderIcon("Submitting request to " + algorithm.getTitle() + "...");
+ loaderIcon.setVisible(true);
+ panelContainer.setVisible(true);
+ panelContainer.add(loaderIcon);
+ Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
+ @Override
+ public void execute() {
+ loaderIcon.setFocus(true);
+ }
+ });
+
+ PerformFishAnalyticsServiceAsync.Util.getInstance().callDMServiceToLoadSynopticAnnualTable(performFishResponse,
+ mapParameters, new AsyncCallback() {
+
+ @Override
+ public void onSuccess(DataMinerResponse dmResponse) {
+ loaderIcon.setVisible(false);
+ checkTabSpinner(submitRequestPanel, tab);
+ // field_unary_algorithm.setVisible(true);
+ GWT.log("I'm displaying: " + dmResponse);
+ displayOutputFilesAsStaticEntities(dmResponse, algorithm, null, null, null, panelContainer,
+ false, outputIteration);
+ }
+
+ @Override
+ public void onFailure(Throwable caught) {
+ loaderIcon.setVisible(false);
+ checkTabSpinner(submitRequestPanel, tab);
+ displayOutputFilesAsStaticEntities(null, algorithm, null, null, null, panelContainer, true,
+ outputIteration);
+
+ }
+ });
+
+ }
+
+ /**
+ * Append DM input table.
+ *
+ * @param performFishResponseMap
+ * the perform fish response map
+ * @param dataInputsFormatter
+ * the data inputs formatter
+ * @param table
+ * the table
+ * @return the string builder
+ */
+ private StringBuilder appendDMInputTable(Map performFishResponseMap,
+ StringBuilder dataInputsFormatter, PFSERVICE_TO_DM_MAPPING_TABLE table) {
+
+ String toDMInputTable = performFishResponseMap.get(table.getPerformFishTable());
+
+ if (toDMInputTable != null && !toDMInputTable.isEmpty()) {
+ dataInputsFormatter.append(table.getDataMinerTable() + "=" + toDMInputTable + ";");
+ }
+
+ return dataInputsFormatter;
+ }
+
+ /**
+ *
+ *
+ *
+ * Remove the spinner if all DM responses are returned.
+ *
+ * @param requestPanel
+ * the request panel
+ * @param tab
+ * the tab
+ */
+ private void checkTabSpinner(SubmitRequestPanel requestPanel, Tab tab) {
+ requestPanel.incrementCompletedRequests();
+ int completed = requestPanel.getCompletedRequests();
+ int total = requestPanel.getTotalRequests();
+
+ if (completed >= total) {
+ viewAnnualController.noSpinner(tab);
+ }
+ }
+
+ private String getOutputId(int oIteration, boolean isLegend) {
+ String outputId;
+ if (isLegend) {
+ outputId = "OutputId_" + requestId + "_" + oIteration + "_" + 1;
+ } else {
+ outputNumber++;
+ outputId = "OutputId_" + requestId + "_" + oIteration + "_" + outputNumber;
+ }
+ return outputId;
+ }
+
+ private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
+ final DataMinerAlgorithms chartType, List inputKPIs, List outputKPIs, final String focusID,
+ final Panel container, boolean displayError, final int oIteration) {
+
+ String title = displayError ? "No results " : "";
+
+ if (displayError) {
+ Alert alert = new Alert(title);
+ alert.setType(AlertType.ERROR);
+ alert.setClose(false);
+ alert.getElement().getStyle().setMargin(10, Unit.PX);
+ container.add(alert);
+ return;
+ }
+
+ savePDFButton.setVisible(true);
+
+ final String toTitle = title;
+
+ outputNumber = 1;
+
+ for (OutputFile outputFile : dmResponse.getListOutput()) {
+
+ final FileContentType fileContentType = outputFile.getDataType();
+
+ switch (outputFile.getDataType()) {
+ case IMAGE:
+ PerformFishAnalyticsServiceAsync.Util.getInstance().getImageFile(outputFile,
+ new AsyncCallback() {
+
+ @Override
+ public void onFailure(Throwable caught) {
+ // showAlert(caught.getMessage(),
+ // AlertType.ERROR, true,
+ // uib_vp_deanalanlysis_request_container);
+ Window.alert(caught.getMessage());
+
+ }
+
+ @Override
+ public void onSuccess(String base64Content) {
+
+ String title = toTitle;
+
+ String outputId = getOutputId(oIteration, false);
+ ShowResult showResult = new ShowResult(outputId, title, fileContentType);
+ showResult.showImage(base64Content);
+ container.add(showResult);
+
+ }
+ });
+ break;
+ case CSV:
+ PerformFishAnalyticsServiceAsync.Util.getInstance().getCSVFile(outputFile, true,
+ new AsyncCallback() {
+
+ @Override
+ public void onFailure(Throwable caught) {
+ // showAlert(caught.getMessage(),
+ // AlertType.ERROR, true,
+ // uib_vp_deanalanlysis_request_container);
+ Window.alert(caught.getMessage());
+ }
+
+ @Override
+ public void onSuccess(CSVFile result) {
+ GWT.log("Displaying: " + result);
+
+ String cssTableStyle = "simpletable";
+
+ String title = toTitle;
+ switch (chartType) {
+ case PERFORMFISH_SYNOPTIC_TABLE_FARM:
+ String outputId;
+ if (!result.getFileName().contains("legend")) {
+ cssTableStyle = "synoptictable-farm";
+ outputId = getOutputId(oIteration, false);
+ } else {
+ cssTableStyle = "simpletable-synoptic";
+ outputId = getOutputId(oIteration, true);
+ }
+
+ ShowResult showResultSin = new ShowResult(outputId, title, fileContentType);
+ showResultSin.showCSVFile(result, cssTableStyle);
+ displayingOrderedSynopticTable(dmResponse, result.getFileName(), container,
+ showResultSin);
+ return;
+ case PERFORMFISH_SYNOPTICTABLE_BATCH:
+ break;
+ case PERFORMFISH_SYNOPTICTABLE_BATCH_HATCHERY:
+ break;
+ case PERFORMFISH_SYNOPTICTABLE_BATCH_PREGROW:
+ break;
+ default:
+ break;
+ }
+
+ String outputId = getOutputId(oIteration, false);
+ ShowResult showResult = new ShowResult(outputId, title, fileContentType);
+ showResult.showCSVFile(result, cssTableStyle);
+ container.add(showResult);
+
+ }
+ });
+ break;
+
+ default:
+ break;
+ }
+
+ }
+ }
+
+ private void displayingOrderedSynopticTable(final DataMinerResponse dmResponse, String fileName,
+ final Panel container, ShowResult showResult) {
+ int hashcode = dmResponse.hashCode();
+ GWT.log("The hascode is: " + hashcode);
+ FlexTable flex = synopticOrderBy.get(hashcode);
+
+ if (flex == null) {
+ GWT.log("The flextable is null");
+ flex = new FlexTable();
+ synopticOrderBy.put(hashcode, flex);
+ container.add(flex);
+ }
+
+ if (fileName.toLowerCase().contains("legend")) {
+ flex.setWidget(0, 0, showResult);
+ } else {
+ flex.setWidget(flex.getRowCount() + 1, 0, showResult);
+ }
+ }
+
+ private static native void saveFilePDF(String chartType, String filename, String tabTitle, String tabDescr,
+ int requestId, int outputIteration, int outputNumber)/*-{
+ var that = this;
+ console.log('saveFilePDF()');
+ console.log('requestId: ' + requestId);
+ console.log('OutputIteration: ' + outputIteration);
+ console.log('OutputNumber:' + outputNumber);
+
+ var tTitle = tabTitle;
+ var tDescr = tabDescr;
+
+ var pdoc = new jsPDF("p", "mm", "a4");
+ pdoc.setProperties({
+ title : 'PerformFish ' + tTitle,
+ subject : ' Results',
+ author : 'PerformFish',
+ keywords : 'PerformFish',
+ creator : 'D4Science'
+ });
+
+ var lMargin = 15; //left margin in mm
+ var rMargin = 15; //right margin in mm
+ var tMargin = 15; //top margin in mm
+ var bMargin = 15; //bottom margin in mm
+ var pdfWidthInMM = 210; // width of A4 in mm
+ var pdfHeightInMM = 297; // height of A4 in mm
+ var pageCenter = pdfWidthInMM / 2;
+
+ pdoc.setFontSize(24);
+ var title = "PerformFish " + tTitle;
+ var titleHeight = pdoc.getLineHeight(title) / pdoc.internal.scaleFactor
+ var xPos = lMargin;
+ var yPos = tMargin;
+ pdoc.text(title, pageCenter, yPos, 'center');
+ yPos += titleHeight;
+
+ pdoc.setFontSize(10);
+ var lineHeight = pdoc.getLineHeight(tDescr) / pdoc.internal.scaleFactor
+ var splittedAnalysisDescription = pdoc.splitTextToSize(tDescr,
+ (pdfWidthInMM - lMargin - rMargin));
+ var lines = splittedAnalysisDescription.length // splitted text is a string array
+ var analysisDescriptionHeight = lines * lineHeight
+
+ pdoc.text(splittedAnalysisDescription, xPos, yPos, 'left');
+ yPos += analysisDescriptionHeight;
+
+ //yPos += 2;
+ //pdoc.text("Analysis:", xPos, yPos, 'left');
+ yPos += 6;
+
+ for (var i = 1; i <= outputIteration; i++) {
+
+ for (var j = 1; j <= outputNumber; j++) {
+
+ var outputId = 'OutputId_' + requestId + '_' + i + '_' + j;
+ console.log('OutputId: ' + outputId);
+
+ var resultOutputNumber = $doc.getElementById(outputId);
+
+ console.log('OutputId_: ' + resultOutputNumber.innerHTML);
+ var resultType = resultOutputNumber.className;
+
+ console.log('resultOutputNumber className: ' + resultType);
+
+ if (typeof resultType !== 'undefined' && resultType !== null
+ && resultType !== '') {
+
+ if (resultType == 'csv') {
+ console.log('Result Type csv: ' + i);
+ // foo could get resolved and it's defined
+
+ var childrenTable = resultOutputNumber.children;
+ var titleCurrentTable = childrenTable[0].rows[0].cells[0];
+ console.log('Title current table: '
+ + titleCurrentTable.textContent);
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text(titleCurrentTable.textContent, xPos, yPos,
+ 'left');
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
+ var secondDiv = childrenTable[0].rows[1].cells[0];
+ var secondTable = secondDiv.children[0].children[0];
+
+ console.log('CSV SecondTable: ' + secondTable);
+
+ var checkColor = function(data) {
+ if (data.section === 'body') {
+ console.log(data);
+ var good = '
';
+ var normal = '
';
+ var bad = '
';
+
+ if (typeof data.cell !== 'undefined'
+ && data.cell !== null) {
+ if (typeof data.cell.raw !== 'undefined'
+ && data.cell.raw !== null) {
+
+ console.log(data.cell.raw.innerHTML);
+ if (data.cell.raw.innerHTML === good) {
+ console.log('good');
+ var posIW = (data.cell.x + (data.cell.width / 2)-2);
+ var posIH = (data.cell.y + (data.cell.height / 2)-2);
+ var greenImg = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD//gATQ3JlYXRlZCB3aXRoIEdJTVD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wgARCAAKAAoDAREAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAb/xAAWAQEBAQAAAAAAAAAAAAAAAAAACAn/2gAMAwEAAhADEAAAAbSM8+wB/8QAFBABAAAAAAAAAAAAAAAAAAAAIP/aAAgBAQABBQIf/8QAFBEBAAAAAAAAAAAAAAAAAAAAIP/aAAgBAwEBPwEf/8QAFBEBAAAAAAAAAAAAAAAAAAAAIP/aAAgBAgEBPwEf/8QAFBABAAAAAAAAAAAAAAAAAAAAIP/aAAgBAQAGPwIf/8QAFBABAAAAAAAAAAAAAAAAAAAAIP/aAAgBAQABPyEf/9oADAMBAAIAAwAAABAAD//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQMBAT8QH//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQIBAT8QH//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEAAT8QH//Z'
+ pdoc.addImage(greenImg, 'JPEG', posIW, posIH, 4, 4);
+ //pdoc.setFontSize(10);
+ //pdoc.setFontType("normal");
+ //var posW = (data.cell.x + (data.cell.width / 2));
+ //var posH = (data.cell.y + (data.cell.height / 2));
+ //pdoc.text('G', posW, posH,'center');
+ } else {
+ if (data.cell.raw.innerHTML === normal) {
+ console.log('normal');
+ var posIW = (data.cell.x + (data.cell.width / 2)-2);
+ var posIH = (data.cell.y + (data.cell.height / 2)-2);
+ var yellowImg = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD//gATQ3JlYXRlZCB3aXRoIEdJTVD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wgARCAAKAAoDAREAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAn/xAAWAQEBAQAAAAAAAAAAAAAAAAAABwr/2gAMAwEAAhADEAAAAbEZ/wCqAD//xAAUEAEAAAAAAAAAAAAAAAAAAAAg/9oACAEBAAEFAh//xAAUEQEAAAAAAAAAAAAAAAAAAAAg/9oACAEDAQE/AR//xAAUEQEAAAAAAAAAAAAAAAAAAAAg/9oACAECAQE/AR//xAAUEAEAAAAAAAAAAAAAAAAAAAAg/9oACAEBAAY/Ah//xAAUEAEAAAAAAAAAAAAAAAAAAAAg/9oACAEBAAE/IR//2gAMAwEAAgADAAAAEAAP/8QAFBEBAAAAAAAAAAAAAAAAAAAAIP/aAAgBAwEBPxAf/8QAFBEBAAAAAAAAAAAAAAAAAAAAIP/aAAgBAgEBPxAf/8QAFBABAAAAAAAAAAAAAAAAAAAAIP/aAAgBAQABPxAf/9k='
+ pdoc.addImage(yellowImg, 'JPEG', posIW, posIH, 4, 4);
+ //pdoc.setFontSize(10);
+ //pdoc.setFontType("normal");
+ //var posW = (data.cell.x + (data.cell.width / 2));
+ //var posH = (data.cell.y + (data.cell.height / 2));
+ //pdoc.text('N', posW, posH,'center');
+ } else {
+ if (data.cell.raw.innerHTML === bad) {
+ console.log('bad');
+ var posIW = (data.cell.x + (data.cell.width / 2)-2);
+ var posIH = (data.cell.y + (data.cell.height / 2)-2);
+ var redImg = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD//gATQ3JlYXRlZCB3aXRoIEdJTVD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wgARCAAKAAoDAREAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAj/xAAWAQEBAQAAAAAAAAAAAAAAAAAACAn/2gAMAwEAAhADEAAAAYvlPfwAf//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEAAQUCH//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQMBAT8BH//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQIBAT8BH//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEABj8CH//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEAAT8hH//aAAwDAQACAAMAAAAQAA//xAAUEQEAAAAAAAAAAAAAAAAAAAAg/9oACAEDAQE/EB//xAAUEQEAAAAAAAAAAAAAAAAAAAAg/9oACAECAQE/EB//xAAUEAEAAAAAAAAAAAAAAAAAAAAg/9oACAEBAAE/EB//2Q=='
+ pdoc.addImage(redImg, 'JPEG', posIW, posIH, 4, 4);
+ //pdoc.setFontSize(10);
+ //pdoc.setFontType("normal");
+ //var posW = (data.cell.x + (data.cell.width / 2));
+ //var posH = (data.cell.y + (data.cell.height / 2));
+ //pdoc.text('B', posW, posH,'center');
+ } else {
+
+ }
+
+ }
+
+ }
+ }
+ }
+
+ }
+ };
+
+ pdoc.autoTable({
+ theme : 'grid',
+ startY : yPos,
+ pageBreak : 'auto',
+ bodyStyles : {
+ fontSize : 9
+ },
+ didDrawCell : checkColor,
+ html : secondTable
+ });
+
+ yPos = pdoc.previousAutoTable.finalY + 6;
+ } else {
+ if (resultType == 'image') {
+ console.log('Result Type image: ' + i);
+ var childrenTable = resultOutputNumber.children;
+
+ var titleCurrentImage = childrenTable[0].rows[0].cells[0];
+ console.log('Title current image: '
+ + titleCurrentImage.textContent);
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text(titleCurrentImage.textContent, xPos,
+ yPos, 'left');
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
+ var secondDiv = childrenTable[0].rows[1].cells[0];
+ var imageElement = secondDiv.getElementsByTagName(
+ 'img').item(0);
+ console.log('Image element: ' + imageElement);
+ pdoc.addImage(imageElement, lMargin, yPos);
+ console.log('Image Height: ' + imageElement.height);
+ yPos += (imageElement.height * 0.26458333);
+
+ } else {
+ console.log('Result Type unknow: ' + i);
+ }
+
+ }
+ } else {
+ console.log('Result Type is undefined:' + i);
+ }
+
+ }
+
+ if (i == outputNumber) {
+
+ } else {
+ if (pdfHeightInMM - yPos < pdfHeightInMM / 7) {
+ pdoc.addPage();
+ yPos = tMargin; // Restart position
+ }
+ }
+
+ }
+
+ var numberOfPages = pdoc.internal.getNumberOfPages();
+ console.log('NumberOfPages: ' + numberOfPages);
+ for (var k = 1; k <= numberOfPages; k++) {
+ pdoc.setPage(k);
+ console.log('CurrentPage: ' + k);
+ var footner = 'Page ' + k + "/" + numberOfPages;
+ pdoc.text(footner, pageCenter, pdfHeightInMM - 7, 'center');
+
+ }
+
+ console.log('Done');
+
+ pdoc.save(filename);
+
+ }-*/;
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/AnalyticsPanelResult.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/AnalyticsPanelResult.java
deleted file mode 100644
index c32671a..0000000
--- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/AnalyticsPanelResult.java
+++ /dev/null
@@ -1,588 +0,0 @@
-/**
- *
- */
-package org.gcube.portlets.user.performfishanalytics.client.viewbinder;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.gcube.portlets.user.performfishanalytics.client.DataMinerAlgorithms;
-import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant;
-import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync;
-import org.gcube.portlets.user.performfishanalytics.client.controllers.PerformFishAnalyticsController;
-import org.gcube.portlets.user.performfishanalytics.client.event.CallAlgorithmEvent;
-import org.gcube.portlets.user.performfishanalytics.client.view.util.CorrelationValueToColourUtil;
-import org.gcube.portlets.user.performfishanalytics.shared.FileContentType;
-import org.gcube.portlets.user.performfishanalytics.shared.KPI;
-import org.gcube.portlets.user.performfishanalytics.shared.OutputFile;
-import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile;
-import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVRow;
-import org.gcube.portlets.user.performfishanalytics.shared.dataminer.DataMinerResponse;
-
-import com.github.gwtbootstrap.client.ui.Alert;
-import com.github.gwtbootstrap.client.ui.ControlGroup;
-import com.github.gwtbootstrap.client.ui.ListBox;
-import com.github.gwtbootstrap.client.ui.constants.AlertType;
-import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.dom.client.Style.Unit;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.event.logical.shared.AttachEvent;
-import com.google.gwt.uibinder.client.UiBinder;
-import com.google.gwt.uibinder.client.UiField;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.ui.ComplexPanel;
-import com.google.gwt.user.client.ui.Composite;
-import com.google.gwt.user.client.ui.FlexTable;
-import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.HTMLPanel;
-import com.google.gwt.user.client.ui.HorizontalPanel;
-import com.google.gwt.user.client.ui.Label;
-import com.google.gwt.user.client.ui.VerticalPanel;
-import com.google.gwt.user.client.ui.Widget;
-
-
-/**
- * The Class AnalyticsPanelResult.
- *
- * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
- * Jan 29, 2019
- */
-public class AnalyticsPanelResult extends Composite {
-
- /**
- *
- */
-
-
- private static AnalyticsPanelResultUiBinder uiBinder =
- GWT.create(AnalyticsPanelResultUiBinder.class);
-
- /**
- * The Interface AnalyticsPanelResultUiBinder.
- *
- * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
- * Jan 30, 2019
- */
- interface AnalyticsPanelResultUiBinder
- extends UiBinder {
- }
-
- @UiField
- HTMLPanel field_html_panel;
-
- @UiField
- VerticalPanel field_parameters_container;
-
- @UiField
- VerticalPanel uib_vp_correlation_results_container;
-
- @UiField
- VerticalPanel field_unary_algorithm_container;
-
- @UiField
- VerticalPanel field_binary_algorithm;
-
- @UiField
- VerticalPanel field_binary_algorithm_container;
-
- @UiField
- VerticalPanel field_unary_algorithm;
-
- @UiField
- Label uib_label_focus_id;
-
- @UiField
- ControlGroup cg_focus_id_correlation;
-
- @UiField
- ListBox field_list_focus_id_correlation;
-
-
- private Map dataInputParameters;
-
- private DataMinerResponse dmResponse;
-
- private Map> kpiMapPointers = new HashMap>();
-
- private List selectedKPIs;
-
- private List selectedAreas;
-
- private Map csvGenerated = new HashMap();
-
- /**
- * Because this class has a default constructor, it can
- * be used as a binder template. In other words, it can be used in other
- * *.ui.xml files as follows:
- *
- * Hello!
- *
- * Note that depending on the widget that is used, it may be necessary to
- * implement HasHTML instead of HasText.
- */
- public AnalyticsPanelResult() {
-
- initWidget(uiBinder.createAndBindUi(this));
- }
-
-
-
- /**
- * Adds the selected areas.
- *
- * @param listAreas the list areas
- */
- public void addSelectedAreas(List listAreas) {
-
- this.selectedAreas = listAreas;
-
- }
-
-
- /**
- * Gets the data miner response.
- *
- * @return the data miner response
- */
- public DataMinerResponse getDataMinerResponse(){
- return dmResponse;
- }
-
-
-
- /**
- * Gets the data input parameters.
- *
- * @return the data input parameters
- */
- public Map getDataInputParameters() {
-
- return dataInputParameters;
- }
-
- /**
- * Show alert.
- *
- * @param error the error
- * @param type the type
- * @param closable the closable
- * @param panel the panel
- */
- private void showAlert(String error, AlertType type, boolean closable, ComplexPanel panel){
- Alert alert = new Alert(error);
- alert.setType(type);
- alert.setClose(closable);
- alert.getElement().getStyle().setMargin(10, Unit.PX);
- panel.add(alert);
- }
-
-
- /**
- * Adds the selected kp is.
- *
- * @param selectedKPIs the selected kp is
- */
- public void addSelectedKPIs(List selectedKPIs) {
-
- this.selectedKPIs = selectedKPIs;
-
- }
-
- /**
- * Gets the KPI for name.
- *
- * @param name the name
- * @return the KPI for name
- */
- public KPI getKPIForName(String name){
-
- GWT.log("Searching KPI name: "+name);
- KPI foundKPI = null;
- String purgedName = name.trim();
- for (KPI kpi : selectedKPIs) {
- String purgedKPIName = kpi.getName().trim();
- if(purgedKPIName.compareToIgnoreCase(purgedName)==0) {
- foundKPI = kpi;
- break;
- }
- }
- GWT.log("FOUND KPI: "+foundKPI);
- return foundKPI;
- }
-
-
-
- /**
- * Adds the parameters.
- *
- * @param keyToGet the key to get
- * @param parameters the parameters
- * @param toShowBatchTypeValue label to show batch type value
- */
- public void addParameters(String keyToGet, Map> parameters, String toShowBatchTypeValue) {
-
-
- final FlexTable flexTable = new FlexTable();
- flexTable.setStyleName("colgrouptable");
-
- try{
- List dataInputs = parameters.get(keyToGet);
-
- if(dataInputs==null || dataInputs.isEmpty())
- return;
-
- dataInputParameters = new HashMap();
-
- String theDataInputs = dataInputs.get(0);
- String[] splittedParams = theDataInputs.split(";");
-
- for (String splitParam : splittedParams) {
- try{
- String[] keyvalue = splitParam.split("=");
- dataInputParameters.put(keyvalue[0], keyvalue[1]);
- }catch(Exception e){
-
- }
- }
-
-
- flexTable.setWidget(0, 0, new HTML("Batch Type:"));
- flexTable.setWidget(0, 1, new HTML(toShowBatchTypeValue));
- flexTable.setWidget(1, 0, new HTML("Level:"));
- flexTable.setWidget(1, 1, new HTML(dataInputParameters.get(PerformFishAnalyticsConstant.DM_SCALEP_PARAM)));
-
- String KPINames = "";
- for (KPI kpi: selectedKPIs) {
- KPINames+=kpi.getName() +", ";
- }
- KPINames = KPINames.substring(0, KPINames.length()-2);
- flexTable.setWidget(2, 0, new HTML("KPIs:"));
- flexTable.setWidget(2, 1, new HTML(KPINames));
-
-
-
-
- }catch(Exception e){
- //silent
- }
-
- field_parameters_container.add(flexTable);
- }
-
-
-
- /**
- * Adds the list focus ids.
- *
- * @param listFocusIDs the list focus I ds
- */
- public void addListFocusIds(List listFocusIDs){
- for (String batchID : listFocusIDs) {
- field_list_focus_id_correlation.addItem(batchID, batchID);
- }
- }
-
- /**
- * Adds the results.
- *
- * @param dmResponse the dm response
- */
- public void addResults(DataMinerResponse dmResponse) {
- this.dmResponse = dmResponse;
-
- for (final OutputFile outputFile : dmResponse.getListOutput()) {
-
- if(outputFile.getDataType().equals(FileContentType.CSV)){
- PerformFishAnalyticsServiceAsync.Util.getInstance().getCSVFile(outputFile, true, new AsyncCallback() {
-
- @Override
- public void onFailure(Throwable caught) {
- showAlert(caught.getMessage(), AlertType.ERROR, true, uib_vp_correlation_results_container);
-
- }
-
- @Override
- public void onSuccess(CSVFile result) {
-
- csvGenerated.put(result.getFileName(), result);
- fillCorrelationMatrix();
- }
- });
- }
-
- }
- }
-
- private void fillCorrelationMatrix() {
-
- if(csvGenerated.size()<2)
- return;
-
- String corrIndexFilename = null;
- String corrFilename = null;
- for (String fileName : csvGenerated.keySet()) {
- if(fileName.contains("index")) {
- corrIndexFilename = fileName;
- }else {
- corrFilename = fileName;
- }
- }
-
- GWT.log("Correlation Matrix Index File: "+corrIndexFilename);
- GWT.log("Correlation Matrix File: "+corrFilename);
- CSVFile corrIndexCsvFile = csvGenerated.get(corrIndexFilename);
- CSVFile corrCsvFile = csvGenerated.get(corrFilename);
- GWT.log("Correlation Matrix Index CSV: "+corrIndexCsvFile);
- GWT.log("Correlation Matrix CSV: "+corrCsvFile);
-
- HorizontalPanel hp = new HorizontalPanel();
- final FlexTable flexTable = new FlexTable();
- flexTable.setStyleName("fixedtable");
- flexTable.getElement().getStyle().setMarginBottom(10, Unit.PX);
-
- flexTable.setWidget(0, 0,new Label(""));
-
-
- CSVRow headerRow = corrIndexCsvFile.getHeaderRow();
- //HEADER
- for (int i=1; i 0
- }else{
- KPI columnKPI = getKPIForName(headerRow.getListValues().get(columnIndex));
- //Here the first index is the KPI name
- KPI rowKPI = getKPIForName(row.getListValues().get(0));
- fillKPIReferenceForIndex(rowIndex, columnIndex, Arrays.asList(columnKPI, rowKPI));
- //button.setText(" ");
- //button.setIcon(IconType.COMPASS);
- //button.setSize(ButtonSize.LARGE);
-
- buttonHTML.addClickHandler(new ClickHandler() {
-
- @Override
- public void onClick(ClickEvent event) {
-
- //callScatterAndDeaChart(rowIndex, columnIndex, button);
- callScatter(rowIndex, columnIndex, buttonHTML);
- }
- });
- }
-
- //button.setType(ButtonType.LINK);
- //APPLYING STYLE ONLY ON INTERNAL VALUES OF CSV
- if(j>0)
- buttonHTML.getElement().getStyle().setColor("#000");
-
- buttonHTML.addAttachHandler(new AttachEvent.Handler() {
-
- @Override
- public void onAttachOrDetach(AttachEvent event) {
- if(theColor.startsWith("#")){
- GWT.log("Setting backgrounf color: "+theColor);
- buttonHTML.getElement().getParentElement().getStyle().setBackgroundColor(theColor);
- }
- }
- });
-
- flexTable.setWidget(rowIndex, j,buttonHTML);
- }
-
- }
-
- hp.add(flexTable);
-
- final FlexTable flexLegend = new FlexTable();
- flexLegend.setStyleName("simpletable");
- //flexLegend.getElement().getStyle().setBorderWidth(0, Unit.PX);
- Map map = CorrelationValueToColourUtil.getMap();
- flexLegend.setWidget(0, 0, new Label("Legend"));
- flexLegend.setWidget(0, 1, new HTML(""));
- int i = 1;
- for (String key : map.keySet()) {
- final String rgbColor = map.get(key);
- final HTML theLegendColor = new HTML("");
- flexLegend.setWidget(i, 0, theLegendColor);
- flexLegend.setWidget(i, 1, new HTML(key));
- theLegendColor.addAttachHandler(new AttachEvent.Handler() {
-
- @Override
- public void onAttachOrDetach(AttachEvent event) {
- theLegendColor.getElement().getParentElement().getStyle().setBackgroundColor(rgbColor);
- }
- });
-
- i++;
- }
-
- flexLegend.getElement().getStyle().setMarginLeft(15, Unit.PX);
- hp.add(flexLegend);
- uib_vp_correlation_results_container.insert(hp,0);
-
- }
-
- /**
- * Fill kpi reference for index.
- *
- * @param rowIndex the row index
- * @param columnIndex the column index
- * @param listKPI the list kpi
- */
- private void fillKPIReferenceForIndex(int rowIndex, int columnIndex, List listKPI){
-
- String key = generateKey(rowIndex, columnIndex);
- kpiMapPointers.put(key, listKPI);
- }
-
- /**
- * Gets the KPI for indexes.
- *
- * @param rowIndex the row index
- * @param columnIndex the column index
- * @return the KPI for indexes
- */
- public List getKPIForIndexes(int rowIndex, int columnIndex){
- String key = generateKey(rowIndex, columnIndex);
- return kpiMapPointers.get(key);
- }
-
- /**
- * Generate key.
- *
- * @param rowIndex the row index
- * @param columnIndex the column index
- * @return the string
- */
- private String generateKey(int rowIndex, int columnIndex) {
- return rowIndex+"-"+columnIndex;
- }
-
-
- /**
- * Check valid focus id.
- *
- * @return the FocusID if it is valid, null otherwise.
- */
- public String checkValidFocusID(){
-
- cg_focus_id_correlation.setType(ControlGroupType.NONE);
-
- //CHECK THE FOCUS ID VALUE
- String focusID = field_list_focus_id_correlation.getSelectedItemText();
-
- if(focusID==null || focusID.isEmpty()){
-
- String msgError = "Could not execute a valid Analysis.";
-
- if(selectedAreas==null || selectedAreas.isEmpty()){
- msgError+=" Please select another parameters computation";
- }else{
- msgError+=" Select at least the Area of your FARM";
- }
-
- showAlert(msgError, AlertType.ERROR, true, uib_vp_correlation_results_container);
- cg_focus_id_correlation.setType(ControlGroupType.ERROR);
- return null;
- }
-
- return focusID;
- }
-
-
- /**
- * Call scatter.
- *
- * @param rowIndex the row index
- * @param columnIndex the column index
- * @param button the button
- */
- private void callScatter(int rowIndex, int columnIndex, HTML button){
-
- String focusID = checkValidFocusID();
-
- if(focusID==null)
- return;
-
- GWT.log("Called ScatterChart at rowIndex: "+rowIndex +", columnIndex: "+columnIndex);
- List selectedKPI = getKPIForIndexes(rowIndex, columnIndex);
- GWT.log("Selected KPI: "+selectedKPI);
- PerformFishAnalyticsController.eventBus.fireEvent(new CallAlgorithmEvent(DataMinerAlgorithms.SCATTER, focusID, selectedKPI, null));
- }
-
-
-
-
-
-
-
-}
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/BoxPlotPanelResult.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/BoxPlotPanelResult.java
index 46b8c9d..cd89ab5 100644
--- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/BoxPlotPanelResult.java
+++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/BoxPlotPanelResult.java
@@ -12,6 +12,7 @@ import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsS
import org.gcube.portlets.user.performfishanalytics.client.controllers.PerformFishAnalyticsViewController;
import org.gcube.portlets.user.performfishanalytics.client.resources.PerformFishResources;
import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon;
+import org.gcube.portlets.user.performfishanalytics.shared.FileContentType;
import org.gcube.portlets.user.performfishanalytics.shared.KPI;
import org.gcube.portlets.user.performfishanalytics.shared.OutputFile;
import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile;
@@ -38,18 +39,20 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Panel;
public class BoxPlotPanelResult {
-
+
private Map boxPlotOrderBy = new HashMap();
private PerformFishAnalyticsViewController viewController;
private int outputIteration = 0;
- private int outputNumber = 0;
- private int requestId;
-
+ private int outputNumber = 3;
+ private int requestId = 0;
- public BoxPlotPanelResult(int reqId,PerformFishAnalyticsViewController viewController, final DataMinerAlgorithms algorithm,
- String focusID, List inputKPI, final List outputKPI) {
- this.requestId=reqId;
+ private Button savePDFButton;
+
+ public BoxPlotPanelResult(int reqId, PerformFishAnalyticsViewController viewController,
+ final DataMinerAlgorithms algorithm, String focusID, List inputKPI, final List outputKPI) {
+ GWT.log("RequestID: " + reqId);
+ requestId = reqId;
this.viewController = viewController;
TextResource algDescr = PerformFishResources.INSTANCE.batch_BOXPLOT();
@@ -65,7 +68,7 @@ public class BoxPlotPanelResult {
HorizontalPanel res = new HorizontalPanel();
- Button savePDFButton = new Button();
+ savePDFButton = new Button();
savePDFButton.getElement().getStyle().setMargin(10, Unit.PX);
savePDFButton.setIcon(IconType.PRINT);
savePDFButton.addClickHandler(new ClickHandler() {
@@ -76,6 +79,7 @@ public class BoxPlotPanelResult {
// dmResponse.getListOutput().size()
}
});
+ savePDFButton.setVisible(false);
res.add(savePDFButton);
submitRequestPanel.addWidget(res);
@@ -86,6 +90,7 @@ public class BoxPlotPanelResult {
oIteration++;
String title = "KPI: " + kpi.getName();
HTML toBigTitle = new HTML(title);
+ toBigTitle.getElement().setId("KPI_BoxPlot_" + requestId + "_" + oIteration);
toBigTitle.getElement().addClassName("to-big-title");
submitRequestPanel.addWidget(toBigTitle);
HorizontalPanel hp = new HorizontalPanel();
@@ -194,11 +199,26 @@ public class BoxPlotPanelResult {
}
});
+
+ }
+
+ private String getOutputId(int oIteration, String title) {
+ if (title.startsWith("My")) {
+ String outputId = "OutputId_" + requestId + "_" + oIteration + "_" + 1;
+ return outputId;
+ } else if (title.startsWith("All")) {
+ String outputId = "OutputId_" + requestId + "_" + oIteration + "_" + 2;
+ return outputId;
+ } else {
+ String outputId = "OutputId_" + requestId + "_" + oIteration + "_" + 3;
+ return outputId;
+ }
+
}
private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
final DataMinerAlgorithms chartType, List inputKPIs, List outputKPIs, final String focusID,
- final Panel container, boolean displayError, int oIteration) {
+ final Panel container, boolean displayError, final int oIteration) {
String title = displayError ? "No results " : "";
@@ -210,16 +230,13 @@ public class BoxPlotPanelResult {
container.add(alert);
return;
}
-
+
+ savePDFButton.setVisible(true);
final String toTitle = title;
- outputNumber = dmResponse.getListOutput().size();
+ for (OutputFile outputFile : dmResponse.getListOutput()) {
- int oNumber = 0;
-
- for (final OutputFile outputFile : dmResponse.getListOutput()) {
- oNumber++;
- final String outputId = "OutputId_" +requestId+"_"+ oIteration + "_" + oNumber;
+ final FileContentType fileContentType = outputFile.getDataType();
switch (outputFile.getDataType()) {
case IMAGE:
@@ -243,7 +260,8 @@ public class BoxPlotPanelResult {
title = chartType.getName() + " - on all batches
";
title += "Blue dots indicate the selected batch(es): " + focusID;
- ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
+ String outputId = getOutputId(oIteration, title);
+ ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showImage(base64Content);
displayingOrderedBoxPlot(dmResponse, title, container, showResult);
}
@@ -277,7 +295,8 @@ public class BoxPlotPanelResult {
title += "
";
title += "Data aggregation is performed by considering batches as base units";
- ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
+ String outputId = getOutputId(oIteration, title);
+ ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showCSVFile(result, cssTableStyle);
displayingOrderedBoxPlot(dmResponse, title, container, showResult);
@@ -292,7 +311,7 @@ public class BoxPlotPanelResult {
}
}
-
+
private void displayingOrderedBoxPlot(final DataMinerResponse dmResponse, String title, final Panel container,
ShowResult showResult) {
int hashcode = dmResponse.hashCode();
@@ -314,7 +333,7 @@ public class BoxPlotPanelResult {
flex.setWidget(0, 2, showResult);
}
}
-
+
/**
* Remove the spinner if all DM responses are returned.
*
@@ -337,7 +356,7 @@ public class BoxPlotPanelResult {
int requestId, int outputIteration, int outputNumber)/*-{
var that = this;
console.log('saveFilePDF()');
- console.log('requestId: '+requestId);
+ console.log('requestId: ' + requestId);
console.log('OutputIteration: ' + outputIteration);
console.log('OutputNumber:' + outputNumber);
@@ -385,9 +404,32 @@ public class BoxPlotPanelResult {
for (var i = 1; i <= outputIteration; i++) {
+ var kpiId = 'KPI_BoxPlot_' + requestId + '_' + i;
+ console.log('kpiId: ' + kpiId);
+
+ var kpiName = $doc.getElementById(kpiId);
+
+ yPos += 2;
+ pdoc.setFontSize(14);
+ pdoc.setFontType("bold");
+
+ var kpiText = kpiName.textContent;
+ var kpiHeight = pdoc.getLineHeight(kpiText)
+ / pdoc.internal.scaleFactor;
+ var splittedKpiName = pdoc.splitTextToSize(kpiText, (pdfWidthInMM
+ - lMargin - rMargin));
+ var kpiLines = splittedKpiName.length; // splitted text is a string array
+ var kpiLinesHeight = kpiLines * kpiHeight;
+ pdoc.text(splittedKpiName, xPos, yPos, 'left');
+ yPos += kpiLinesHeight;
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
for (var j = 1; j <= outputNumber; j++) {
- var outputId = 'OutputId_'+requestId+'_'+ i + '_' + j;
+ var outputId = 'OutputId_' + requestId + '_' + i + '_' + j;
console.log('OutputId: ' + outputId);
var resultOutputNumber = $doc.getElementById(outputId);
@@ -405,6 +447,19 @@ public class BoxPlotPanelResult {
// foo could get resolved and it's defined
var childrenTable = resultOutputNumber.children;
+ var titleCurrentTable = childrenTable[0].rows[0].cells[0];
+ console.log('Title current table: '
+ + titleCurrentTable.textContent);
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text(titleCurrentTable.textContent, xPos, yPos,
+ 'left');
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
var secondDiv = childrenTable[0].rows[1].cells[0];
var secondTable = secondDiv.children[0].children[0];
@@ -425,6 +480,20 @@ public class BoxPlotPanelResult {
if (resultType == 'image') {
console.log('Result Type image: ' + i);
var childrenTable = resultOutputNumber.children;
+
+ var titleCurrentImage = childrenTable[0].rows[0].cells[0];
+ console.log('Title current image: '
+ + titleCurrentImage.textContent);
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text(titleCurrentImage.textContent, xPos,
+ yPos, 'left');
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
var secondDiv = childrenTable[0].rows[1].cells[0];
var imageElement = secondDiv.getElementsByTagName(
'img').item(0);
@@ -443,6 +512,24 @@ public class BoxPlotPanelResult {
}
}
+
+ if (i < outputIteration) {
+ pdoc.addPage();
+ yPos = tMargin; // Restart position
+ } else {
+
+ }
+
+ }
+
+ var numberOfPages=pdoc.internal.getNumberOfPages()
+ console.log('NumberOfPages: ' + numberOfPages);
+ for (var k = 1; k <= numberOfPages; k++) {
+ pdoc.setPage(k);
+ console.log('CurrentPage: ' + k);
+ var footner = 'Page ' + k + "/"+numberOfPages;
+ pdoc.text(footner, pageCenter, pdfHeightInMM - 7, 'center');
+
}
console.log('Done');
@@ -450,5 +537,5 @@ public class BoxPlotPanelResult {
pdoc.save(filename);
}-*/;
-
+
}
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/CorrelationPanelResult.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/CorrelationPanelResult.java
new file mode 100644
index 0000000..7593274
--- /dev/null
+++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/CorrelationPanelResult.java
@@ -0,0 +1,807 @@
+/**
+ *
+ */
+package org.gcube.portlets.user.performfishanalytics.client.viewbinder;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.gcube.portlets.user.performfishanalytics.client.DataMinerAlgorithms;
+import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant;
+import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync;
+import org.gcube.portlets.user.performfishanalytics.client.controllers.PerformFishAnalyticsController;
+import org.gcube.portlets.user.performfishanalytics.client.event.CallAlgorithmEvent;
+import org.gcube.portlets.user.performfishanalytics.client.view.util.CorrelationValueToColourUtil;
+import org.gcube.portlets.user.performfishanalytics.shared.FileContentType;
+import org.gcube.portlets.user.performfishanalytics.shared.KPI;
+import org.gcube.portlets.user.performfishanalytics.shared.OutputFile;
+import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile;
+import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVRow;
+import org.gcube.portlets.user.performfishanalytics.shared.dataminer.DataMinerResponse;
+
+import com.github.gwtbootstrap.client.ui.Alert;
+import com.github.gwtbootstrap.client.ui.Button;
+import com.github.gwtbootstrap.client.ui.ControlGroup;
+import com.github.gwtbootstrap.client.ui.ListBox;
+import com.github.gwtbootstrap.client.ui.constants.AlertType;
+import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
+import com.github.gwtbootstrap.client.ui.constants.IconType;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.Style.Unit;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.event.logical.shared.AttachEvent;
+import com.google.gwt.uibinder.client.UiBinder;
+import com.google.gwt.uibinder.client.UiField;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.ComplexPanel;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.FlexTable;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.HTMLPanel;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.Label;
+import com.google.gwt.user.client.ui.VerticalPanel;
+import com.google.gwt.user.client.ui.Widget;
+
+/**
+ * The Class AnalyticsPanelResult.
+ *
+ * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jan 29, 2019
+ */
+public class CorrelationPanelResult extends Composite {
+
+ /**
+ *
+ */
+
+ private static CorrelationPanelResultUiBinder uiBinder = GWT.create(CorrelationPanelResultUiBinder.class);
+
+ /**
+ * The Interface AnalyticsPanelResultUiBinder.
+ *
+ * @author Francesco Mangiacrapa at ISTI-CNR
+ * (francesco.mangiacrapa@isti.cnr.it) Jan 30, 2019
+ */
+ interface CorrelationPanelResultUiBinder extends UiBinder {
+ }
+
+ @UiField
+ HTMLPanel field_html_panel;
+
+ @UiField
+ VerticalPanel field_parameters_container;
+
+ @UiField
+ VerticalPanel uib_vp_correlation_results_container;
+
+ @UiField
+ VerticalPanel field_unary_algorithm_container;
+
+ @UiField
+ VerticalPanel field_binary_algorithm;
+
+ @UiField
+ VerticalPanel field_binary_algorithm_container;
+
+ @UiField
+ VerticalPanel field_unary_algorithm;
+
+ @UiField
+ Label uib_label_focus_id;
+
+ @UiField
+ ControlGroup cg_focus_id_correlation;
+
+ @UiField
+ ListBox field_list_focus_id_correlation;
+
+ @UiField
+ Button uib_save_pdf_1;
+
+ private Map dataInputParameters;
+
+ private DataMinerResponse dmResponse;
+
+ private Map> kpiMapPointers = new HashMap>();
+
+ private List selectedKPIs;
+
+ private List selectedAreas;
+
+ private Map csvGenerated = new HashMap();
+
+ private CorrelationPanelResult analyticsPanelResult;
+
+ private int outputNumber;
+ private int requestId = 0;
+
+ /**
+ *
+ * @param reqId
+ * Request Identifier
+ * @param tabTitle
+ * Title
+ * @param tabDescription
+ * Description
+ */
+ public CorrelationPanelResult(int reqId, final String tabTitle, final String tabDescription) {
+ GWT.log("RequestID: " + reqId);
+ requestId = reqId;
+
+ initWidget(uiBinder.createAndBindUi(this));
+
+ analyticsPanelResult = this;
+
+ uib_save_pdf_1.setIcon(IconType.PRINT);
+ uib_save_pdf_1.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+ saveFilePDF(analyticsPanelResult, tabTitle, tabTitle, tabDescription, requestId, outputNumber);
+ }
+ });
+ }
+
+ /**
+ * Adds the selected areas.
+ *
+ * @param listAreas
+ * the list areas
+ */
+ public void addSelectedAreas(List listAreas) {
+
+ this.selectedAreas = listAreas;
+
+ }
+
+ /**
+ * Gets the data miner response.
+ *
+ * @return the data miner response
+ */
+ public DataMinerResponse getDataMinerResponse() {
+ return dmResponse;
+ }
+
+ /**
+ * Gets the data input parameters.
+ *
+ * @return the data input parameters
+ */
+ public Map getDataInputParameters() {
+
+ return dataInputParameters;
+ }
+
+ /**
+ * Show alert.
+ *
+ * @param error
+ * the error
+ * @param type
+ * the type
+ * @param closable
+ * the closable
+ * @param panel
+ * the panel
+ */
+ private void showAlert(String error, AlertType type, boolean closable, ComplexPanel panel) {
+ Alert alert = new Alert(error);
+ alert.setType(type);
+ alert.setClose(closable);
+ alert.getElement().getStyle().setMargin(10, Unit.PX);
+ panel.add(alert);
+ }
+
+ /**
+ * Adds the selected kp is.
+ *
+ * @param selectedKPIs
+ * the selected kp is
+ */
+ public void addSelectedKPIs(List selectedKPIs) {
+
+ this.selectedKPIs = selectedKPIs;
+
+ }
+
+ /**
+ * Gets the KPI for name.
+ *
+ * @param name
+ * the name
+ * @return the KPI for name
+ */
+ public KPI getKPIForName(String name) {
+
+ GWT.log("Searching KPI name: " + name);
+ KPI foundKPI = null;
+ String purgedName = name.trim();
+ for (KPI kpi : selectedKPIs) {
+ String purgedKPIName = kpi.getName().trim();
+ if (purgedKPIName.compareToIgnoreCase(purgedName) == 0) {
+ foundKPI = kpi;
+ break;
+ }
+ }
+ GWT.log("FOUND KPI: " + foundKPI);
+ return foundKPI;
+ }
+
+ /**
+ * Adds the parameters.
+ *
+ * @param keyToGet
+ * the key to get
+ * @param parameters
+ * the parameters
+ * @param toShowBatchTypeValue
+ * label to show batch type value
+ */
+ public void addParameters(String keyToGet, Map> parameters, String toShowBatchTypeValue) {
+
+ final FlexTable flexTable = new FlexTable();
+ flexTable.getElement().setId("CorrelationParameterInputKPIs");
+ flexTable.setStyleName("colgrouptable");
+
+ try {
+ List dataInputs = parameters.get(keyToGet);
+
+ if (dataInputs == null || dataInputs.isEmpty())
+ return;
+
+ dataInputParameters = new HashMap();
+
+ String theDataInputs = dataInputs.get(0);
+ String[] splittedParams = theDataInputs.split(";");
+
+ for (String splitParam : splittedParams) {
+ try {
+ String[] keyvalue = splitParam.split("=");
+ dataInputParameters.put(keyvalue[0], keyvalue[1]);
+ } catch (Exception e) {
+
+ }
+ }
+
+ flexTable.setWidget(0, 0, new HTML("Batch Type:"));
+ flexTable.setWidget(0, 1, new HTML(toShowBatchTypeValue));
+ flexTable.setWidget(1, 0, new HTML("Level:"));
+ flexTable.setWidget(1, 1, new HTML(dataInputParameters.get(PerformFishAnalyticsConstant.DM_SCALEP_PARAM)));
+
+ String KPINames = "";
+ for (KPI kpi : selectedKPIs) {
+ KPINames += kpi.getName() + ", ";
+ }
+ KPINames = KPINames.substring(0, KPINames.length() - 2);
+ flexTable.setWidget(2, 0, new HTML("KPIs:"));
+ flexTable.setWidget(2, 1, new HTML(KPINames));
+
+ } catch (Exception e) {
+ // silent
+ }
+
+ field_parameters_container.add(flexTable);
+ }
+
+ /**
+ * Adds the list focus ids.
+ *
+ * @param listFocusIDs
+ * the list focus I ds
+ */
+ public void addListFocusIds(List listFocusIDs) {
+ for (String batchID : listFocusIDs) {
+ field_list_focus_id_correlation.addItem(batchID, batchID);
+ }
+ }
+
+ private String getOutputId() {
+ outputNumber++;
+ String outputId = "OutputId_" + outputNumber;
+ GWT.log("Generated OutputId: " + outputId);
+ return outputId;
+ }
+
+ /**
+ * Adds the results.
+ *
+ * @param dmResponse
+ * the dm response
+ */
+ public void addResults(DataMinerResponse dmResponse) {
+ this.dmResponse = dmResponse;
+
+ outputNumber = 0;
+ for (OutputFile outputFile : dmResponse.getListOutput()) {
+
+ if (outputFile.getDataType().equals(FileContentType.CSV)) {
+ PerformFishAnalyticsServiceAsync.Util.getInstance().getCSVFile(outputFile, true,
+ new AsyncCallback() {
+
+ @Override
+ public void onFailure(Throwable caught) {
+ showAlert(caught.getMessage(), AlertType.ERROR, true,
+ uib_vp_correlation_results_container);
+
+ }
+
+ @Override
+ public void onSuccess(CSVFile result) {
+
+ csvGenerated.put(result.getFileName(), result);
+ fillCorrelationMatrix();
+ }
+ });
+ }
+
+ }
+ }
+
+ private void fillCorrelationMatrix() {
+
+ if (csvGenerated.size() < 2)
+ return;
+
+ String corrIndexFilename = null;
+ String corrFilename = null;
+ for (String fileName : csvGenerated.keySet()) {
+ if (fileName.contains("index")) {
+ corrIndexFilename = fileName;
+ } else {
+ corrFilename = fileName;
+ }
+ }
+
+ GWT.log("Correlation Matrix Index File: " + corrIndexFilename);
+ GWT.log("Correlation Matrix File: " + corrFilename);
+ CSVFile corrIndexCsvFile = csvGenerated.get(corrIndexFilename);
+ CSVFile corrCsvFile = csvGenerated.get(corrFilename);
+ GWT.log("Correlation Matrix Index CSV: " + corrIndexCsvFile);
+ GWT.log("Correlation Matrix CSV: " + corrCsvFile);
+
+ HorizontalPanel hp = new HorizontalPanel();
+ final FlexTable flexTable = new FlexTable();
+ flexTable.getElement().setId(getOutputId());
+ flexTable.setStyleName("fixedtable");
+ flexTable.getElement().getStyle().setMarginBottom(10, Unit.PX);
+
+ flexTable.setWidget(0, 0, new Label(""));
+
+ CSVRow headerRow = corrIndexCsvFile.getHeaderRow();
+ // HEADER
+ for (int i = 1; i < headerRow.getListValues().size(); i++) {
+
+ final String headerValue = headerRow.getListValues().get(i);
+ HTML label = new HTML(headerValue);
+ label.getElement().getStyle().setFontSize(16, Unit.PX);
+
+ final int columnIndex = i;
+ KPI kpi = getKPIForName(headerValue);
+ fillKPIReferenceForIndex(0, columnIndex, Arrays.asList(kpi));
+ flexTable.setWidget(0, i, label);
+ }
+ // DATA
+ for (int i = 0; i < corrIndexCsvFile.getValueRows().size(); i++) {
+ CSVRow row = corrIndexCsvFile.getValueRows().get(i);
+ CSVRow rowMatrixColor = corrCsvFile.getValueRows().get(i);
+ final int rowIndex = i + 1; // adding +1 for header row
+ for (int j = 0; j < row.getListValues().size(); j++) {
+ final String rowValue = row.getListValues().get(j);
+ final String rowMatrixColorValue = rowMatrixColor.getListValues().get(j);
+ final String theColor = CorrelationValueToColourUtil.getRGBColor(rowMatrixColorValue);
+ final int columnIndex = j;
+ final HTML buttonHTML = new HTML(rowValue);
+ buttonHTML.addStyleName("my-active-html");
+ if (j == 0) {
+ HTML label = new HTML(rowValue);
+ label.getElement().getStyle().setFontSize(16, Unit.PX);
+ flexTable.setWidget(rowIndex, j, label);
+ // rowValue is a KPI name
+ KPI kpi = getKPIForName(rowValue);
+ fillKPIReferenceForIndex(rowIndex, columnIndex, Arrays.asList(kpi));
+ continue;
+ }
+ // diagonal
+ else if (rowIndex == j) {
+ HTML dg = new HTML(rowValue);
+ dg.getElement().getStyle().setFontSize(18, Unit.PX);
+ flexTable.setWidget(rowIndex, j, dg);
+ continue;
+ // j > 0
+ } else {
+ KPI columnKPI = getKPIForName(headerRow.getListValues().get(columnIndex));
+ // Here the first index is the KPI name
+ KPI rowKPI = getKPIForName(row.getListValues().get(0));
+ fillKPIReferenceForIndex(rowIndex, columnIndex, Arrays.asList(columnKPI, rowKPI));
+
+ buttonHTML.addClickHandler(new ClickHandler() {
+
+ @Override
+ public void onClick(ClickEvent event) {
+
+ // callScatterAndDeaChart(rowIndex, columnIndex,
+ // button);
+ callScatter(rowIndex, columnIndex, buttonHTML);
+ }
+ });
+ }
+
+ // button.setType(ButtonType.LINK);
+ // APPLYING STYLE ONLY ON INTERNAL VALUES OF CSV
+ if (j > 0)
+ buttonHTML.getElement().getStyle().setColor("#000");
+
+ buttonHTML.addAttachHandler(new AttachEvent.Handler() {
+
+ @Override
+ public void onAttachOrDetach(AttachEvent event) {
+ if (theColor.startsWith("#")) {
+ GWT.log("Setting backgrounf color: " + theColor);
+ buttonHTML.getElement().getParentElement().getStyle().setBackgroundColor(theColor);
+ }
+ }
+ });
+
+ buttonHTML.getElement().getStyle().setBackgroundColor(theColor);
+ flexTable.setWidget(rowIndex, j, buttonHTML);
+ }
+
+ }
+
+ hp.add(flexTable);
+
+ final FlexTable flexLegend = new FlexTable();
+ flexLegend.getElement().setId(getOutputId());
+ flexLegend.setStyleName("simpletable");
+ Map map = CorrelationValueToColourUtil.getMap();
+ flexLegend.setWidget(0, 0, new Label("Legend"));
+ flexLegend.setWidget(0, 1, new HTML(""));
+ int i = 1;
+ for (String key : map.keySet()) {
+ final String rgbColor = map.get(key);
+ final HTML theLegendColor = new HTML("");
+ theLegendColor.getElement().getStyle().setBackgroundColor(rgbColor);
+ flexLegend.setWidget(i, 0, theLegendColor);
+ flexLegend.setWidget(i, 1, new HTML(key));
+ theLegendColor.addAttachHandler(new AttachEvent.Handler() {
+
+ @Override
+ public void onAttachOrDetach(AttachEvent event) {
+ theLegendColor.getElement().getParentElement().getStyle().setBackgroundColor(rgbColor);
+ }
+ });
+
+ i++;
+ }
+
+ flexLegend.getElement().getStyle().setMarginLeft(15, Unit.PX);
+ hp.add(flexLegend);
+ uib_vp_correlation_results_container.insert(hp, 0);
+
+ }
+
+ /**
+ * Fill kpi reference for index.
+ *
+ * @param rowIndex
+ * the row index
+ * @param columnIndex
+ * the column index
+ * @param listKPI
+ * the list kpi
+ */
+ private void fillKPIReferenceForIndex(int rowIndex, int columnIndex, List listKPI) {
+
+ String key = generateKey(rowIndex, columnIndex);
+ kpiMapPointers.put(key, listKPI);
+ }
+
+ /**
+ * Gets the KPI for indexes.
+ *
+ * @param rowIndex
+ * the row index
+ * @param columnIndex
+ * the column index
+ * @return the KPI for indexes
+ */
+ public List getKPIForIndexes(int rowIndex, int columnIndex) {
+ String key = generateKey(rowIndex, columnIndex);
+ return kpiMapPointers.get(key);
+ }
+
+ /**
+ * Generate key.
+ *
+ * @param rowIndex
+ * the row index
+ * @param columnIndex
+ * the column index
+ * @return the string
+ */
+ private String generateKey(int rowIndex, int columnIndex) {
+ return rowIndex + "-" + columnIndex;
+ }
+
+ /**
+ * Check valid focus id.
+ *
+ * @return the FocusID if it is valid, null otherwise.
+ */
+ public String checkValidFocusID() {
+
+ cg_focus_id_correlation.setType(ControlGroupType.NONE);
+
+ // CHECK THE FOCUS ID VALUE
+ String focusID = field_list_focus_id_correlation.getSelectedItemText();
+
+ if (focusID == null || focusID.isEmpty()) {
+
+ String msgError = "Could not execute a valid Analysis.";
+
+ if (selectedAreas == null || selectedAreas.isEmpty()) {
+ msgError += " Please select another parameters computation";
+ } else {
+ msgError += " Select at least the Area of your FARM";
+ }
+
+ showAlert(msgError, AlertType.ERROR, true, uib_vp_correlation_results_container);
+ cg_focus_id_correlation.setType(ControlGroupType.ERROR);
+ return null;
+ }
+
+ return focusID;
+ }
+
+ /**
+ * Call scatter.
+ *
+ * @param rowIndex
+ * the row index
+ * @param columnIndex
+ * the column index
+ * @param button
+ * the button
+ */
+ private void callScatter(int rowIndex, int columnIndex, HTML button) {
+
+ String focusID = checkValidFocusID();
+
+ if (focusID == null)
+ return;
+
+ GWT.log("Called ScatterChart at rowIndex: " + rowIndex + ", columnIndex: " + columnIndex);
+ List selectedKPI = getKPIForIndexes(rowIndex, columnIndex);
+ GWT.log("Selected KPI: " + selectedKPI);
+ PerformFishAnalyticsController.eventBus
+ .fireEvent(new CallAlgorithmEvent(DataMinerAlgorithms.SCATTER, focusID, selectedKPI, null));
+ }
+
+ private static native void saveFilePDF(CorrelationPanelResult chart, String filename, String tabTitle,
+ String tabDescr, int requestId, int outputNumber)/*-{
+ var that = this;
+ console.log('saveFilePDF()');
+
+ var tTitle = tabTitle;
+ var tDescr = tabDescr;
+
+ var pdoc = new jsPDF("p", "mm", "a4");
+ pdoc.setProperties({
+ title : 'PerformFish ' + tTitle,
+ subject : ' Results',
+ author : 'PerformFish',
+ keywords : 'PerformFish',
+ creator : 'D4Science'
+ });
+
+ var lMargin = 15; //left margin in mm
+ var rMargin = 15; //right margin in mm
+ var tMargin = 15; //top margin in mm
+ var bMargin = 15; //bottom margin in mm
+ var pdfWidthInMM = 210; // width of A4 in mm
+ var pdfHeightInMM = 297; // height of A4 in mm
+ var pageCenter = pdfWidthInMM / 2;
+
+ pdoc.setFontSize(24);
+ var title = "PerformFish " + tTitle;
+ var titleHeight = pdoc.getLineHeight(title) / pdoc.internal.scaleFactor
+ var xPos = lMargin;
+ var yPos = tMargin;
+ pdoc.text(title, pageCenter, yPos, 'center');
+ yPos += titleHeight;
+
+ pdoc.setFontSize(10);
+ var lineHeight = pdoc.getLineHeight(tDescr) / pdoc.internal.scaleFactor
+ var splittedAnalysisDescription = pdoc.splitTextToSize(tDescr,
+ (pdfWidthInMM - lMargin - rMargin));
+ var lines = splittedAnalysisDescription.length // splitted text is a string array
+ var analysisDescriptionHeight = lines * lineHeight
+
+ pdoc.text(splittedAnalysisDescription, xPos, yPos, 'left');
+ yPos += analysisDescriptionHeight;
+
+ yPos += 4;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text("Parameters:", xPos, yPos, 'left');
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+ yPos += 4;
+
+ var correlationParametersInputKPIs = $doc
+ .getElementById('CorrelationParameterInputKPIs');
+
+ console.log('InputKPIs: ' + correlationParametersInputKPIs);
+
+ pdoc.autoTable({
+ theme : 'plain',
+ startY : yPos,
+ pageBreak : 'auto',
+ columnStyles : {
+ 0 : {
+ halign : 'left',
+ fillColor : [ 211, 225, 241 ]
+ }
+ },
+ html : correlationParametersInputKPIs
+
+ });
+
+ //head : null,
+ // body : [
+ // [ 'Parameters',
+ // correlationParametersInputKPIs ]
+ // ]
+
+ yPos = pdoc.previousAutoTable.finalY + 6;
+
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text("CORRELATION Matrix:", xPos, yPos, 'left');
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+ yPos += 4;
+
+ console.log('OutputNumber: ' + outputNumber);
+
+ for (var i = 1; i <= outputNumber; i++) {
+
+ var outputId = 'OutputId_' + requestId + '_' + i;
+ console.log('OutputId: ' + outputId);
+
+ var resultElement = $doc.getElementById(outputId);
+
+ console.log('Result Element: ' + resultElement);
+ var resultType = resultElement.className;
+
+ console.log('Result Element className: ' + resultType);
+
+ if (typeof resultType !== 'undefined' && resultType !== null
+ && resultType !== '') {
+
+ if (resultType == 'fixedtable' || resultType == 'simpletable') {
+ console.log('Result Type csv: ' + i);
+ console.log('Result Content: ' + resultElement.innerHTML);
+
+ var checkColor = function(data) {
+ if (data.section === 'body') {
+ console.log(data);
+ if (typeof data.cell !== 'undefined'
+ && data.cell !== null) {
+ if (typeof data.cell.raw !== 'undefined'
+ && data.cell.raw !== null) {
+ console.log(data.cell.raw.innerHTML);
+ var positive = 'rgb(255, 68, 45)';
+ var negative = 'rgb(173, 216, 230)';
+ var nonsignificant = 'rgb(230, 223, 0)';
+
+ if (data.cell.raw.innerHTML
+ .indexOf(positive) >= 0) {
+ data.cell.styles.fillColor = [ 255, 68,
+ 45 ];
+ } else {
+ if (data.cell.raw.innerHTML
+ .indexOf(negative) >= 0) {
+ data.cell.styles.fillColor = [ 173,
+ 216, 230 ];
+ } else {
+ if (data.cell.raw.innerHTML
+ .indexOf(nonsignificant) >= 0) {
+ data.cell.styles.fillColor = [
+ 230, 223, 0 ];
+ } else {
+
+ }
+
+ }
+
+ }
+ }
+ }
+
+ }
+ };
+
+ pdoc.autoTable({
+ theme : 'grid',
+ startY : yPos,
+ pageBreak : 'auto',
+ bodyStyles : {
+ fontSize : 9
+ },
+ didParseCell : checkColor,
+ html : resultElement
+ });
+
+ yPos = pdoc.previousAutoTable.finalY + 6;
+ } else {
+ if (resultType == 'image') {
+ console.log('Result Type image: ' + i);
+ var childrenTable = outputNumber.children;
+ var secondDiv = childrenTable[0].rows[1].cells[0];
+ var imageElement = secondDiv
+ .getElementsByTagName('img').item(0);
+ console.log('Image element: ' + imageElement);
+ pdoc.addImage(imageElement, lMargin, yPos);
+ console.log('Image Height: ' + imageElement.height);
+ yPos += (imageElement.height * 0.26458333);
+
+ } else {
+ console.log('Result Type unknow: ' + i);
+ }
+
+ }
+ } else {
+ console.log('Result Type is undefined:' + i);
+ }
+
+ if (i == outputNumber) {
+
+ } else {
+ if (pdfHeightInMM - yPos < pdfHeightInMM / 7) {
+ pdoc.addPage();
+ yPos = tMargin; // Restart position
+ }
+ }
+
+ }
+
+ var focusIDElement = $doc
+ .getElementById('field_list_focus_id_correlation');
+ console.log('FocusID Element: ' + focusIDElement);
+ var selectedIndex = focusIDElement.selectedIndex;
+ if (selectedIndex > -1) {
+ var value = focusIDElement[selectedIndex].innerText;
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+ pdoc.text("Focus ID: "+value, xPos, yPos, 'left');
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+ yPos += 4;
+
+ }
+
+ var numberOfPages = pdoc.internal.getNumberOfPages()
+ console.log('NumberOfPages: ' + numberOfPages);
+ for (var k = 1; k <= numberOfPages; k++) {
+ pdoc.setPage(k);
+ console.log('CurrentPage: ' + k);
+ var footner = 'Page ' + k + "/" + numberOfPages;
+ pdoc.text(footner, pageCenter, pdfHeightInMM - 7, 'center');
+
+ }
+
+ console.log('Done');
+
+ pdoc.save(filename);
+
+ }-*/;
+
+
+}
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/AnalyticsPanelResult.ui.xml b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/CorrelationPanelResult.ui.xml
similarity index 95%
rename from src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/AnalyticsPanelResult.ui.xml
rename to src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/CorrelationPanelResult.ui.xml
index 4881ce1..5fed12b 100644
--- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/AnalyticsPanelResult.ui.xml
+++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/CorrelationPanelResult.ui.xml
@@ -8,7 +8,10 @@
-
+
+
+
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/ScatterPanelResult.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/ScatterPanelResult.java
index 577642e..dbb4546 100644
--- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/ScatterPanelResult.java
+++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/ScatterPanelResult.java
@@ -12,6 +12,7 @@ import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsS
import org.gcube.portlets.user.performfishanalytics.client.controllers.PerformFishAnalyticsViewController;
import org.gcube.portlets.user.performfishanalytics.client.resources.PerformFishResources;
import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon;
+import org.gcube.portlets.user.performfishanalytics.shared.FileContentType;
import org.gcube.portlets.user.performfishanalytics.shared.KPI;
import org.gcube.portlets.user.performfishanalytics.shared.OutputFile;
import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile;
@@ -32,19 +33,22 @@ import com.google.gwt.resources.client.TextResource;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.ComplexPanel;
+import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Panel;
public class ScatterPanelResult {
private PerformFishAnalyticsViewController viewController;
- private int requestId;
- private int outputIteration = 0;
- private int outputNumber = 0;
-
- public ScatterPanelResult(int reqId,PerformFishAnalyticsViewController viewController,
+ private int requestId = 0;
+ private int outputIteration = 1;
+ private int outputNumber = 1;
+ private Button savePDFButton;
+
+ public ScatterPanelResult(int reqId, PerformFishAnalyticsViewController viewController,
final DataMinerAlgorithms algorithm, String focusID, List inputKPI, final List outputKPI) {
- this.requestId=reqId;
+ GWT.log("RequestID: " + reqId);
+ requestId = reqId;
this.viewController = viewController;
TextResource algDescr = PerformFishResources.INSTANCE.batch_SCATTER();
@@ -60,21 +64,21 @@ public class ScatterPanelResult {
HorizontalPanel res = new HorizontalPanel();
- Button savePDFButton = new Button();
+ savePDFButton = new Button();
savePDFButton.getElement().getStyle().setMargin(10, Unit.PX);
savePDFButton.setIcon(IconType.PRINT);
savePDFButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
- saveFilePDF(algorithm.getId(), tabTitle, tabTitle, tabDescr, requestId,outputIteration, outputNumber);
+ saveFilePDF(algorithm.getId(), tabTitle, tabTitle, tabDescr, requestId, outputIteration, outputNumber);
// dmResponse.getListOutput().size()
}
});
+ savePDFButton.setVisible(false);
res.add(savePDFButton);
submitRequestPanel.addWidget(res);
- int oIteration = 1;
if (inputKPI.get(0) == null || inputKPI.get(1) == null) {
submitRequestPanel
@@ -85,13 +89,17 @@ public class ScatterPanelResult {
// again");
}
- String titleScatter = "KPI: " + inputKPI.get(0).getName() + " vs " + inputKPI.get(1).getName();
- submitRequestPanel.setTheTitle(titleScatter);
+ String title = "KPI: " + inputKPI.get(0).getName() + " vs " + inputKPI.get(1).getName();
+ HTML toBigTitle = new HTML(title);
+ toBigTitle.getElement().setId("KPI_Scatter_" + requestId + "_" + outputIteration);
+ toBigTitle.getElement().addClassName("to-big-title");
+ submitRequestPanel.addWidget(toBigTitle);
+ HorizontalPanel hp = new HorizontalPanel();
+ hp.getElement().addClassName("ext-horizontal-panel");
callDataMinerServiceForChart(viewController.getPerformFishResponse(), POPULATION_LEVEL.BATCH, inputKPI,
- outputKPI, algorithm, focusID, submitRequestPanel, submitRequestPanel.getContainerPanel(), tab,
- oIteration);
- outputIteration = oIteration;
+ outputKPI, algorithm, focusID, submitRequestPanel, hp, tab, outputIteration);
+ submitRequestPanel.addWidget(hp);
}
@@ -191,9 +199,15 @@ public class ScatterPanelResult {
});
}
+ private String getOutputId(int oIteration, String title) {
+ String outputId = "OutputId_" + requestId + "_" + oIteration + "_" + 1;
+ return outputId;
+
+ }
+
private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
final DataMinerAlgorithms chartType, List inputKPIs, List outputKPIs, final String focusID,
- final Panel container, boolean displayError, int oIteration) {
+ final Panel container, boolean displayError, final int oIteration) {
String title = displayError ? "No results " : "";
@@ -205,17 +219,13 @@ public class ScatterPanelResult {
container.add(alert);
return;
}
-
+
+ savePDFButton.setVisible(true);
final String toTitle = title;
- outputNumber = dmResponse.getListOutput().size();
-
- int oNumber = 0;
-
- for (final OutputFile outputFile : dmResponse.getListOutput()) {
- oNumber++;
- final String outputId = "OutputId_" + requestId+"_"+oIteration + "_" + oNumber;
+ for (OutputFile outputFile : dmResponse.getListOutput()) {
+ final FileContentType fileContentType = outputFile.getDataType();
switch (outputFile.getDataType()) {
case IMAGE:
PerformFishAnalyticsServiceAsync.Util.getInstance().getImageFile(outputFile,
@@ -234,11 +244,11 @@ public class ScatterPanelResult {
public void onSuccess(String base64Content) {
String title = toTitle;
- ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
+ String outputId = getOutputId(oIteration, title);
+ ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showImage(base64Content);
container.add(showResult);
-
}
});
break;
@@ -262,7 +272,8 @@ public class ScatterPanelResult {
String title = toTitle;
- ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
+ String outputId = getOutputId(oIteration, title);
+ ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showCSVFile(result, cssTableStyle);
container.add(showResult);
}
@@ -277,8 +288,6 @@ public class ScatterPanelResult {
}
-
-
/**
* Remove the spinner if all DM responses are returned.
*
@@ -301,7 +310,7 @@ public class ScatterPanelResult {
int requestId, int outputIteration, int outputNumber)/*-{
var that = this;
console.log('saveFilePDF()');
- console.log('requestId: '+requestId);
+ console.log('requestId: ' + requestId);
console.log('OutputIteration: ' + outputIteration);
console.log('OutputNumber:' + outputNumber);
@@ -349,9 +358,32 @@ public class ScatterPanelResult {
for (var i = 1; i <= outputIteration; i++) {
+ var kpiId = 'KPI_Scatter_' + requestId + '_' + i;
+ console.log('kpiId: ' + kpiId);
+
+ var kpiName = $doc.getElementById(kpiId);
+
+ yPos += 2;
+ pdoc.setFontSize(14);
+ pdoc.setFontType("bold");
+
+ var kpiText = kpiName.textContent;
+ var kpiHeight = pdoc.getLineHeight(kpiText)
+ / pdoc.internal.scaleFactor;
+ var splittedKpiName = pdoc.splitTextToSize(kpiText, (pdfWidthInMM
+ - lMargin - rMargin));
+ var kpiLines = splittedKpiName.length; // splitted text is a string array
+ var kpiLinesHeight = kpiLines * kpiHeight;
+ pdoc.text(splittedKpiName, xPos, yPos, 'left');
+ yPos += kpiLinesHeight;
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
for (var j = 1; j <= outputNumber; j++) {
- var outputId = 'OutputId_'+requestId+'_'+ i + '_' + j;
+ var outputId = 'OutputId_' + requestId + '_' + i + '_' + j;
console.log('OutputId: ' + outputId);
var resultOutputNumber = $doc.getElementById(outputId);
@@ -369,6 +401,19 @@ public class ScatterPanelResult {
// foo could get resolved and it's defined
var childrenTable = resultOutputNumber.children;
+ var titleCurrentTable = childrenTable[0].rows[0].cells[0];
+ console.log('Title current table: '
+ + titleCurrentTable.textContent);
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text(titleCurrentTable.textContent, xPos, yPos,
+ 'left');
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
var secondDiv = childrenTable[0].rows[1].cells[0];
var secondTable = secondDiv.children[0].children[0];
@@ -389,6 +434,20 @@ public class ScatterPanelResult {
if (resultType == 'image') {
console.log('Result Type image: ' + i);
var childrenTable = resultOutputNumber.children;
+
+ var titleCurrentImage = childrenTable[0].rows[0].cells[0];
+ console.log('Title current image: '
+ + titleCurrentImage.textContent);
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text(titleCurrentImage.textContent, xPos,
+ yPos, 'left');
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
var secondDiv = childrenTable[0].rows[1].cells[0];
var imageElement = secondDiv.getElementsByTagName(
'img').item(0);
@@ -407,6 +466,26 @@ public class ScatterPanelResult {
}
}
+
+ if (i == outputNumber) {
+
+ } else {
+ if (pdfHeightInMM - yPos < pdfHeightInMM / 4) {
+ pdoc.addPage();
+ yPos = tMargin; // Restart position
+ }
+ }
+
+ }
+
+ var numberOfPages=pdoc.internal.getNumberOfPages()
+ console.log('NumberOfPages: ' + numberOfPages);
+ for (var k = 1; k <= numberOfPages; k++) {
+ pdoc.setPage(k);
+ console.log('CurrentPage: ' + k);
+ var footner = 'Page ' + k + "/"+numberOfPages;
+ pdoc.text(footner, pageCenter, pdfHeightInMM - 7, 'center');
+
}
console.log('Done');
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/SpeedometerPanelResult.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/SpeedometerPanelResult.java
index 6f13715..7e500f9 100644
--- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/SpeedometerPanelResult.java
+++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/SpeedometerPanelResult.java
@@ -12,6 +12,7 @@ import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsS
import org.gcube.portlets.user.performfishanalytics.client.controllers.PerformFishAnalyticsViewController;
import org.gcube.portlets.user.performfishanalytics.client.resources.PerformFishResources;
import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon;
+import org.gcube.portlets.user.performfishanalytics.shared.FileContentType;
import org.gcube.portlets.user.performfishanalytics.shared.KPI;
import org.gcube.portlets.user.performfishanalytics.shared.OutputFile;
import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile;
@@ -41,11 +42,13 @@ public class SpeedometerPanelResult {
private PerformFishAnalyticsViewController viewController;
private int requestId;
private int outputIteration = 0;
- private int outputNumber = 0;
-
- public SpeedometerPanelResult(int reqId,PerformFishAnalyticsViewController viewController,
+ private int outputNumber = 1;
+ private Button savePDFButton;
+
+ public SpeedometerPanelResult(int reqId, PerformFishAnalyticsViewController viewController,
final DataMinerAlgorithms algorithm, String focusID, List inputKPI, final List outputKPI) {
- this.requestId=reqId;
+ GWT.log("RequestID: " + reqId);
+ requestId = reqId;
this.viewController = viewController;
TextResource algDescr = PerformFishResources.INSTANCE.batch_SPEEDOMETER();
@@ -61,17 +64,18 @@ public class SpeedometerPanelResult {
HorizontalPanel res = new HorizontalPanel();
- Button savePDFButton = new Button();
+ savePDFButton = new Button();
savePDFButton.getElement().getStyle().setMargin(10, Unit.PX);
savePDFButton.setIcon(IconType.PRINT);
savePDFButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
- saveFilePDF(algorithm.getId(), tabTitle, tabTitle, tabDescr, requestId,outputIteration, outputNumber);
+ saveFilePDF(algorithm.getId(), tabTitle, tabTitle, tabDescr, requestId, outputIteration, outputNumber);
}
});
-
+ savePDFButton.setVisible(false);
+
res.add(savePDFButton);
submitRequestPanel.addWidget(res);
int oIteration = 0;
@@ -81,6 +85,7 @@ public class SpeedometerPanelResult {
oIteration++;
String title = "KPI: " + kpi.getName();
HTML toBigTitle = new HTML(title);
+ toBigTitle.getElement().setId("KPI_Speedometer_" + requestId + "_" + oIteration);
toBigTitle.getElement().addClassName("to-big-title");
submitRequestPanel.addWidget(toBigTitle);
HorizontalPanel hp = new HorizontalPanel();
@@ -191,9 +196,15 @@ public class SpeedometerPanelResult {
});
}
+ private String getOutputId(int oIteration, String title) {
+ String outputId = "OutputId_" + requestId + "_" + oIteration + "_" + 1;
+ return outputId;
+
+ }
+
private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
final DataMinerAlgorithms chartType, List inputKPIs, List outputKPIs, final String focusID,
- final Panel container, boolean displayError, int oIteration) {
+ final Panel container, boolean displayError, final int oIteration) {
String title = displayError ? "No results " : "";
@@ -205,16 +216,13 @@ public class SpeedometerPanelResult {
container.add(alert);
return;
}
-
+
+ savePDFButton.setVisible(true);
+
final String toTitle = title;
- outputNumber = dmResponse.getListOutput().size();
-
- int oNumber = 0;
-
- for (final OutputFile outputFile : dmResponse.getListOutput()) {
- oNumber++;
- final String outputId = "OutputId_" +requestId+"_"+ oIteration + "_" + oNumber;
+ for (OutputFile outputFile : dmResponse.getListOutput()) {
+ final FileContentType fileContentType = outputFile.getDataType();
switch (outputFile.getDataType()) {
case IMAGE:
@@ -238,7 +246,8 @@ public class SpeedometerPanelResult {
title += "Selected Batch ID: " + focusID + "
";
title += "Normalized with respect to all batches in the VRE";
- ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
+ String outputId = getOutputId(oIteration, title);
+ ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showImage(base64Content);
container.add(showResult);
@@ -265,7 +274,8 @@ public class SpeedometerPanelResult {
String title = toTitle;
- ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
+ String outputId = getOutputId(oIteration, title);
+ ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showCSVFile(result, cssTableStyle);
container.add(showResult);
}
@@ -280,8 +290,6 @@ public class SpeedometerPanelResult {
}
-
-
/**
* Remove the spinner if all DM responses are returned.
*
@@ -304,7 +312,7 @@ public class SpeedometerPanelResult {
int requestId, int outputIteration, int outputNumber)/*-{
var that = this;
console.log('saveFilePDF()');
- console.log('requestId: '+requestId);
+ console.log('requestId: ' + requestId);
console.log('OutputIteration: ' + outputIteration);
console.log('OutputNumber:' + outputNumber);
@@ -352,9 +360,32 @@ public class SpeedometerPanelResult {
for (var i = 1; i <= outputIteration; i++) {
+ var kpiId = 'KPI_Speedometer_' + requestId + '_' + i;
+ console.log('kpiId: ' + kpiId);
+
+ var kpiName = $doc.getElementById(kpiId);
+
+ yPos += 2;
+ pdoc.setFontSize(14);
+ pdoc.setFontType("bold");
+
+ var kpiText = kpiName.textContent;
+ var kpiHeight = pdoc.getLineHeight(kpiText)
+ / pdoc.internal.scaleFactor;
+ var splittedKpiName = pdoc.splitTextToSize(kpiText, (pdfWidthInMM
+ - lMargin - rMargin));
+ var kpiLines = splittedKpiName.length; // splitted text is a string array
+ var kpiLinesHeight = kpiLines * kpiHeight;
+ pdoc.text(splittedKpiName, xPos, yPos, 'left');
+ yPos += kpiLinesHeight;
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
for (var j = 1; j <= outputNumber; j++) {
- var outputId = 'OutputId_'+requestId+'_'+ i + '_' + j;
+ var outputId = 'OutputId_' + requestId + '_' + i + '_' + j;
console.log('OutputId: ' + outputId);
var resultOutputNumber = $doc.getElementById(outputId);
@@ -372,6 +403,19 @@ public class SpeedometerPanelResult {
// foo could get resolved and it's defined
var childrenTable = resultOutputNumber.children;
+ var titleCurrentTable = childrenTable[0].rows[0].cells[0];
+ console.log('Title current table: '
+ + titleCurrentTable.textContent);
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text(titleCurrentTable.textContent, xPos, yPos,
+ 'left');
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
var secondDiv = childrenTable[0].rows[1].cells[0];
var secondTable = secondDiv.children[0].children[0];
@@ -392,6 +436,20 @@ public class SpeedometerPanelResult {
if (resultType == 'image') {
console.log('Result Type image: ' + i);
var childrenTable = resultOutputNumber.children;
+
+ var titleCurrentImage = childrenTable[0].rows[0].cells[0];
+ console.log('Title current image: '
+ + titleCurrentImage.textContent);
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text(titleCurrentImage.textContent, xPos,
+ yPos, 'left');
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
var secondDiv = childrenTable[0].rows[1].cells[0];
var imageElement = secondDiv.getElementsByTagName(
'img').item(0);
@@ -410,6 +468,26 @@ public class SpeedometerPanelResult {
}
}
+
+ if (i == outputNumber) {
+
+ } else {
+ if (pdfHeightInMM - yPos < pdfHeightInMM / 4) {
+ pdoc.addPage();
+ yPos = tMargin; // Restart position
+ }
+ }
+
+ }
+
+ var numberOfPages=pdoc.internal.getNumberOfPages()
+ console.log('NumberOfPages: ' + numberOfPages);
+ for (var k = 1; k <= numberOfPages; k++) {
+ pdoc.setPage(k);
+ console.log('CurrentPage: ' + k);
+ var footner = 'Page ' + k + "/"+numberOfPages;
+ pdoc.text(footner, pageCenter, pdfHeightInMM - 7, 'center');
+
}
console.log('Done');
@@ -417,4 +495,5 @@ public class SpeedometerPanelResult {
pdoc.save(filename);
}-*/;
+
}
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/SubmitRequestPanel.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/SubmitRequestPanel.java
index bb90e1f..7484341 100644
--- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/SubmitRequestPanel.java
+++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/SubmitRequestPanel.java
@@ -91,6 +91,11 @@ public class SubmitRequestPanel extends Composite {
else
theTitle.setHTML("");
}
+
+
+ public void addTheTitleClassName(String className){
+ theTitle.getElement().addClassName(className);
+ }
/**
* Gets the panel.
diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/SynopticTablePanelResult.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/SynopticTablePanelResult.java
index 535cdc0..45a6ace 100644
--- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/SynopticTablePanelResult.java
+++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewbinder/SynopticTablePanelResult.java
@@ -11,6 +11,7 @@ import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsS
import org.gcube.portlets.user.performfishanalytics.client.controllers.PerformFishAnalyticsViewController;
import org.gcube.portlets.user.performfishanalytics.client.resources.PerformFishResources;
import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon;
+import org.gcube.portlets.user.performfishanalytics.shared.FileContentType;
import org.gcube.portlets.user.performfishanalytics.shared.KPI;
import org.gcube.portlets.user.performfishanalytics.shared.OutputFile;
import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile;
@@ -40,12 +41,15 @@ public class SynopticTablePanelResult {
private PerformFishAnalyticsViewController viewController;
private int requestId;
- private int outputIteration = 0;
+ private int outputIteration = 1;
private int outputNumber = 0;
+ private Button savePDFButton;
+
public SynopticTablePanelResult(int reqId, PerformFishAnalyticsViewController viewController,
PerformFishResponse performFishResponse, final Map> performFishRequestParameters) {
- this.requestId = reqId;
+ GWT.log("RequestID: " + reqId);
+ requestId = reqId;
this.viewController = viewController;
String batchTableURL = performFishResponse.getMapParameters().get(PerformFishAnalyticsConstant.BATCHES_TABLE);
@@ -103,7 +107,7 @@ public class SynopticTablePanelResult {
PerformFishResources.INSTANCE.synopticTable().getText(), submitRequestPanel);
HorizontalPanel res = new HorizontalPanel();
- Button savePDFButton = new Button();
+ savePDFButton = new Button();
savePDFButton.getElement().getStyle().setMargin(10, Unit.PX);
savePDFButton.setIcon(IconType.PRINT);
savePDFButton.addClickHandler(new ClickHandler() {
@@ -114,10 +118,10 @@ public class SynopticTablePanelResult {
// dmResponse.getListOutput().size()
}
});
+ savePDFButton.setVisible(false);
res.add(savePDFButton);
submitRequestPanel.addWidget(res);
- outputIteration=1;
final HTMLPanel panelContainer = submitRequestPanel.getContainerPanel();
@@ -144,7 +148,7 @@ public class SynopticTablePanelResult {
// field_unary_algorithm.setVisible(true);
GWT.log("I'm displaying: " + dmResponse);
displayOutputFilesAsStaticEntities(dmResponse, toFinalChartType, null, null, null,
- panelContainer, false, 1);
+ panelContainer, false, outputIteration);
}
@Override
@@ -152,7 +156,7 @@ public class SynopticTablePanelResult {
loaderIcon.setVisible(false);
checkTabSpinner(submitRequestPanel, tab);
displayOutputFilesAsStaticEntities(null, toFinalChartType, null, null, null, panelContainer,
- true, 1);
+ true, outputIteration);
}
});
@@ -177,9 +181,20 @@ public class SynopticTablePanelResult {
}
}
+ private String getOutputId(int oIteration, boolean isLegend) {
+ String outputId;
+ if (isLegend) {
+ outputId = "OutputId_" + requestId + "_" + oIteration + "_" + 1;
+ } else {
+ outputNumber++;
+ outputId = "OutputId_" + requestId + "_" + oIteration + "_" + outputNumber;
+ }
+ return outputId;
+ }
+
private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
final DataMinerAlgorithms chartType, List inputKPIs, List outputKPIs, final String focusID,
- final Panel container, boolean displayError, int oIteration) {
+ final Panel container, boolean displayError, final int oIteration) {
String title = displayError ? "No results " : "";
@@ -192,15 +207,15 @@ public class SynopticTablePanelResult {
return;
}
+ savePDFButton.setVisible(false);
+
final String toTitle = title;
+
+ outputNumber = 1;
- outputNumber = dmResponse.getListOutput().size();
+ for (OutputFile outputFile : dmResponse.getListOutput()) {
- int oNumber = 0;
-
- for (final OutputFile outputFile : dmResponse.getListOutput()) {
- oNumber++;
- final String outputId = "OutputId_" + requestId + "_" + oIteration + "_" + oNumber;
+ final FileContentType fileContentType = outputFile.getDataType();
switch (outputFile.getDataType()) {
case IMAGE:
@@ -221,7 +236,8 @@ public class SynopticTablePanelResult {
String title = toTitle;
- ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
+ String outputId = getOutputId(oIteration, false);
+ ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showImage(base64Content);
container.add(showResult);
@@ -252,14 +268,16 @@ public class SynopticTablePanelResult {
case PERFORMFISH_SYNOPTICTABLE_BATCH_HATCHERY:
case PERFORMFISH_SYNOPTICTABLE_BATCH_PREGROW:
+ String outputId;
if (!result.getFileName().contains("legend")) {
- cssTableStyle = "synoptictable-batch";
+ cssTableStyle = "synoptictable-farm";
+ outputId = getOutputId(oIteration, false);
} else {
cssTableStyle = "simpletable-synoptic";
+ outputId = getOutputId(oIteration, true);
}
- ShowResult showResultSin = new ShowResult(outputId, title,
- outputFile.getDataType());
+ ShowResult showResultSin = new ShowResult(outputId, title, fileContentType);
showResultSin.showCSVFile(result, cssTableStyle);
displayingOrderedSynopticTable(dmResponse, result.getFileName(), container,
showResultSin);
@@ -271,7 +289,9 @@ public class SynopticTablePanelResult {
break;
}
// ALL OTHER CASES
- ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
+
+ String outputId = getOutputId(oIteration, false);
+ ShowResult showResult = new ShowResult(outputId, title, fileContentType);
showResult.showCSVFile(result, cssTableStyle);
container.add(showResult);
}
@@ -356,7 +376,7 @@ public class SynopticTablePanelResult {
//pdoc.text("Analysis:", xPos, yPos, 'left');
yPos += 6;
- for (var i = 1; i <= outputIteration; i++) {
+ for (var i = 1; i <= outputIteration; i++) {
for (var j = 1; j <= outputNumber; j++) {
@@ -378,11 +398,85 @@ public class SynopticTablePanelResult {
// foo could get resolved and it's defined
var childrenTable = resultOutputNumber.children;
+ var titleCurrentTable = childrenTable[0].rows[0].cells[0];
+ console.log('Title current table: '
+ + titleCurrentTable.textContent);
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text(titleCurrentTable.textContent, xPos, yPos,
+ 'left');
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
var secondDiv = childrenTable[0].rows[1].cells[0];
var secondTable = secondDiv.children[0].children[0];
console.log('CSV SecondTable: ' + secondTable);
+ var checkColor = function(data) {
+ if (data.section === 'body') {
+ console.log(data);
+ var good = '
';
+ var normal = '
';
+ var bad = '
';
+
+ if (typeof data.cell !== 'undefined'
+ && data.cell !== null) {
+ if (typeof data.cell.raw !== 'undefined'
+ && data.cell.raw !== null) {
+
+ console.log(data.cell.raw.innerHTML);
+ if (data.cell.raw.innerHTML === good) {
+ console.log('good');
+ var posIW = (data.cell.x + (data.cell.width / 2)-2);
+ var posIH = (data.cell.y + (data.cell.height / 2)-2);
+ var greenImg = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD//gATQ3JlYXRlZCB3aXRoIEdJTVD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wgARCAAKAAoDAREAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAb/xAAWAQEBAQAAAAAAAAAAAAAAAAAACAn/2gAMAwEAAhADEAAAAbSM8+wB/8QAFBABAAAAAAAAAAAAAAAAAAAAIP/aAAgBAQABBQIf/8QAFBEBAAAAAAAAAAAAAAAAAAAAIP/aAAgBAwEBPwEf/8QAFBEBAAAAAAAAAAAAAAAAAAAAIP/aAAgBAgEBPwEf/8QAFBABAAAAAAAAAAAAAAAAAAAAIP/aAAgBAQAGPwIf/8QAFBABAAAAAAAAAAAAAAAAAAAAIP/aAAgBAQABPyEf/9oADAMBAAIAAwAAABAAD//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQMBAT8QH//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQIBAT8QH//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEAAT8QH//Z'
+ pdoc.addImage(greenImg, 'JPEG', posIW, posIH, 4, 4);
+ //pdoc.setFontSize(10);
+ //pdoc.setFontType("normal");
+ //var posW = (data.cell.x + (data.cell.width / 2));
+ //var posH = (data.cell.y + (data.cell.height / 2));
+ //pdoc.text('G', posW, posH,'center');
+ } else {
+ if (data.cell.raw.innerHTML === normal) {
+ console.log('normal');
+ var posIW = (data.cell.x + (data.cell.width / 2)-2);
+ var posIH = (data.cell.y + (data.cell.height / 2)-2);
+ var yellowImg = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD//gATQ3JlYXRlZCB3aXRoIEdJTVD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wgARCAAKAAoDAREAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAn/xAAWAQEBAQAAAAAAAAAAAAAAAAAABwr/2gAMAwEAAhADEAAAAbEZ/wCqAD//xAAUEAEAAAAAAAAAAAAAAAAAAAAg/9oACAEBAAEFAh//xAAUEQEAAAAAAAAAAAAAAAAAAAAg/9oACAEDAQE/AR//xAAUEQEAAAAAAAAAAAAAAAAAAAAg/9oACAECAQE/AR//xAAUEAEAAAAAAAAAAAAAAAAAAAAg/9oACAEBAAY/Ah//xAAUEAEAAAAAAAAAAAAAAAAAAAAg/9oACAEBAAE/IR//2gAMAwEAAgADAAAAEAAP/8QAFBEBAAAAAAAAAAAAAAAAAAAAIP/aAAgBAwEBPxAf/8QAFBEBAAAAAAAAAAAAAAAAAAAAIP/aAAgBAgEBPxAf/8QAFBABAAAAAAAAAAAAAAAAAAAAIP/aAAgBAQABPxAf/9k='
+ pdoc.addImage(yellowImg, 'JPEG', posIW, posIH, 4, 4);
+ //pdoc.setFontSize(10);
+ //pdoc.setFontType("normal");
+ //var posW = (data.cell.x + (data.cell.width / 2));
+ //var posH = (data.cell.y + (data.cell.height / 2));
+ //pdoc.text('N', posW, posH,'center');
+ } else {
+ if (data.cell.raw.innerHTML === bad) {
+ console.log('bad');
+ var posIW = (data.cell.x + (data.cell.width / 2)-2);
+ var posIH = (data.cell.y + (data.cell.height / 2)-2);
+ var redImg = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD//gATQ3JlYXRlZCB3aXRoIEdJTVD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wgARCAAKAAoDAREAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAj/xAAWAQEBAQAAAAAAAAAAAAAAAAAACAn/2gAMAwEAAhADEAAAAYvlPfwAf//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEAAQUCH//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQMBAT8BH//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQIBAT8BH//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEABj8CH//EABQQAQAAAAAAAAAAAAAAAAAAACD/2gAIAQEAAT8hH//aAAwDAQACAAMAAAAQAA//xAAUEQEAAAAAAAAAAAAAAAAAAAAg/9oACAEDAQE/EB//xAAUEQEAAAAAAAAAAAAAAAAAAAAg/9oACAECAQE/EB//xAAUEAEAAAAAAAAAAAAAAAAAAAAg/9oACAEBAAE/EB//2Q=='
+ pdoc.addImage(redImg, 'JPEG', posIW, posIH, 4, 4);
+ //pdoc.setFontSize(10);
+ //pdoc.setFontType("normal");
+ //var posW = (data.cell.x + (data.cell.width / 2));
+ //var posH = (data.cell.y + (data.cell.height / 2));
+ //pdoc.text('B', posW, posH,'center');
+ } else {
+
+ }
+
+ }
+
+ }
+ }
+ }
+
+ }
+ };
+
pdoc.autoTable({
theme : 'grid',
startY : yPos,
@@ -390,6 +484,7 @@ public class SynopticTablePanelResult {
bodyStyles : {
fontSize : 9
},
+ didDrawCell : checkColor,
html : secondTable
});
@@ -398,6 +493,20 @@ public class SynopticTablePanelResult {
if (resultType == 'image') {
console.log('Result Type image: ' + i);
var childrenTable = resultOutputNumber.children;
+
+ var titleCurrentImage = childrenTable[0].rows[0].cells[0];
+ console.log('Title current image: '
+ + titleCurrentImage.textContent);
+ yPos += 2;
+ pdoc.setFontSize(10);
+ pdoc.setFontType("bold");
+ pdoc.text(titleCurrentImage.textContent, xPos,
+ yPos, 'left');
+ yPos += 6;
+
+ pdoc.setFontSize(10);
+ pdoc.setFontType("normal");
+
var secondDiv = childrenTable[0].rows[1].cells[0];
var imageElement = secondDiv.getElementsByTagName(
'img').item(0);
@@ -416,6 +525,26 @@ public class SynopticTablePanelResult {
}
}
+
+ if (i == outputNumber) {
+
+ } else {
+ if (pdfHeightInMM - yPos < pdfHeightInMM / 7) {
+ pdoc.addPage();
+ yPos = tMargin; // Restart position
+ }
+ }
+
+ }
+
+ var numberOfPages = pdoc.internal.getNumberOfPages();
+ console.log('NumberOfPages: ' + numberOfPages);
+ for (var k = 1; k <= numberOfPages; k++) {
+ pdoc.setPage(k);
+ console.log('CurrentPage: ' + k);
+ var footner = 'Page ' + k + "/" + numberOfPages;
+ pdoc.text(footner, pageCenter, pdfHeightInMM - 7, 'center');
+
}
console.log('Done');
@@ -423,5 +552,4 @@ public class SynopticTablePanelResult {
pdoc.save(filename);
}-*/;
-
}