ref 17249: Save produced charts as report
https://support.d4science.org/issues/17249 Added PDF support
This commit is contained in:
parent
988cace4e7
commit
5df51216d7
2
pom.xml
2
pom.xml
|
@ -11,7 +11,7 @@
|
|||
<groupId>org.gcube.portlets.user</groupId>
|
||||
<artifactId>performfish-analytics-portlet</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>0.6.0-SNAPSHOT</version>
|
||||
<version>0.7.0-SNAPSHOT</version>
|
||||
<name>PerformFish Analytics Portlet</name>
|
||||
|
||||
<scm>
|
||||
|
|
|
@ -45,11 +45,15 @@ 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;
|
||||
|
@ -60,6 +64,7 @@ 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
|
||||
/**
|
||||
|
@ -90,6 +95,8 @@ public class PerformFishAnnualAnalyticsController {
|
|||
|
||||
private Map<Integer, FlexTable> synopticOrderBy = new HashMap<Integer, FlexTable>();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new perform fish analytics controller.
|
||||
*/
|
||||
|
@ -154,13 +161,6 @@ public class PerformFishAnnualAnalyticsController {
|
|||
selectedKPI.getSelectedPopulationType());
|
||||
eventBus.fireEvent(new PerformFishFieldFormChangedEvent(null));
|
||||
|
||||
// viewController.manageAlgorithmsSubmit(selectedKPIsSize);
|
||||
// List<String> batchIds = viewController.getSelectedBatchID();
|
||||
// if(batchIds==null || batchIds.size()==0) {
|
||||
// viewController.enableAllAlgorithmsForSubmit(false);
|
||||
// }else
|
||||
|
||||
// viewController.manageAlgorithmsSubmit(selectedKPIsSize);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -345,11 +345,12 @@ public class PerformFishAnnualAnalyticsController {
|
|||
|
||||
final DataMinerAlgorithms algorithm = DataMinerAlgorithms.PERFORMFISH_SYNOPTIC_TABLE_FARM;
|
||||
final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
|
||||
String tabTitle = "Synoptic Table";
|
||||
final String tabTitle = "Synoptic Table";
|
||||
final String tabDescr = PerformFishResources.INSTANCE.synopticTable().getText();
|
||||
|
||||
final Tab tab = viewAnnualController.createTab(
|
||||
tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1),
|
||||
PerformFishResources.INSTANCE.synopticTable().getText(), submitRequestPanel);
|
||||
tabDescr, submitRequestPanel);
|
||||
|
||||
StringBuilder dataInputsFormatter = new StringBuilder();
|
||||
Map<String, String> performFishResponseMap = thePerformFishResponse.getMapParameters();
|
||||
|
@ -402,14 +403,14 @@ public class PerformFishAnnualAnalyticsController {
|
|||
// field_unary_algorithm.setVisible(true);
|
||||
GWT.log("I'm displaying: " + dmResponse);
|
||||
displayOutputFilesAsStaticEntities(dmResponse, algorithm, null, null, null, panelContainer,
|
||||
false);
|
||||
false,tabTitle, tabDescr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
loaderIcon.setVisible(false);
|
||||
checkTabSpinner(submitRequestPanel, tab);
|
||||
displayOutputFilesAsStaticEntities(null, algorithm, null, null, null, panelContainer, true);
|
||||
displayOutputFilesAsStaticEntities(null, algorithm, null, null, null, panelContainer, true,tabTitle, tabDescr);
|
||||
|
||||
}
|
||||
});
|
||||
|
@ -487,8 +488,9 @@ public class PerformFishAnnualAnalyticsController {
|
|||
GWT.log("Building DM request with input parameters: " + dmInputParameters);
|
||||
|
||||
StringBuilder dataInputsFormatter = new StringBuilder();
|
||||
//dataInputsFormatter.append(
|
||||
// PerformFishAnalyticsConstant.DM_SCALEP_PARAM + "=" + viewAnnualController.getForm().getLevel() + ";");
|
||||
// dataInputsFormatter.append(
|
||||
// PerformFishAnalyticsConstant.DM_SCALEP_PARAM + "=" +
|
||||
// viewAnnualController.getForm().getLevel() + ";");
|
||||
dataInputsFormatter
|
||||
.append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM + "=" + dmInputParameters.getChartType() + ";");
|
||||
|
||||
|
@ -553,7 +555,8 @@ public class PerformFishAnnualAnalyticsController {
|
|||
submitRequestPanel.showLoader(false, null);
|
||||
|
||||
String tabTitle = DataMinerAlgorithms.DEA_ANALYSIS.getTitle();
|
||||
final Tab tab = viewAnnualController.createTab(tabTitle+" #" + (viewAnnualController.currentNumberOfTab() + 1),
|
||||
final Tab tab = viewAnnualController.createTab(
|
||||
tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1),
|
||||
PerformFishResources.INSTANCE.farm_DEAANALYSIS().getText(), submitRequestPanel);
|
||||
viewAnnualController.noSpinner(tab);
|
||||
|
||||
|
@ -731,7 +734,6 @@ public class PerformFishAnnualAnalyticsController {
|
|||
|
||||
SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
|
||||
// submitRequestPanel.getElement().addClassName("ext-horizontal-panel");
|
||||
String tabTitle = algorithm.getTitle();
|
||||
|
||||
// TO MANAGE ALGORITHMS DESCRIPTION
|
||||
TextResource algDescr = null;
|
||||
|
@ -764,8 +766,14 @@ public class PerformFishAnnualAnalyticsController {
|
|||
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);
|
||||
|
||||
|
@ -784,7 +792,7 @@ public class PerformFishAnnualAnalyticsController {
|
|||
|
||||
DataMinerInputParameters dmInputParams = new DataMinerInputParameters(thePerformFishResponse,
|
||||
viewAnnualController.getSelectedYears(), Arrays.asList(kpi), null, algorithm, focusID);
|
||||
callDataMinerServiceForChart(dmInputParams, submitRequestPanel, hp, tab);
|
||||
callDataMinerServiceForChart(dmInputParams, submitRequestPanel, hp, tab, tabTitle, tabDescr);
|
||||
// resultPanel.add(hp);
|
||||
submitRequestPanel.addWidget(hp);
|
||||
}
|
||||
|
@ -807,7 +815,7 @@ public class PerformFishAnnualAnalyticsController {
|
|||
DataMinerInputParameters dmInputParams = new DataMinerInputParameters(thePerformFishResponse,
|
||||
viewAnnualController.getSelectedYears(), inputKPI, outputKPI, algorithm, focusID);
|
||||
callDataMinerServiceForChart(dmInputParams, submitRequestPanel, submitRequestPanel.getContainerPanel(),
|
||||
tab);
|
||||
tab,tabTitle, tabDescr);
|
||||
// callDataMinerServiceForChart(thePerformFishResponse,
|
||||
// POPULATION_LEVEL.BATCH, inputKPI, outputKPI, algorithm, focusID,
|
||||
// submitRequestPanel, submitRequestPanel.getContainerPanel(), tab);
|
||||
|
@ -826,9 +834,11 @@ public class PerformFishAnnualAnalyticsController {
|
|||
* 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 SubmitRequestPanel requestPanel, final ComplexPanel panelContainer, final Tab tab, final String tabTitle, final String tabDescr) {
|
||||
|
||||
GWT.log("Building DM request with input parameters: " + dmInputParameters);
|
||||
|
||||
|
@ -914,7 +924,7 @@ public class PerformFishAnnualAnalyticsController {
|
|||
GWT.log("I'm displaying: " + dmResponse);
|
||||
displayOutputFilesAsStaticEntities(dmResponse, dmInputParameters.getChartType(),
|
||||
dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
|
||||
dmInputParameters.getFocusID(), panelContainer, false);
|
||||
dmInputParameters.getFocusID(), panelContainer, false,tabTitle, tabDescr);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -923,7 +933,7 @@ public class PerformFishAnnualAnalyticsController {
|
|||
checkTabSpinner(requestPanel, tab);
|
||||
displayOutputFilesAsStaticEntities(null, dmInputParameters.getChartType(),
|
||||
dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
|
||||
dmInputParameters.getFocusID(), panelContainer, true);
|
||||
dmInputParameters.getFocusID(), panelContainer, true,tabTitle, tabDescr);
|
||||
|
||||
}
|
||||
});
|
||||
|
@ -987,10 +997,12 @@ public class PerformFishAnnualAnalyticsController {
|
|||
* the container
|
||||
* @param displayError
|
||||
* the display error
|
||||
* @param tabDescr
|
||||
* @param tabTitle
|
||||
*/
|
||||
private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
|
||||
final DataMinerAlgorithms chartType, List<KPI> inputKPIs, List<KPI> outputKPIs, final String focusID,
|
||||
final Panel container, boolean displayError) {
|
||||
final Panel container, boolean displayError, final String tabTitle, final String tabDescr) {
|
||||
|
||||
String title = displayError ? "No results " : "";
|
||||
|
||||
|
@ -1003,12 +1015,32 @@ public class PerformFishAnnualAnalyticsController {
|
|||
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;
|
||||
int outputNumber = 0;
|
||||
|
||||
for (final OutputFile outputFile : dmResponse.getListOutput()) {
|
||||
outputNumber++;
|
||||
final String outputId="OutputId_"+outputNumber;
|
||||
final String outputId = "OutputId_" + outputNumber;
|
||||
|
||||
switch (outputFile.getDataType()) {
|
||||
case IMAGE:
|
||||
|
@ -1037,7 +1069,7 @@ public class PerformFishAnnualAnalyticsController {
|
|||
title = chartType.getTitle() + " - on all farm data<br>";
|
||||
title += "Blue dots indicate the selected farm: " + focusID;
|
||||
|
||||
ShowResult showResult = new ShowResult(outputId,title, outputFile.getDataType());
|
||||
ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
|
||||
showResult.showImage(base64Content);
|
||||
displayingOrderedBoxPlot(dmResponse, title, container, showResult);
|
||||
return;
|
||||
|
@ -1066,7 +1098,7 @@ public class PerformFishAnnualAnalyticsController {
|
|||
break;
|
||||
}
|
||||
|
||||
ShowResult showResult = new ShowResult(outputId,title,outputFile.getDataType());
|
||||
ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
|
||||
showResult.showImage(base64Content);
|
||||
container.add(showResult);
|
||||
|
||||
|
@ -1102,7 +1134,7 @@ public class PerformFishAnnualAnalyticsController {
|
|||
title += "<br>";
|
||||
title += "Data aggregation is performed by considering farms as base units";
|
||||
|
||||
ShowResult showResult = new ShowResult(outputId,title, outputFile.getDataType());
|
||||
ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
|
||||
showResult.showCSVFile(result, cssTableStyle);
|
||||
displayingOrderedBoxPlot(dmResponse, title, container, showResult);
|
||||
return;
|
||||
|
@ -1122,7 +1154,8 @@ public class PerformFishAnnualAnalyticsController {
|
|||
} else {
|
||||
cssTableStyle = "simpletable-synoptic";
|
||||
}
|
||||
ShowResult showResultSin = new ShowResult(outputId,title, outputFile.getDataType());
|
||||
ShowResult showResultSin = new ShowResult(outputId, title,
|
||||
outputFile.getDataType());
|
||||
showResultSin.showCSVFile(result, cssTableStyle);
|
||||
displayingOrderedSynopticTable(dmResponse, result.getFileName(), container,
|
||||
showResultSin);
|
||||
|
@ -1138,7 +1171,7 @@ public class PerformFishAnnualAnalyticsController {
|
|||
break;
|
||||
}
|
||||
|
||||
ShowResult showResult = new ShowResult(outputId,title, outputFile.getDataType());
|
||||
ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
|
||||
showResult.showCSVFile(result, cssTableStyle);
|
||||
container.add(showResult);
|
||||
}
|
||||
|
@ -1218,4 +1251,121 @@ public class PerformFishAnnualAnalyticsController {
|
|||
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);
|
||||
|
||||
}-*/;
|
||||
|
||||
}
|
||||
|
|
|
@ -34,13 +34,14 @@ import org.gcube.portlets.user.performfishanalytics.client.event.SubmitRequestEv
|
|||
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.BoxPlotPanelResult;
|
||||
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.DeaPanelResult;
|
||||
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.ShowResult;
|
||||
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.ScatterPanelResult;
|
||||
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.SpeedometerPanelResult;
|
||||
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.SubmitRequestPanel;
|
||||
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.SynopticTablePanelResult;
|
||||
import org.gcube.portlets.user.performfishanalytics.shared.KPI;
|
||||
import org.gcube.portlets.user.performfishanalytics.shared.OutputFile;
|
||||
import org.gcube.portlets.user.performfishanalytics.shared.PopulationType;
|
||||
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.PerformFishInitParameter;
|
||||
import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse;
|
||||
|
@ -50,19 +51,10 @@ import com.github.gwtbootstrap.client.ui.Modal;
|
|||
import com.github.gwtbootstrap.client.ui.Tab;
|
||||
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
||||
import com.github.gwtbootstrap.client.ui.constants.ControlGroupType;
|
||||
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.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;
|
||||
|
||||
/**
|
||||
|
@ -82,9 +74,7 @@ public class PerformFishAnalyticsController {
|
|||
/** The decrypt parameters. */
|
||||
private PerformFishInitParameter decryptParameters;
|
||||
|
||||
private Map<Integer, FlexTable> boxPlotOrderBy = new HashMap<Integer, FlexTable>();
|
||||
|
||||
private Map<Integer, FlexTable> synopticOrderBy = new HashMap<Integer, FlexTable>();
|
||||
private static int requestId = 0;
|
||||
|
||||
/**
|
||||
* Instantiates a new perform fish analytics controller.
|
||||
|
@ -376,92 +366,9 @@ public class PerformFishAnalyticsController {
|
|||
final Map<String, List<String>> performFishRequestParameters) {
|
||||
GWT.log("Read perform fish response: " + performFishResponse);
|
||||
|
||||
String batchTableURL = performFishResponse.getMapParameters().get(PerformFishAnalyticsConstant.BATCHES_TABLE);
|
||||
|
||||
if (batchTableURL == null || batchTableURL.isEmpty())
|
||||
Window.alert("Something seems wrong. No batches tables matching with parameter "
|
||||
+ PerformFishAnalyticsConstant.BATCHES_TABLE + " returned from service");
|
||||
|
||||
final Map<String, List<String>> mapParameters = new HashMap<String, List<String>>();
|
||||
|
||||
StringBuilder dataInputsFormatter = new StringBuilder();
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_INPUT_TABLE + "=" + batchTableURL + ";");
|
||||
|
||||
// READ THE INPUT FILE
|
||||
String popType = viewController.getForm().getBatchType();
|
||||
|
||||
DataMinerAlgorithms chartType = null;
|
||||
if (popType.equalsIgnoreCase(PerformFishAnalyticsConstant.BATCH_LEVEL.GROW_OUT_INDIVIDUAL_CLOSED_BATCHES.name())
|
||||
|| popType.equalsIgnoreCase(PerformFishAnalyticsConstant.BATCH_LEVEL.GROW_OUT_INDIVIDUAL.name())) {
|
||||
chartType = DataMinerAlgorithms.PERFORMFISH_SYNOPTICTABLE_BATCH;
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_QUARTER_LABELS + "="
|
||||
+ PerformFishAnalyticsConstant.DM_VALUE_ALL + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_ZONE_LABELS + "="
|
||||
+ PerformFishAnalyticsConstant.DM_VALUE_ALL + ";");
|
||||
} else if (popType
|
||||
.equalsIgnoreCase(PerformFishAnalyticsConstant.BATCH_LEVEL.HATCHERY_INDIVIDUAL_CLOSED_BATCHES.name())
|
||||
|| popType.equalsIgnoreCase(PerformFishAnalyticsConstant.BATCH_LEVEL.HATCHERY_INDIVIDUAL.name())) {
|
||||
chartType = DataMinerAlgorithms.PERFORMFISH_SYNOPTICTABLE_BATCH_HATCHERY;
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_STOCKING_PERIOD + "="
|
||||
+ PerformFishAnalyticsConstant.DM_VALUE_ALL + ";");
|
||||
} else if (popType.equalsIgnoreCase(PerformFishAnalyticsConstant.BATCH_LEVEL.PRE_ONGROWING.name()) || popType
|
||||
.equalsIgnoreCase(PerformFishAnalyticsConstant.BATCH_LEVEL.PRE_ONGROWING_CLOSED_BATCHES.name())) {
|
||||
chartType = DataMinerAlgorithms.PERFORMFISH_SYNOPTICTABLE_BATCH_PREGROW;
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_ZONE_LABELS + "="
|
||||
+ PerformFishAnalyticsConstant.DM_VALUE_ALL + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_STOCKING_PERIOD + "="
|
||||
+ PerformFishAnalyticsConstant.DM_VALUE_ALL + ";");
|
||||
}
|
||||
|
||||
String dataInParameters = dataInputsFormatter.toString();
|
||||
mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters));
|
||||
mapParameters.put("Identifier", Arrays.asList(
|
||||
"org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers." + chartType));
|
||||
|
||||
GWT.log("Calling DM service with client input parameters: " + mapParameters);
|
||||
|
||||
final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
|
||||
// submitRequestPanel.getElement().addClassName("ext-horizontal-panel");
|
||||
String tabTitle = "Synoptic Table"; // CAMEL CASE
|
||||
final Tab tab = viewController.createTab(tabTitle + " #" + (viewController.currentNumberOfTab() + 1),
|
||||
PerformFishResources.INSTANCE.synopticTable().getText(), submitRequestPanel);
|
||||
final HTMLPanel panelContainer = submitRequestPanel.getContainerPanel();
|
||||
|
||||
final LoaderIcon loaderIcon = new LoaderIcon(
|
||||
"Submitting request to " + DataMinerAlgorithms.PERFORMFISH_SYNOPTICTABLE_BATCH.getTitle() + "...");
|
||||
loaderIcon.setVisible(true);
|
||||
panelContainer.setVisible(true);
|
||||
panelContainer.add(loaderIcon);
|
||||
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
loaderIcon.setFocus(true);
|
||||
}
|
||||
});
|
||||
|
||||
final DataMinerAlgorithms toFinalChartType = chartType;
|
||||
PerformFishAnalyticsServiceAsync.Util.getInstance().callDMServiceToLoadSynopticTable(performFishResponse,
|
||||
mapParameters, new AsyncCallback<DataMinerResponse>() {
|
||||
|
||||
@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, toFinalChartType, null, null, null,
|
||||
panelContainer, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
loaderIcon.setVisible(false);
|
||||
checkTabSpinner(submitRequestPanel, tab);
|
||||
displayOutputFilesAsStaticEntities(null, toFinalChartType, null, null, null, panelContainer,
|
||||
true);
|
||||
|
||||
}
|
||||
});
|
||||
@SuppressWarnings("unused")
|
||||
SynopticTablePanelResult synopticTablePanelResult = new SynopticTablePanelResult(requestId++, viewController,
|
||||
performFishResponse, performFishRequestParameters);
|
||||
|
||||
}
|
||||
|
||||
|
@ -494,7 +401,8 @@ public class PerformFishAnalyticsController {
|
|||
dataInputsFormatter
|
||||
.append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM + "=" + DataMinerAlgorithms.CORRELATION + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FARMFILE_PARAM + "=" + batchTableURL + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM + "="+viewController.getSelectedBatchID()+";");
|
||||
dataInputsFormatter
|
||||
.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM + "=" + viewController.getSelectedBatchID() + ";");
|
||||
|
||||
String kpiCodes = "";
|
||||
for (KPI kpi : viewController.getSelectedKPIs()) {
|
||||
|
@ -514,7 +422,7 @@ public class PerformFishAnalyticsController {
|
|||
submitRequestPanel.showLoader(false, null);
|
||||
|
||||
String tabTitle = DataMinerAlgorithms.DEA_ANALYSIS.getTitle();
|
||||
final Tab tab = viewController.createTab(tabTitle+" #" + (viewController.currentNumberOfTab() + 1),
|
||||
final Tab tab = viewController.createTab(tabTitle + " #" + (viewController.currentNumberOfTab() + 1),
|
||||
PerformFishResources.INSTANCE.batch_DEAANALYSIS().getText(), submitRequestPanel);
|
||||
viewController.noSpinner(tab);
|
||||
final List<KPI> selectedKPI = new ArrayList<KPI>(viewController.getSelectedKPIs());
|
||||
|
@ -648,7 +556,7 @@ public class PerformFishAnalyticsController {
|
|||
* @param outputKPI
|
||||
* the output kpi
|
||||
*/
|
||||
private void callAlgorithm(DataMinerAlgorithms algorithm, String focusID, List<KPI> inputKPI,
|
||||
private void callAlgorithm(final DataMinerAlgorithms algorithm, String focusID, List<KPI> inputKPI,
|
||||
final List<KPI> outputKPI) {
|
||||
|
||||
String selectedBatchID = viewController.getSelectedBatchID();
|
||||
|
@ -656,199 +564,32 @@ public class PerformFishAnalyticsController {
|
|||
if (selectedBatchID == null || selectedBatchID.isEmpty())
|
||||
Window.alert("Something seems wrong, no selected BatchID, try again");
|
||||
|
||||
// submitRequestPanel.getElement().addClassName("ext-horizontal-panel");
|
||||
String tabTitle = algorithm.getTitle();
|
||||
|
||||
// TO MANAGE ALGORITHMS DESCRIPTION
|
||||
TextResource algDescr = null;
|
||||
switch (algorithm) {
|
||||
case BOXPLOT:
|
||||
algDescr = PerformFishResources.INSTANCE.batch_BOXPLOT();
|
||||
break;
|
||||
case CORRELATION:
|
||||
algDescr = PerformFishResources.INSTANCE.batch_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.batch_SCATTER();
|
||||
@SuppressWarnings("unused")
|
||||
BoxPlotPanelResult boxPlotPanelResult = new BoxPlotPanelResult(requestId++, viewController, algorithm,
|
||||
focusID, inputKPI, outputKPI);
|
||||
break;
|
||||
case SPEEDOMETER:
|
||||
algDescr = PerformFishResources.INSTANCE.batch_SPEEDOMETER();
|
||||
@SuppressWarnings("unused")
|
||||
SpeedometerPanelResult speedometerPanelResult = new SpeedometerPanelResult(requestId++, viewController,
|
||||
algorithm, focusID, inputKPI, outputKPI);
|
||||
|
||||
break;
|
||||
case PERFORMFISH_SYNOPTICTABLE_BATCH_HATCHERY:
|
||||
break;
|
||||
case PERFORMFISH_SYNOPTICTABLE_BATCH_PREGROW:
|
||||
case SCATTER:
|
||||
@SuppressWarnings("unused")
|
||||
ScatterPanelResult scatterPanelResult = new ScatterPanelResult(requestId++, viewController, algorithm,
|
||||
focusID, inputKPI, outputKPI);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
// callDataMinerServiceForChart(viewController.getPerformFishResponse(),
|
||||
// POPULATION_LEVEL.BATCH, inputKPI,
|
||||
// outputKPI, algorithm, focusID, submitRequestPanel,
|
||||
// submitRequestPanel.getContainerPanel(), tab,
|
||||
// req, oIteration);
|
||||
}
|
||||
|
||||
String algDesrTxt = algDescr != null ? algDescr.getText() : null;
|
||||
final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
|
||||
Tab tab = viewController.createTab(tabTitle + " #" + (viewController.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");
|
||||
callDataMinerServiceForChart(viewController.getPerformFishResponse(), POPULATION_LEVEL.BATCH,
|
||||
Arrays.asList(kpi), Arrays.asList(kpi), algorithm, focusID, submitRequestPanel, hp, tab);
|
||||
// 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:
|
||||
callDataMinerServiceForChart(viewController.getPerformFishResponse(), POPULATION_LEVEL.BATCH, inputKPI,
|
||||
outputKPI, algorithm, focusID, submitRequestPanel, submitRequestPanel.getContainerPanel(), tab);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Call data miner service for chart.
|
||||
*
|
||||
* @param performFishResponse
|
||||
* the perform fish response
|
||||
* @param scalePValue
|
||||
* the scale p value
|
||||
* @param inputKPI
|
||||
* the input kpi
|
||||
* @param outputKPI
|
||||
* the output kpi
|
||||
* @param chartType
|
||||
* the chart type
|
||||
* @param focusID
|
||||
* the focus id
|
||||
* @param requestPanel
|
||||
* the request panel
|
||||
* @param panelContainer
|
||||
* the panel
|
||||
* @param tab
|
||||
* the tab
|
||||
*/
|
||||
private void callDataMinerServiceForChart(PerformFishResponse performFishResponse, POPULATION_LEVEL scalePValue,
|
||||
final List<KPI> inputKPI, final List<KPI> outputKPI, final DataMinerAlgorithms chartType,
|
||||
final String focusID, final SubmitRequestPanel requestPanel, final ComplexPanel panelContainer,
|
||||
final Tab tab) {
|
||||
|
||||
GWT.log("Read perform fish response: " + performFishResponse);
|
||||
|
||||
String batchTableURL = performFishResponse.getMapParameters().get(PerformFishAnalyticsConstant.BATCHES_TABLE);
|
||||
|
||||
if (batchTableURL == null || batchTableURL.isEmpty())
|
||||
Window.alert("Something seems wrong. No batches tables matching with parameter "
|
||||
+ PerformFishAnalyticsConstant.BATCHES_TABLE + " returned from service");
|
||||
|
||||
StringBuilder dataInputsFormatter = new StringBuilder();
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_SCALEP_PARAM + "=" + scalePValue.name() + ";");
|
||||
String theBatchType = viewController.getForm().getBatchType();
|
||||
theBatchType = theBatchType.replace("_CLOSED_BATCHES", ""); // REMOVING
|
||||
// SUFFIX
|
||||
// _CLOSED_BATCHES
|
||||
// FOR
|
||||
// DATAMINER
|
||||
// CALL
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_BATCHTYPE_PARAM + "=" + theBatchType + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM + "=" + chartType + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FARMFILE_PARAM + "=" + batchTableURL + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM + "=" + focusID + ";");
|
||||
|
||||
if (inputKPI != null && inputKPI.size() > 0) {
|
||||
String kpiCodes = "";
|
||||
for (KPI kpi : inputKPI) {
|
||||
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 (outputKPI != null && outputKPI.size() > 0) {
|
||||
String kpiCodes = "";
|
||||
for (KPI kpi : outputKPI) {
|
||||
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 + ";");
|
||||
|
||||
}
|
||||
|
||||
String dataInParameters = dataInputsFormatter.toString();
|
||||
GWT.log("Calling DM service with client input parameters: " + dataInParameters);
|
||||
|
||||
Map<String, List<String>> mapParameters = new HashMap<String, List<String>>();
|
||||
mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters));
|
||||
|
||||
final LoaderIcon loaderIcon = new LoaderIcon("Submitting request to " + chartType.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().callingDataMinerPerformFishAnalysis(mapParameters,
|
||||
new AsyncCallback<DataMinerResponse>() {
|
||||
|
||||
@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, chartType, inputKPI, outputKPI, focusID,
|
||||
panelContainer, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
loaderIcon.setVisible(false);
|
||||
checkTabSpinner(requestPanel, tab);
|
||||
displayOutputFilesAsStaticEntities(null, chartType, inputKPI, outputKPI, focusID,
|
||||
panelContainer, true);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -869,223 +610,4 @@ public class PerformFishAnalyticsController {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
|
||||
final DataMinerAlgorithms chartType, List<KPI> inputKPIs, List<KPI> outputKPIs, final String focusID,
|
||||
final Panel container, boolean displayError) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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<String>() {
|
||||
|
||||
@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<br>";
|
||||
title += "Blue dots indicate the selected batch(es): " + 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() + "<br>";
|
||||
title += "Selected Batch ID: " + focusID + "<br>";
|
||||
title += "Normalized with respect to all batches in the VRE";
|
||||
break;
|
||||
case DEA_CHART:
|
||||
break;
|
||||
case PERFORMFISH_SYNOPTICTABLE_BATCH:
|
||||
case PERFORMFISH_SYNOPTICTABLE_BATCH_HATCHERY:
|
||||
case PERFORMFISH_SYNOPTICTABLE_BATCH_PREGROW:
|
||||
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<CSVFile>() {
|
||||
|
||||
@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)";
|
||||
} else {
|
||||
title = "All batches in the VRE (including mine)";
|
||||
}
|
||||
title += "<br>";
|
||||
title += "Data aggregation is performed by considering batches 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_SYNOPTICTABLE_BATCH:
|
||||
case PERFORMFISH_SYNOPTICTABLE_BATCH_HATCHERY:
|
||||
case PERFORMFISH_SYNOPTICTABLE_BATCH_PREGROW:
|
||||
|
||||
if (!result.getFileName().contains("legend")) {
|
||||
cssTableStyle = "synoptictable-batch";
|
||||
} 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_SYNOPTIC_TABLE_FARM:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// ALL OTHER CASES
|
||||
ShowResult showResult = new ShowResult(outputId,title, outputFile.getDataType());
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package org.gcube.portlets.user.performfishanalytics.client.request;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.gcube.portlets.user.performfishanalytics.client.DataMinerAlgorithms;
|
||||
|
||||
public class RequestInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -2786256071405466977L;
|
||||
private int outputIteration;
|
||||
private int outputNumber;
|
||||
private DataMinerAlgorithms dataminerAlgorithms;
|
||||
|
||||
public RequestInfo(){
|
||||
super();
|
||||
}
|
||||
|
||||
public RequestInfo(int outputIteration, int outputNumber, DataMinerAlgorithms dataminerAlgorithms) {
|
||||
super();
|
||||
this.outputIteration = outputIteration;
|
||||
this.outputNumber = outputNumber;
|
||||
this.dataminerAlgorithms = dataminerAlgorithms;
|
||||
}
|
||||
|
||||
public int getOutputIteration() {
|
||||
return outputIteration;
|
||||
}
|
||||
|
||||
public void setOutputIteration(int outputIteration) {
|
||||
this.outputIteration = outputIteration;
|
||||
}
|
||||
|
||||
public int getOutputNumber() {
|
||||
return outputNumber;
|
||||
}
|
||||
|
||||
public void setOutputNumber(int outputNumber) {
|
||||
this.outputNumber = outputNumber;
|
||||
}
|
||||
|
||||
public DataMinerAlgorithms getDataminerAlgorithms() {
|
||||
return dataminerAlgorithms;
|
||||
}
|
||||
|
||||
public void setDataminerAlgorithms(DataMinerAlgorithms dataminerAlgorithms) {
|
||||
this.dataminerAlgorithms = dataminerAlgorithms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RequestInfo [outputIteration=" + outputIteration + ", outputNumber=" + outputNumber
|
||||
+ ", dataminerAlgorithms=" + dataminerAlgorithms + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -21,10 +21,12 @@ 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;
|
||||
|
@ -96,6 +98,12 @@ public class AnalyticsAnnualPanelResult extends Composite {
|
|||
@UiField
|
||||
ListBox field_list_focus_id_correlation;
|
||||
|
||||
@UiField
|
||||
Button uib_save_pdf_1;
|
||||
|
||||
// @UiField
|
||||
// Button uib_save_pdf_2;
|
||||
|
||||
private Map<String, String> dataInputParameters;
|
||||
|
||||
private DataMinerResponse dmResponse;
|
||||
|
@ -110,19 +118,46 @@ public class AnalyticsAnnualPanelResult extends Composite {
|
|||
|
||||
private Map<String, CSVFile> csvGenerated = new HashMap<String, CSVFile>();
|
||||
|
||||
/**
|
||||
* 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: <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" xmlns:g=
|
||||
* "urn:import:**user's package**">
|
||||
* <g:**UserClassName**>Hello!</g:**UserClassName> </ui:UiBinder> Note that
|
||||
* depending on the widget that is used, it may be necessary to implement
|
||||
* HasHTML instead of HasText.
|
||||
*/
|
||||
private AnalyticsAnnualPanelResult analyticsPanelResult;
|
||||
|
||||
private static int callNumber;
|
||||
|
||||
private static Map<String, Integer> outputNumbers = new HashMap<String, Integer>();
|
||||
|
||||
private String analysisDescription;
|
||||
|
||||
public AnalyticsAnnualPanelResult(HandlerManager eventBus) {
|
||||
|
||||
initWidget(uiBinder.createAndBindUi(this));
|
||||
// this.theEventBus = eventBus;
|
||||
|
||||
analyticsPanelResult = this;
|
||||
|
||||
uib_save_pdf_1.setIcon(IconType.PRINT);
|
||||
uib_save_pdf_1.addClickHandler(new ClickHandler() {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
saveFilePDF(analyticsPanelResult, "AnalysisResult.pdf");
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -245,8 +280,9 @@ public class AnalyticsAnnualPanelResult extends Composite {
|
|||
|
||||
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)));
|
||||
// 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) {
|
||||
|
@ -256,8 +292,6 @@ public class AnalyticsAnnualPanelResult extends Composite {
|
|||
flexTable.setWidget(2, 0, new HTML("KPIs:"));
|
||||
flexTable.setWidget(2, 1, new HTML(KPINames));
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
// silent
|
||||
}
|
||||
|
@ -537,4 +571,157 @@ public class AnalyticsAnnualPanelResult extends Composite {
|
|||
.fireEvent(new CallAlgorithmEvent(DataMinerAlgorithms.SCATTER, focusID, selectedKPI, null));
|
||||
}
|
||||
|
||||
private static native void saveFilePDF(AnalyticsAnnualPanelResult chart, String filename)/*-{
|
||||
var that = this;
|
||||
console.log('saveFilePDF()');
|
||||
|
||||
var pdoc = new jsPDF("p", "mm", "a4");
|
||||
pdoc.setProperties({
|
||||
title : 'PerformFish Analysis',
|
||||
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 Analysis";
|
||||
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 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;
|
||||
|
||||
var callNumber = @org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.AnalyticsAnnualPanelResult::callNumber;
|
||||
console.log('CallNumber: ' + callNumber);
|
||||
|
||||
for (var n = 1; n <= callNumber; n++) {
|
||||
var deaAnalysisResultParametersInputKPIs = $doc
|
||||
.getElementById('DeaAnalysisResultParameterInputKPIs_' + n).innerHTML;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
console.log('Done');
|
||||
|
||||
pdoc.save(filename);
|
||||
|
||||
}-*/;
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@
|
|||
|
||||
<g:HTMLPanel ui:field="field_html_panel" addStyleNames="the_margin">
|
||||
|
||||
<b:Button size="SMALL" ui:field="uib_save_pdf_1"
|
||||
title="Save PDF" />
|
||||
|
||||
<g:VerticalPanel ui:field="field_parameters">
|
||||
<g:VerticalPanel ui:field="field_parameters_container"
|
||||
addStyleNames="the_margin_top_bottom">
|
||||
|
@ -45,7 +48,7 @@
|
|||
|
||||
<g:VerticalPanel ui:field="field_binary_algorithm"
|
||||
addStyleNames="the_margin_top_bottom" visible="false">
|
||||
<b:Label text="SCATTER and DEA_CHART Results" type="INFO"></b:Label>
|
||||
<b:Label text="SCATTER Results" type="INFO"></b:Label>
|
||||
<g:VerticalPanel ui:field="field_binary_algorithm_container"
|
||||
addStyleNames="the_margin">
|
||||
</g:VerticalPanel>
|
||||
|
|
|
@ -0,0 +1,454 @@
|
|||
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.PerformFishAnalyticsConstant.POPULATION_LEVEL;
|
||||
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync;
|
||||
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.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 BoxPlotPanelResult {
|
||||
|
||||
private Map<Integer, FlexTable> boxPlotOrderBy = new HashMap<Integer, FlexTable>();
|
||||
|
||||
private PerformFishAnalyticsViewController viewController;
|
||||
private int outputIteration = 0;
|
||||
private int outputNumber = 0;
|
||||
private int requestId;
|
||||
|
||||
|
||||
public BoxPlotPanelResult(int reqId,PerformFishAnalyticsViewController viewController, final DataMinerAlgorithms algorithm,
|
||||
String focusID, List<KPI> inputKPI, final List<KPI> outputKPI) {
|
||||
this.requestId=reqId;
|
||||
this.viewController = viewController;
|
||||
TextResource algDescr = PerformFishResources.INSTANCE.batch_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 = viewController.createTab(tabTitle + " #" + (viewController.currentNumberOfTab() + 1), algDesrTxt,
|
||||
submitRequestPanel);
|
||||
|
||||
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(algorithm.getId(), tabTitle, tabTitle, tabDescr, requestId, outputIteration, outputNumber);
|
||||
// dmResponse.getListOutput().size()
|
||||
}
|
||||
});
|
||||
|
||||
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().addClassName("to-big-title");
|
||||
submitRequestPanel.addWidget(toBigTitle);
|
||||
HorizontalPanel hp = new HorizontalPanel();
|
||||
hp.getElement().addClassName("ext-horizontal-panel");
|
||||
callDataMinerServiceForChart(viewController.getPerformFishResponse(), POPULATION_LEVEL.BATCH,
|
||||
Arrays.asList(kpi), Arrays.asList(kpi), algorithm, focusID, submitRequestPanel, hp, tab,
|
||||
oIteration);
|
||||
// resultPanel.add(hp);
|
||||
submitRequestPanel.addWidget(hp);
|
||||
}
|
||||
outputIteration = oIteration;
|
||||
|
||||
}
|
||||
|
||||
private void callDataMinerServiceForChart(PerformFishResponse performFishResponse, POPULATION_LEVEL scalePValue,
|
||||
final List<KPI> inputKPI, final List<KPI> outputKPI, final DataMinerAlgorithms chartType,
|
||||
final String focusID, final SubmitRequestPanel requestPanel, final ComplexPanel panelContainer,
|
||||
final Tab tab, final int oIteration) {
|
||||
|
||||
GWT.log("Read perform fish response: " + performFishResponse);
|
||||
|
||||
String batchTableURL = performFishResponse.getMapParameters().get(PerformFishAnalyticsConstant.BATCHES_TABLE);
|
||||
|
||||
if (batchTableURL == null || batchTableURL.isEmpty())
|
||||
Window.alert("Something seems wrong. No batches tables matching with parameter "
|
||||
+ PerformFishAnalyticsConstant.BATCHES_TABLE + " returned from service");
|
||||
|
||||
StringBuilder dataInputsFormatter = new StringBuilder();
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_SCALEP_PARAM + "=" + scalePValue.name() + ";");
|
||||
String theBatchType = viewController.getForm().getBatchType();
|
||||
theBatchType = theBatchType.replace("_CLOSED_BATCHES", ""); // REMOVING
|
||||
// SUFFIX
|
||||
// _CLOSED_BATCHES
|
||||
// FOR
|
||||
// DATAMINER
|
||||
// CALL
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_BATCHTYPE_PARAM + "=" + theBatchType + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM + "=" + chartType + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FARMFILE_PARAM + "=" + batchTableURL + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM + "=" + focusID + ";");
|
||||
|
||||
if (inputKPI != null && inputKPI.size() > 0) {
|
||||
String kpiCodes = "";
|
||||
for (KPI kpi : inputKPI) {
|
||||
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 (outputKPI != null && outputKPI.size() > 0) {
|
||||
String kpiCodes = "";
|
||||
for (KPI kpi : outputKPI) {
|
||||
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 + ";");
|
||||
|
||||
}
|
||||
|
||||
String dataInParameters = dataInputsFormatter.toString();
|
||||
GWT.log("Calling DM service with client input parameters: " + dataInParameters);
|
||||
|
||||
Map<String, List<String>> mapParameters = new HashMap<String, List<String>>();
|
||||
mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters));
|
||||
|
||||
final LoaderIcon loaderIcon = new LoaderIcon("Submitting request to " + chartType.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().callingDataMinerPerformFishAnalysis(mapParameters,
|
||||
new AsyncCallback<DataMinerResponse>() {
|
||||
|
||||
@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, chartType, inputKPI, outputKPI, focusID,
|
||||
panelContainer, false, oIteration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
loaderIcon.setVisible(false);
|
||||
checkTabSpinner(requestPanel, tab);
|
||||
displayOutputFilesAsStaticEntities(null, chartType, inputKPI, outputKPI, focusID,
|
||||
panelContainer, true, oIteration);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
|
||||
final DataMinerAlgorithms chartType, List<KPI> inputKPIs, List<KPI> outputKPIs, final String focusID,
|
||||
final Panel container, boolean displayError, 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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
switch (outputFile.getDataType()) {
|
||||
case IMAGE:
|
||||
PerformFishAnalyticsServiceAsync.Util.getInstance().getImageFile(outputFile,
|
||||
new AsyncCallback<String>() {
|
||||
|
||||
@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.getName() + " - on all batches<br>";
|
||||
title += "Blue dots indicate the selected batch(es): " + focusID;
|
||||
|
||||
ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
|
||||
showResult.showImage(base64Content);
|
||||
displayingOrderedBoxPlot(dmResponse, title, container, showResult);
|
||||
}
|
||||
});
|
||||
break;
|
||||
case CSV:
|
||||
PerformFishAnalyticsServiceAsync.Util.getInstance().getCSVFile(outputFile, true,
|
||||
new AsyncCallback<CSVFile>() {
|
||||
|
||||
@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)";
|
||||
} else {
|
||||
title = "All batches in the VRE (including mine)";
|
||||
}
|
||||
title += "<br>";
|
||||
title += "Data aggregation is performed by considering batches as base units";
|
||||
|
||||
ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
|
||||
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) {
|
||||
viewController.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++) {
|
||||
|
||||
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 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);
|
||||
|
||||
}-*/;
|
||||
|
||||
}
|
|
@ -0,0 +1,417 @@
|
|||
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.PerformFishAnalyticsConstant.POPULATION_LEVEL;
|
||||
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync;
|
||||
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.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.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,
|
||||
final DataMinerAlgorithms algorithm, String focusID, List<KPI> inputKPI, final List<KPI> outputKPI) {
|
||||
this.requestId=reqId;
|
||||
this.viewController = viewController;
|
||||
TextResource algDescr = PerformFishResources.INSTANCE.batch_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 = viewController.createTab(tabTitle + " #" + (viewController.currentNumberOfTab() + 1), algDesrTxt,
|
||||
submitRequestPanel);
|
||||
|
||||
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(algorithm.getId(), tabTitle, tabTitle, tabDescr, requestId,outputIteration, outputNumber);
|
||||
// dmResponse.getListOutput().size()
|
||||
}
|
||||
});
|
||||
|
||||
res.add(savePDFButton);
|
||||
submitRequestPanel.addWidget(res);
|
||||
int oIteration = 1;
|
||||
|
||||
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);
|
||||
|
||||
callDataMinerServiceForChart(viewController.getPerformFishResponse(), POPULATION_LEVEL.BATCH, inputKPI,
|
||||
outputKPI, algorithm, focusID, submitRequestPanel, submitRequestPanel.getContainerPanel(), tab,
|
||||
oIteration);
|
||||
outputIteration = oIteration;
|
||||
|
||||
}
|
||||
|
||||
private void callDataMinerServiceForChart(PerformFishResponse performFishResponse, POPULATION_LEVEL scalePValue,
|
||||
final List<KPI> inputKPI, final List<KPI> outputKPI, final DataMinerAlgorithms chartType,
|
||||
final String focusID, final SubmitRequestPanel requestPanel, final ComplexPanel panelContainer,
|
||||
final Tab tab, final int oIteration) {
|
||||
|
||||
GWT.log("Read perform fish response: " + performFishResponse);
|
||||
|
||||
String batchTableURL = performFishResponse.getMapParameters().get(PerformFishAnalyticsConstant.BATCHES_TABLE);
|
||||
|
||||
if (batchTableURL == null || batchTableURL.isEmpty())
|
||||
Window.alert("Something seems wrong. No batches tables matching with parameter "
|
||||
+ PerformFishAnalyticsConstant.BATCHES_TABLE + " returned from service");
|
||||
|
||||
StringBuilder dataInputsFormatter = new StringBuilder();
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_SCALEP_PARAM + "=" + scalePValue.name() + ";");
|
||||
String theBatchType = viewController.getForm().getBatchType();
|
||||
theBatchType = theBatchType.replace("_CLOSED_BATCHES", ""); // REMOVING
|
||||
// SUFFIX
|
||||
// _CLOSED_BATCHES
|
||||
// FOR
|
||||
// DATAMINER
|
||||
// CALL
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_BATCHTYPE_PARAM + "=" + theBatchType + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM + "=" + chartType + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FARMFILE_PARAM + "=" + batchTableURL + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM + "=" + focusID + ";");
|
||||
|
||||
if (inputKPI != null && inputKPI.size() > 0) {
|
||||
String kpiCodes = "";
|
||||
for (KPI kpi : inputKPI) {
|
||||
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 (outputKPI != null && outputKPI.size() > 0) {
|
||||
String kpiCodes = "";
|
||||
for (KPI kpi : outputKPI) {
|
||||
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 + ";");
|
||||
|
||||
}
|
||||
|
||||
String dataInParameters = dataInputsFormatter.toString();
|
||||
GWT.log("Calling DM service with client input parameters: " + dataInParameters);
|
||||
|
||||
Map<String, List<String>> mapParameters = new HashMap<String, List<String>>();
|
||||
mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters));
|
||||
|
||||
final LoaderIcon loaderIcon = new LoaderIcon("Submitting request to " + chartType.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().callingDataMinerPerformFishAnalysis(mapParameters,
|
||||
new AsyncCallback<DataMinerResponse>() {
|
||||
|
||||
@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, chartType, inputKPI, outputKPI, focusID,
|
||||
panelContainer, false, oIteration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
loaderIcon.setVisible(false);
|
||||
checkTabSpinner(requestPanel, tab);
|
||||
displayOutputFilesAsStaticEntities(null, chartType, inputKPI, outputKPI, focusID,
|
||||
panelContainer, true, oIteration);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
|
||||
final DataMinerAlgorithms chartType, List<KPI> inputKPIs, List<KPI> outputKPIs, final String focusID,
|
||||
final Panel container, boolean displayError, 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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
switch (outputFile.getDataType()) {
|
||||
case IMAGE:
|
||||
PerformFishAnalyticsServiceAsync.Util.getInstance().getImageFile(outputFile,
|
||||
new AsyncCallback<String>() {
|
||||
|
||||
@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;
|
||||
|
||||
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<CSVFile>() {
|
||||
|
||||
@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;
|
||||
|
||||
ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
|
||||
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) {
|
||||
viewController.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++) {
|
||||
|
||||
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 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);
|
||||
|
||||
}-*/;
|
||||
}
|
|
@ -0,0 +1,420 @@
|
|||
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.PerformFishAnalyticsConstant.POPULATION_LEVEL;
|
||||
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync;
|
||||
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.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 SpeedometerPanelResult {
|
||||
|
||||
private PerformFishAnalyticsViewController viewController;
|
||||
private int requestId;
|
||||
private int outputIteration = 0;
|
||||
private int outputNumber = 0;
|
||||
|
||||
public SpeedometerPanelResult(int reqId,PerformFishAnalyticsViewController viewController,
|
||||
final DataMinerAlgorithms algorithm, String focusID, List<KPI> inputKPI, final List<KPI> outputKPI) {
|
||||
this.requestId=reqId;
|
||||
this.viewController = viewController;
|
||||
TextResource algDescr = PerformFishResources.INSTANCE.batch_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 = viewController.createTab(tabTitle + " #" + (viewController.currentNumberOfTab() + 1), algDesrTxt,
|
||||
submitRequestPanel);
|
||||
|
||||
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(algorithm.getId(), tabTitle, tabTitle, tabDescr, requestId,outputIteration, outputNumber);
|
||||
}
|
||||
});
|
||||
|
||||
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().addClassName("to-big-title");
|
||||
submitRequestPanel.addWidget(toBigTitle);
|
||||
HorizontalPanel hp = new HorizontalPanel();
|
||||
hp.getElement().addClassName("ext-horizontal-panel");
|
||||
callDataMinerServiceForChart(viewController.getPerformFishResponse(), POPULATION_LEVEL.BATCH,
|
||||
Arrays.asList(kpi), Arrays.asList(kpi), algorithm, focusID, submitRequestPanel, hp, tab,
|
||||
oIteration);
|
||||
// resultPanel.add(hp);
|
||||
submitRequestPanel.addWidget(hp);
|
||||
}
|
||||
outputIteration = oIteration;
|
||||
|
||||
}
|
||||
|
||||
private void callDataMinerServiceForChart(PerformFishResponse performFishResponse, POPULATION_LEVEL scalePValue,
|
||||
final List<KPI> inputKPI, final List<KPI> outputKPI, final DataMinerAlgorithms chartType,
|
||||
final String focusID, final SubmitRequestPanel requestPanel, final ComplexPanel panelContainer,
|
||||
final Tab tab, final int oIteration) {
|
||||
|
||||
GWT.log("Read perform fish response: " + performFishResponse);
|
||||
|
||||
String batchTableURL = performFishResponse.getMapParameters().get(PerformFishAnalyticsConstant.BATCHES_TABLE);
|
||||
|
||||
if (batchTableURL == null || batchTableURL.isEmpty())
|
||||
Window.alert("Something seems wrong. No batches tables matching with parameter "
|
||||
+ PerformFishAnalyticsConstant.BATCHES_TABLE + " returned from service");
|
||||
|
||||
StringBuilder dataInputsFormatter = new StringBuilder();
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_SCALEP_PARAM + "=" + scalePValue.name() + ";");
|
||||
String theBatchType = viewController.getForm().getBatchType();
|
||||
theBatchType = theBatchType.replace("_CLOSED_BATCHES", ""); // REMOVING
|
||||
// SUFFIX
|
||||
// _CLOSED_BATCHES
|
||||
// FOR
|
||||
// DATAMINER
|
||||
// CALL
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_BATCHTYPE_PARAM + "=" + theBatchType + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM + "=" + chartType + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FARMFILE_PARAM + "=" + batchTableURL + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM + "=" + focusID + ";");
|
||||
|
||||
if (inputKPI != null && inputKPI.size() > 0) {
|
||||
String kpiCodes = "";
|
||||
for (KPI kpi : inputKPI) {
|
||||
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 (outputKPI != null && outputKPI.size() > 0) {
|
||||
String kpiCodes = "";
|
||||
for (KPI kpi : outputKPI) {
|
||||
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 + ";");
|
||||
|
||||
}
|
||||
|
||||
String dataInParameters = dataInputsFormatter.toString();
|
||||
GWT.log("Calling DM service with client input parameters: " + dataInParameters);
|
||||
|
||||
Map<String, List<String>> mapParameters = new HashMap<String, List<String>>();
|
||||
mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters));
|
||||
|
||||
final LoaderIcon loaderIcon = new LoaderIcon("Submitting request to " + chartType.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().callingDataMinerPerformFishAnalysis(mapParameters,
|
||||
new AsyncCallback<DataMinerResponse>() {
|
||||
|
||||
@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, chartType, inputKPI, outputKPI, focusID,
|
||||
panelContainer, false, oIteration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
loaderIcon.setVisible(false);
|
||||
checkTabSpinner(requestPanel, tab);
|
||||
displayOutputFilesAsStaticEntities(null, chartType, inputKPI, outputKPI, focusID,
|
||||
panelContainer, true, oIteration);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
|
||||
final DataMinerAlgorithms chartType, List<KPI> inputKPIs, List<KPI> outputKPIs, final String focusID,
|
||||
final Panel container, boolean displayError, 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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
switch (outputFile.getDataType()) {
|
||||
case IMAGE:
|
||||
PerformFishAnalyticsServiceAsync.Util.getInstance().getImageFile(outputFile,
|
||||
new AsyncCallback<String>() {
|
||||
|
||||
@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() + "<br>";
|
||||
title += "Selected Batch ID: " + focusID + "<br>";
|
||||
title += "Normalized with respect to all batches in the VRE";
|
||||
|
||||
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<CSVFile>() {
|
||||
|
||||
@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;
|
||||
|
||||
ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
|
||||
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) {
|
||||
viewController.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++) {
|
||||
|
||||
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 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);
|
||||
|
||||
}-*/;
|
||||
}
|
|
@ -0,0 +1,427 @@
|
|||
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.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.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 SynopticTablePanelResult {
|
||||
|
||||
private Map<Integer, FlexTable> synopticOrderBy = new HashMap<Integer, FlexTable>();
|
||||
|
||||
private PerformFishAnalyticsViewController viewController;
|
||||
private int requestId;
|
||||
private int outputIteration = 0;
|
||||
private int outputNumber = 0;
|
||||
|
||||
public SynopticTablePanelResult(int reqId, PerformFishAnalyticsViewController viewController,
|
||||
PerformFishResponse performFishResponse, final Map<String, List<String>> performFishRequestParameters) {
|
||||
this.requestId = reqId;
|
||||
this.viewController = viewController;
|
||||
|
||||
String batchTableURL = performFishResponse.getMapParameters().get(PerformFishAnalyticsConstant.BATCHES_TABLE);
|
||||
|
||||
if (batchTableURL == null || batchTableURL.isEmpty())
|
||||
Window.alert("Something seems wrong. No batches tables matching with parameter "
|
||||
+ PerformFishAnalyticsConstant.BATCHES_TABLE + " returned from service");
|
||||
|
||||
final Map<String, List<String>> mapParameters = new HashMap<String, List<String>>();
|
||||
|
||||
StringBuilder dataInputsFormatter = new StringBuilder();
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_INPUT_TABLE + "=" + batchTableURL + ";");
|
||||
|
||||
// READ THE INPUT FILE
|
||||
String popType = viewController.getForm().getBatchType();
|
||||
|
||||
DataMinerAlgorithms chartType = null;
|
||||
if (popType.equalsIgnoreCase(PerformFishAnalyticsConstant.BATCH_LEVEL.GROW_OUT_INDIVIDUAL_CLOSED_BATCHES.name())
|
||||
|| popType.equalsIgnoreCase(PerformFishAnalyticsConstant.BATCH_LEVEL.GROW_OUT_INDIVIDUAL.name())) {
|
||||
chartType = DataMinerAlgorithms.PERFORMFISH_SYNOPTICTABLE_BATCH;
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_QUARTER_LABELS + "="
|
||||
+ PerformFishAnalyticsConstant.DM_VALUE_ALL + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_ZONE_LABELS + "="
|
||||
+ PerformFishAnalyticsConstant.DM_VALUE_ALL + ";");
|
||||
} else if (popType
|
||||
.equalsIgnoreCase(PerformFishAnalyticsConstant.BATCH_LEVEL.HATCHERY_INDIVIDUAL_CLOSED_BATCHES.name())
|
||||
|| popType.equalsIgnoreCase(PerformFishAnalyticsConstant.BATCH_LEVEL.HATCHERY_INDIVIDUAL.name())) {
|
||||
chartType = DataMinerAlgorithms.PERFORMFISH_SYNOPTICTABLE_BATCH_HATCHERY;
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_STOCKING_PERIOD + "="
|
||||
+ PerformFishAnalyticsConstant.DM_VALUE_ALL + ";");
|
||||
} else if (popType.equalsIgnoreCase(PerformFishAnalyticsConstant.BATCH_LEVEL.PRE_ONGROWING.name()) || popType
|
||||
.equalsIgnoreCase(PerformFishAnalyticsConstant.BATCH_LEVEL.PRE_ONGROWING_CLOSED_BATCHES.name())) {
|
||||
chartType = DataMinerAlgorithms.PERFORMFISH_SYNOPTICTABLE_BATCH_PREGROW;
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_ZONE_LABELS + "="
|
||||
+ PerformFishAnalyticsConstant.DM_VALUE_ALL + ";");
|
||||
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_STOCKING_PERIOD + "="
|
||||
+ PerformFishAnalyticsConstant.DM_VALUE_ALL + ";");
|
||||
}
|
||||
|
||||
String dataInParameters = dataInputsFormatter.toString();
|
||||
mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters));
|
||||
mapParameters.put("Identifier", Arrays.asList(
|
||||
"org.gcube.dataanalysis.wps.statisticalmanager.synchserver.mappedclasses.transducerers." + chartType));
|
||||
|
||||
GWT.log("Calling DM service with client input parameters: " + mapParameters);
|
||||
|
||||
final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
|
||||
// submitRequestPanel.getElement().addClassName("ext-horizontal-panel");
|
||||
|
||||
// TODO
|
||||
final DataMinerAlgorithms algorithm = chartType;
|
||||
final String tabTitle = "Synoptic Table";
|
||||
final String tabDescr = PerformFishResources.INSTANCE.synopticTable().getText();
|
||||
final Tab tab = viewController.createTab(tabTitle + " #" + (viewController.currentNumberOfTab() + 1),
|
||||
PerformFishResources.INSTANCE.synopticTable().getText(), submitRequestPanel);
|
||||
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(algorithm.getId(), tabTitle, tabTitle, tabDescr, requestId, outputIteration, outputNumber);
|
||||
// dmResponse.getListOutput().size()
|
||||
}
|
||||
});
|
||||
|
||||
res.add(savePDFButton);
|
||||
submitRequestPanel.addWidget(res);
|
||||
outputIteration=1;
|
||||
|
||||
final HTMLPanel panelContainer = submitRequestPanel.getContainerPanel();
|
||||
|
||||
final LoaderIcon loaderIcon = new LoaderIcon(
|
||||
"Submitting request to " + DataMinerAlgorithms.PERFORMFISH_SYNOPTICTABLE_BATCH.getTitle() + "...");
|
||||
loaderIcon.setVisible(true);
|
||||
panelContainer.setVisible(true);
|
||||
panelContainer.add(loaderIcon);
|
||||
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
loaderIcon.setFocus(true);
|
||||
}
|
||||
});
|
||||
|
||||
final DataMinerAlgorithms toFinalChartType = chartType;
|
||||
PerformFishAnalyticsServiceAsync.Util.getInstance().callDMServiceToLoadSynopticTable(performFishResponse,
|
||||
mapParameters, new AsyncCallback<DataMinerResponse>() {
|
||||
|
||||
@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, toFinalChartType, null, null, null,
|
||||
panelContainer, false, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
loaderIcon.setVisible(false);
|
||||
checkTabSpinner(submitRequestPanel, tab);
|
||||
displayOutputFilesAsStaticEntities(null, toFinalChartType, null, null, null, panelContainer,
|
||||
true, 1);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
viewController.noSpinner(tab);
|
||||
}
|
||||
}
|
||||
|
||||
private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
|
||||
final DataMinerAlgorithms chartType, List<KPI> inputKPIs, List<KPI> outputKPIs, final String focusID,
|
||||
final Panel container, boolean displayError, 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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
switch (outputFile.getDataType()) {
|
||||
case IMAGE:
|
||||
PerformFishAnalyticsServiceAsync.Util.getInstance().getImageFile(outputFile,
|
||||
new AsyncCallback<String>() {
|
||||
|
||||
@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;
|
||||
|
||||
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<CSVFile>() {
|
||||
|
||||
@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_SYNOPTICTABLE_BATCH:
|
||||
case PERFORMFISH_SYNOPTICTABLE_BATCH_HATCHERY:
|
||||
case PERFORMFISH_SYNOPTICTABLE_BATCH_PREGROW:
|
||||
|
||||
if (!result.getFileName().contains("legend")) {
|
||||
cssTableStyle = "synoptictable-batch";
|
||||
} 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_SYNOPTIC_TABLE_FARM:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// ALL OTHER CASES
|
||||
ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
|
||||
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 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);
|
||||
|
||||
}-*/;
|
||||
|
||||
}
|
Loading…
Reference in New Issue