ref 17249: Save produced charts as report

https://support.d4science.org/issues/17249

Added PDF support
This commit is contained in:
Giancarlo Panichi 2020-05-25 10:34:17 +02:00
parent 5df51216d7
commit 1e35bb6848
5 changed files with 1919 additions and 681 deletions

View File

@ -30,14 +30,15 @@ import org.gcube.portlets.user.performfishanalytics.client.event.SelectedPopulat
import org.gcube.portlets.user.performfishanalytics.client.event.SubmitRequestEvent; import org.gcube.portlets.user.performfishanalytics.client.event.SubmitRequestEvent;
import org.gcube.portlets.user.performfishanalytics.client.event.SubmitRequestEventHandler; import org.gcube.portlets.user.performfishanalytics.client.event.SubmitRequestEventHandler;
import org.gcube.portlets.user.performfishanalytics.client.resources.PerformFishResources; import org.gcube.portlets.user.performfishanalytics.client.resources.PerformFishResources;
import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon;
import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.AnalyticsAnnualPanelResult; import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.AnalyticsAnnualPanelResult;
import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.BoxPlotAnnualPanelResult;
import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.DeaAnnualPanelResult; import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.DeaAnnualPanelResult;
import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.ScatterAnnualPanelResult;
import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.SpeedometerAnnualPanelResult;
import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.SynopticTableAnnualPanelResult;
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.AnalyticsPanelResult; import org.gcube.portlets.user.performfishanalytics.client.viewbinder.AnalyticsPanelResult;
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.ShowResult;
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.SubmitRequestPanel; import org.gcube.portlets.user.performfishanalytics.client.viewbinder.SubmitRequestPanel;
import org.gcube.portlets.user.performfishanalytics.shared.KPI; import org.gcube.portlets.user.performfishanalytics.shared.KPI;
import org.gcube.portlets.user.performfishanalytics.shared.OutputFile;
import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile; import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile;
import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVRow; import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVRow;
import org.gcube.portlets.user.performfishanalytics.shared.dataminer.DataMinerResponse; import org.gcube.portlets.user.performfishanalytics.shared.dataminer.DataMinerResponse;
@ -45,26 +46,12 @@ import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.Pe
import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse; import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse;
import com.github.gwtbootstrap.client.ui.Alert; 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.Tab;
import com.github.gwtbootstrap.client.ui.constants.AlertType; 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.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.event.shared.HandlerManager;
import com.google.gwt.resources.client.TextResource;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;
// TODO: Auto-generated Javadoc // TODO: Auto-generated Javadoc
/** /**
@ -91,11 +78,7 @@ public class PerformFishAnnualAnalyticsController {
// the table AnnualTable_internal.csv returned by PerformFish Service // the table AnnualTable_internal.csv returned by PerformFish Service
private String theFocusValue = null; private String theFocusValue = null;
private Map<Integer, FlexTable> boxPlotOrderBy = new HashMap<Integer, FlexTable>(); private static int requestId = 0;
private Map<Integer, FlexTable> synopticOrderBy = new HashMap<Integer, FlexTable>();
/** /**
* Instantiates a new perform fish analytics controller. * Instantiates a new perform fish analytics controller.
@ -343,78 +326,9 @@ public class PerformFishAnnualAnalyticsController {
*/ */
protected void callAlgorithmSynopticTableFarm() { protected void callAlgorithmSynopticTableFarm() {
final DataMinerAlgorithms algorithm = DataMinerAlgorithms.PERFORMFISH_SYNOPTIC_TABLE_FARM; @SuppressWarnings("unused")
final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1); SynopticTableAnnualPanelResult synopticTablePanelResult = new SynopticTableAnnualPanelResult(requestId++,
final String tabTitle = "Synoptic Table"; viewAnnualController, thePerformFishResponse);
final String tabDescr = PerformFishResources.INSTANCE.synopticTable().getText();
final Tab tab = viewAnnualController.createTab(
tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1),
tabDescr, submitRequestPanel);
StringBuilder dataInputsFormatter = new StringBuilder();
Map<String, String> performFishResponseMap = thePerformFishResponse.getMapParameters();
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.LethalIncidentsTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AnnualTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntibioticsTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntiparasiticTable);
String yearsValue = "";
for (String year : viewAnnualController.getSelectedYears()) {
yearsValue += year + "#";
}
yearsValue = yearsValue.substring(0, yearsValue.length() - 1);
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_ALLYEARS_PARAM + "=" + yearsValue + ";");
// dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_ALLYEARS_PARAM+"="+
// PerformFishAnalyticsConstant.DM_VALUE_ALL +";");
// dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_ALLYEARS_PARAM+"=2016;");
String dataInParameters = dataInputsFormatter.toString();
GWT.log("Calling DM service with client input parameters: " + dataInParameters);
Map<String, List<String>> mapParameters = new HashMap<String, List<String>>();
mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters));
final HTMLPanel panelContainer = submitRequestPanel.getContainerPanel();
final LoaderIcon loaderIcon = new LoaderIcon("Submitting request to " + algorithm.getTitle() + "...");
loaderIcon.setVisible(true);
panelContainer.setVisible(true);
panelContainer.add(loaderIcon);
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
loaderIcon.setFocus(true);
}
});
PerformFishAnalyticsServiceAsync.Util.getInstance().callDMServiceToLoadSynopticAnnualTable(
thePerformFishResponse, mapParameters, new AsyncCallback<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, algorithm, null, null, null, panelContainer,
false,tabTitle, tabDescr);
}
@Override
public void onFailure(Throwable caught) {
loaderIcon.setVisible(false);
checkTabSpinner(submitRequestPanel, tab);
displayOutputFilesAsStaticEntities(null, algorithm, null, null, null, panelContainer, true,tabTitle, tabDescr);
}
});
} }
/** /**
@ -726,217 +640,27 @@ public class PerformFishAnnualAnalyticsController {
private void callAlgorithm(DataMinerAlgorithms algorithm, String focusID, List<KPI> inputKPI, private void callAlgorithm(DataMinerAlgorithms algorithm, String focusID, List<KPI> inputKPI,
final List<KPI> outputKPI) { final List<KPI> outputKPI) {
// List<String> listBatchID = viewController.getSelectedBatchID();
//
// if(listBatchID==null || listBatchID.size()==0)
// Window.alert("Something seems wrong, no selected BatchID, try
// again");
SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
// submitRequestPanel.getElement().addClassName("ext-horizontal-panel");
// TO MANAGE ALGORITHMS DESCRIPTION
TextResource algDescr = null;
switch (algorithm) { switch (algorithm) {
case BOXPLOT: case BOXPLOT:
algDescr = PerformFishResources.INSTANCE.farm_BOXPLOT(); @SuppressWarnings("unused")
break; BoxPlotAnnualPanelResult boxPlotPanelResult = new BoxPlotAnnualPanelResult(requestId++,
case CORRELATION: viewAnnualController, thePerformFishResponse, algorithm, focusID, inputKPI, outputKPI);
algDescr = PerformFishResources.INSTANCE.farm_CORRELATION();
break;
case DEA_ANALYSIS:
break;
case DEA_CHART:
break;
case PERFORMFISH_SYNOPTIC_TABLE_FARM:
break;
case PERFORMFISH_SYNOPTICTABLE_BATCH:
break;
case SCATTER:
algDescr = PerformFishResources.INSTANCE.farm_SCATTER();
break; break;
case SPEEDOMETER: case SPEEDOMETER:
algDescr = PerformFishResources.INSTANCE.farm_SPEEDOMETER(); @SuppressWarnings("unused")
SpeedometerAnnualPanelResult speedometerPanelResult = new SpeedometerAnnualPanelResult(requestId++,
viewAnnualController, thePerformFishResponse, algorithm, focusID, inputKPI, outputKPI);
break; break;
case PERFORMFISH_SYNOPTICTABLE_BATCH_HATCHERY: case SCATTER:
break; @SuppressWarnings("unused")
case PERFORMFISH_SYNOPTICTABLE_BATCH_PREGROW: ScatterAnnualPanelResult scatterPanelResult = new ScatterAnnualPanelResult(requestId++,
viewAnnualController, thePerformFishResponse, algorithm, focusID, inputKPI, outputKPI);
break; break;
default: default:
break; break;
}
String algDesrTxt = algDescr != null ? algDescr.getText() : null;
String tabTitle = algorithm.getTitle();
String tabDescr = algDesrTxt;
Tab tab = viewAnnualController.createTab(tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1),
algDesrTxt, submitRequestPanel);
switch (algorithm) {
case BOXPLOT:
case SPEEDOMETER:
submitRequestPanel.setTotalRequests(inputKPI.size());
for (KPI kpi : inputKPI) {
String title = "KPI: " + kpi.getName();
HTML toBigTitle = new HTML(title);
toBigTitle.getElement().addClassName("to-big-title");
submitRequestPanel.addWidget(toBigTitle);
HorizontalPanel hp = new HorizontalPanel();
hp.getElement().addClassName("ext-horizontal-panel");
DataMinerInputParameters dmInputParams = new DataMinerInputParameters(thePerformFishResponse,
viewAnnualController.getSelectedYears(), Arrays.asList(kpi), null, algorithm, focusID);
callDataMinerServiceForChart(dmInputParams, submitRequestPanel, hp, tab, tabTitle, tabDescr);
// resultPanel.add(hp);
submitRequestPanel.addWidget(hp);
}
break;
case SCATTER:
if (inputKPI.get(0) == null || inputKPI.get(1) == null) {
submitRequestPanel
.setTheTitle("Sorry, something seems wrong, the selected KPIs are not valid. Please try again");
checkTabSpinner(submitRequestPanel, tab);
return;
// Window.alert("Something seems wrong, no selected BatchID, try
// again");
}
String titleScatter = "KPI: " + inputKPI.get(0).getName() + " vs " + inputKPI.get(1).getName();
submitRequestPanel.setTheTitle(titleScatter);
default: {
DataMinerInputParameters dmInputParams = new DataMinerInputParameters(thePerformFishResponse,
viewAnnualController.getSelectedYears(), inputKPI, outputKPI, algorithm, focusID);
callDataMinerServiceForChart(dmInputParams, submitRequestPanel, submitRequestPanel.getContainerPanel(),
tab,tabTitle, tabDescr);
// callDataMinerServiceForChart(thePerformFishResponse,
// POPULATION_LEVEL.BATCH, inputKPI, outputKPI, algorithm, focusID,
// submitRequestPanel, submitRequestPanel.getContainerPanel(), tab);
}
}
}
/**
* Call data miner service for chart.
*
* @param dmInputParameters
* the dm input parameters
* @param requestPanel
* the request panel
* @param panelContainer
* the panel
* @param tab
* the tab
* @param tabDescr
* @param tabTitle
*/
private void callDataMinerServiceForChart(final DataMinerInputParameters dmInputParameters,
final SubmitRequestPanel requestPanel, final ComplexPanel panelContainer, final Tab tab, final String tabTitle, final String tabDescr) {
GWT.log("Building DM request with input parameters: " + dmInputParameters);
StringBuilder dataInputsFormatter = new StringBuilder();
dataInputsFormatter
.append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM + "=" + dmInputParameters.getChartType() + ";");
String yearsValue = "";
for (String year : dmInputParameters.getSelectedYears()) {
yearsValue += year + "|";
}
yearsValue = yearsValue.substring(0, yearsValue.length() - 1);
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_YEARS_PARAM + "=" + yearsValue + ";");
dataInputsFormatter
.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM + "=" + dmInputParameters.getFocusID() + ";");
// dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM+"=ID;");
if (dmInputParameters.getInputKPI() != null && dmInputParameters.getInputKPI().size() > 0) {
String kpiCodes = "";
for (KPI kpi : dmInputParameters.getInputKPI()) {
kpiCodes += kpi.getCode() + "|";
}
// remove last |
kpiCodes = kpiCodes.substring(0, kpiCodes.length() - 1);
GWT.log("Input KPICodes: " + kpiCodes);
// ADDING KPIs code
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_INPUT_KPI_PARAM + "=" + kpiCodes + ";");
} }
if (dmInputParameters.getOutputKPI() != null && dmInputParameters.getOutputKPI().size() > 0) {
String kpiCodes = "";
for (KPI kpi : dmInputParameters.getOutputKPI()) {
kpiCodes += kpi.getCode() + "|";
}
// remove last |
kpiCodes = kpiCodes.substring(0, kpiCodes.length() - 1);
GWT.log("Output KPICodes: " + kpiCodes);
// ADDING KPIs code
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_OUTPUT_KPI_PARAM + "=" + kpiCodes + ";");
}
Map<String, String> performFishResponseMap = dmInputParameters.getPerformFishResponse().getMapParameters();
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.LethalIncidentsTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AnnualTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntibioticsTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntiparasiticTable);
String dataInParameters = dataInputsFormatter.toString();
GWT.log("Calling DM service with client input parameters: " + dataInParameters);
Map<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 " + dmInputParameters.getChartType().getTitle() + " Analysis...");
loaderIcon.setVisible(true);
panelContainer.setVisible(true);
panelContainer.add(loaderIcon);
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
loaderIcon.setFocus(true);
}
});
PerformFishAnalyticsServiceAsync.Util.getInstance().callingDataMinerPerformFishAnnualAnalysis(mapParameters,
new AsyncCallback<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, dmInputParameters.getChartType(),
dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
dmInputParameters.getFocusID(), panelContainer, false,tabTitle, tabDescr);
}
@Override
public void onFailure(Throwable caught) {
loaderIcon.setVisible(false);
checkTabSpinner(requestPanel, tab);
displayOutputFilesAsStaticEntities(null, dmInputParameters.getChartType(),
dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
dmInputParameters.getFocusID(), panelContainer, true,tabTitle, tabDescr);
}
});
} }
/** /**
@ -980,392 +704,6 @@ public class PerformFishAnnualAnalyticsController {
} }
} }
/**
* Display output files as static entities.
*
* @param dmResponse
* the dm response
* @param chartType
* the chart type
* @param inputKPIs
* the input kp is
* @param outputKPIs
* the output kp is
* @param focusID
* the focus id
* @param container
* the container
* @param displayError
* the display error
* @param tabDescr
* @param tabTitle
*/
private void displayOutputFilesAsStaticEntities(final DataMinerResponse dmResponse,
final DataMinerAlgorithms chartType, List<KPI> inputKPIs, List<KPI> outputKPIs, final String focusID,
final Panel container, boolean displayError, final String tabTitle, final String tabDescr) {
String title = displayError ? "No results " : "";
if (displayError) {
Alert alert = new Alert(title);
alert.setType(AlertType.ERROR);
alert.setClose(false);
alert.getElement().getStyle().setMargin(10, Unit.PX);
container.add(alert);
return;
}
VerticalPanel vp = new VerticalPanel();
final HorizontalPanel res = new HorizontalPanel();
Button savePDFButton = new Button();
savePDFButton.getElement().getStyle().setMargin(10, Unit.PX);
savePDFButton.setIcon(IconType.PRINT);
savePDFButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
saveFilePDF(res,tabTitle,tabTitle,tabDescr,dmResponse.getListOutput().size());
}
});
vp.add(savePDFButton);
vp.add(res);
container.add(vp);
final String toTitle = title;
int outputNumber = 0;
for (final OutputFile outputFile : dmResponse.getListOutput()) {
outputNumber++;
final String outputId = "OutputId_" + outputNumber;
switch (outputFile.getDataType()) {
case IMAGE:
PerformFishAnalyticsServiceAsync.Util.getInstance().getImageFile(outputFile,
new AsyncCallback<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;
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.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 Farm: " + focusID + "<br>";
title += "Normalized with respect to all farm data in the VRE";
break;
case DEA_CHART:
break;
case PERFORMFISH_SYNOPTICTABLE_BATCH:
break;
case PERFORMFISH_SYNOPTICTABLE_BATCH_HATCHERY:
break;
case PERFORMFISH_SYNOPTICTABLE_BATCH_PREGROW:
break;
case PERFORMFISH_SYNOPTIC_TABLE_FARM:
break;
default:
break;
}
ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
showResult.showImage(base64Content);
container.add(showResult);
}
});
break;
case CSV:
PerformFishAnalyticsServiceAsync.Util.getInstance().getCSVFile(outputFile, true,
new AsyncCallback<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)";
return;
} else {
title = "All farm data in the VRE (including mine)";
}
title += "<br>";
title += "Data aggregation is performed by considering farms as base units";
ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
showResult.showCSVFile(result, cssTableStyle);
displayingOrderedBoxPlot(dmResponse, title, container, showResult);
return;
case CORRELATION:
break;
case DEA_ANALYSIS:
break;
case SCATTER:
break;
case SPEEDOMETER:
break;
case DEA_CHART:
break;
case PERFORMFISH_SYNOPTIC_TABLE_FARM:
if (!result.getFileName().contains("legend")) {
cssTableStyle = "synoptictable-farm";
} else {
cssTableStyle = "simpletable-synoptic";
}
ShowResult showResultSin = new ShowResult(outputId, title,
outputFile.getDataType());
showResultSin.showCSVFile(result, cssTableStyle);
displayingOrderedSynopticTable(dmResponse, result.getFileName(), container,
showResultSin);
return;
case PERFORMFISH_SYNOPTICTABLE_BATCH:
break;
case PERFORMFISH_SYNOPTICTABLE_BATCH_HATCHERY:
break;
case PERFORMFISH_SYNOPTICTABLE_BATCH_PREGROW:
break;
default:
break;
}
ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
showResult.showCSVFile(result, cssTableStyle);
container.add(showResult);
}
});
break;
default:
break;
}
}
}
/**
* Displaying ordered synoptic table.
*
* @param dmResponse
* the dm response
* @param fileName
* the file name
* @param container
* the container
* @param showResult
* the show result
*/
private void displayingOrderedSynopticTable(final DataMinerResponse dmResponse, String fileName,
final Panel container, ShowResult showResult) {
int hashcode = dmResponse.hashCode();
GWT.log("The hascode is: " + hashcode);
FlexTable flex = synopticOrderBy.get(hashcode);
if (flex == null) {
GWT.log("The flextable is null");
flex = new FlexTable();
synopticOrderBy.put(hashcode, flex);
container.add(flex);
}
if (fileName.toLowerCase().contains("legend")) {
flex.setWidget(0, 0, showResult);
} else {
flex.setWidget(flex.getRowCount() + 1, 0, showResult);
}
}
/**
* Displaying ordered box plot.
*
* @param dmResponse
* the dm response
* @param title
* the title
* @param container
* the container
* @param showResult
* the show result
*/
private void displayingOrderedBoxPlot(final DataMinerResponse dmResponse, String title, final Panel container,
ShowResult showResult) {
int hashcode = dmResponse.hashCode();
GWT.log("The hascode is: " + hashcode);
FlexTable flex = boxPlotOrderBy.get(hashcode);
if (flex == null) {
GWT.log("The flextable is null");
flex = new FlexTable();
boxPlotOrderBy.put(hashcode, flex);
container.add(flex);
}
if (title.startsWith("My")) {
flex.setWidget(0, 0, showResult);
} else if (title.startsWith("All")) {
flex.setWidget(0, 1, showResult);
} else {
flex.setWidget(0, 2, showResult);
}
}
private static native void saveFilePDF(HorizontalPanel chart, String filename, String tabTitle, String tabDescr, int outputNumber)/*-{
var that = this;
console.log('saveFilePDF()');
var tTitle=tabTitle;
var tDescr=tabDescr;
var result = chart;
console.log(chart);
var pdoc = new jsPDF("p", "mm", "a4");
pdoc.setProperties({
title : 'PerformFish '+tTitle,
subject : ' Results',
author : 'PerformFish',
keywords : 'PerformFish',
creator : 'D4Science'
});
var lMargin = 15; //left margin in mm
var rMargin = 15; //right margin in mm
var tMargin = 15; //top margin in mm
var bMargin = 15; //bottom margin in mm
var pdfWidthInMM = 210; // width of A4 in mm
var pdfHeightInMM = 297; // height of A4 in mm
var pageCenter = pdfWidthInMM / 2;
pdoc.setFontSize(24);
var title = "PerformFish "+tTitle;
var titleHeight = pdoc.getLineHeight(title) / pdoc.internal.scaleFactor
var xPos = lMargin;
var yPos = tMargin;
pdoc.text(title, pageCenter, yPos, 'center');
yPos += titleHeight;
pdoc.setFontSize(10);
var lineHeight = pdoc.getLineHeight(tDescr)
/ pdoc.internal.scaleFactor
var splittedAnalysisDescription = pdoc.splitTextToSize(
tDescr, (pdfWidthInMM - lMargin - rMargin));
var lines = splittedAnalysisDescription.length // splitted text is a string array
var analysisDescriptionHeight = lines * lineHeight
pdoc.text(splittedAnalysisDescription, xPos, yPos, 'left');
yPos += analysisDescriptionHeight;
//yPos += 2;
//pdoc.text("Analysis:", xPos, yPos, 'left');
yPos += 6;
for (var i = 1; i <= outputNumber; i++) {
var outputId = 'OutputId_'+ i;
console.log('OutputId: ' + outputId);
var resultOutputNumber = $doc.getElementById(outputId);
console.log('OutputId_: ' + resultOutputNumber.innerHTML);
var resultType = resultOutputNumber.className;
console.log('resultOutputNumber className: ' + resultType);
if (typeof resultType !== 'undefined' && resultType !== null
&& resultType !== '') {
if (resultType == 'csv') {
console.log('Result Type csv: ' + i);
// foo could get resolved and it's defined
var childrenTable = resultOutputNumber.children;
var secondDiv = childrenTable[0].rows[1].cells[0];
var secondTable = secondDiv.children[0].children[0];
console.log('CSV SecondTable: ' + secondTable);
pdoc.autoTable({
theme : 'grid',
startY : yPos,
pageBreak : 'auto',
bodyStyles : {
fontSize : 9
},
html : secondTable
});
yPos = pdoc.previousAutoTable.finalY + 6;
} else {
if (resultType == 'image') {
console.log('Result Type image: ' + i);
var childrenTable = resultOutputNumber.children;
var secondDiv = childrenTable[0].rows[1].cells[0];
var imageElement = secondDiv.getElementsByTagName(
'img').item(0);
console.log('Image element: ' + imageElement);
pdoc.addImage(imageElement, lMargin, yPos);
console.log('Image Height: ' + imageElement.height);
yPos += (imageElement.height * 0.26458333);
} else {
console.log('Result Type unknow: ' + i);
}
}
} else {
console.log('Result Type is undefined:' + i);
}
}
console.log('Done');
pdoc.save(filename);
}-*/;
} }

View File

@ -0,0 +1,505 @@
package org.gcube.portlets.user.performfishanalytics.client.viewannualbinder;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.user.performfishanalytics.client.DataMinerAlgorithms;
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant;
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE;
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync;
import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.DataMinerInputParameters;
import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.PerformFishAnnualAnalyticsViewController;
import org.gcube.portlets.user.performfishanalytics.client.resources.PerformFishResources;
import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon;
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.ShowResult;
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.SubmitRequestPanel;
import org.gcube.portlets.user.performfishanalytics.shared.KPI;
import org.gcube.portlets.user.performfishanalytics.shared.OutputFile;
import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile;
import org.gcube.portlets.user.performfishanalytics.shared.dataminer.DataMinerResponse;
import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse;
import com.github.gwtbootstrap.client.ui.Alert;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Tab;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.resources.client.TextResource;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Panel;
public class BoxPlotAnnualPanelResult {
private Map<Integer, FlexTable> boxPlotOrderBy = new HashMap<Integer, FlexTable>();
private PerformFishAnnualAnalyticsViewController viewAnnualController;
private int outputIteration = 0;
private int outputNumber = 0;
private int requestId;
public BoxPlotAnnualPanelResult(int reqId, PerformFishAnnualAnalyticsViewController viewAnnualController,
PerformFishResponse thePerformFishResponse,
final DataMinerAlgorithms algorithm, String focusID, List<KPI> inputKPI, final List<KPI> outputKPI) {
this.requestId = reqId;
this.viewAnnualController = viewAnnualController;
TextResource algDescr = PerformFishResources.INSTANCE.farm_BOXPLOT();
String algDesrTxt = algDescr != null ? algDescr.getText() : null;
// TODO
final String tabTitle = algorithm.getTitle();
final String tabDescr = algDesrTxt;
final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
Tab tab = viewAnnualController.createTab(tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1),
algDesrTxt, submitRequestPanel);
HorizontalPanel res = new HorizontalPanel();
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");
DataMinerInputParameters dmInputParams = new DataMinerInputParameters(thePerformFishResponse,
viewAnnualController.getSelectedYears(), Arrays.asList(kpi), null, algorithm, focusID);
callDataMinerServiceForChart(dmInputParams, submitRequestPanel, hp, tab, oIteration);
// resultPanel.add(hp);
submitRequestPanel.addWidget(hp);
}
outputIteration = oIteration;
}
/**
* Call data miner service for chart.
*
* @param dmInputParameters
* the dm input parameters
* @param requestPanel
* the request panel
* @param panelContainer
* the panel
* @param tab
* the tab
* @param tabDescr
* @param tabTitle
*/
private void callDataMinerServiceForChart(final DataMinerInputParameters dmInputParameters,
final SubmitRequestPanel requestPanel, final ComplexPanel panelContainer, final Tab tab, final int oIteration) {
GWT.log("Building DM request with input parameters: " + dmInputParameters);
StringBuilder dataInputsFormatter = new StringBuilder();
dataInputsFormatter
.append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM + "=" + dmInputParameters.getChartType() + ";");
String yearsValue = "";
for (String year : dmInputParameters.getSelectedYears()) {
yearsValue += year + "|";
}
yearsValue = yearsValue.substring(0, yearsValue.length() - 1);
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_YEARS_PARAM + "=" + yearsValue + ";");
dataInputsFormatter
.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM + "=" + dmInputParameters.getFocusID() + ";");
// dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM+"=ID;");
if (dmInputParameters.getInputKPI() != null && dmInputParameters.getInputKPI().size() > 0) {
String kpiCodes = "";
for (KPI kpi : dmInputParameters.getInputKPI()) {
kpiCodes += kpi.getCode() + "|";
}
// remove last |
kpiCodes = kpiCodes.substring(0, kpiCodes.length() - 1);
GWT.log("Input KPICodes: " + kpiCodes);
// ADDING KPIs code
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_INPUT_KPI_PARAM + "=" + kpiCodes + ";");
}
if (dmInputParameters.getOutputKPI() != null && dmInputParameters.getOutputKPI().size() > 0) {
String kpiCodes = "";
for (KPI kpi : dmInputParameters.getOutputKPI()) {
kpiCodes += kpi.getCode() + "|";
}
// remove last |
kpiCodes = kpiCodes.substring(0, kpiCodes.length() - 1);
GWT.log("Output KPICodes: " + kpiCodes);
// ADDING KPIs code
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_OUTPUT_KPI_PARAM + "=" + kpiCodes + ";");
}
Map<String, String> performFishResponseMap = dmInputParameters.getPerformFishResponse().getMapParameters();
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.LethalIncidentsTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AnnualTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntibioticsTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntiparasiticTable);
String dataInParameters = dataInputsFormatter.toString();
GWT.log("Calling DM service with client input parameters: " + dataInParameters);
Map<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 " + dmInputParameters.getChartType().getTitle() + " Analysis...");
loaderIcon.setVisible(true);
panelContainer.setVisible(true);
panelContainer.add(loaderIcon);
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
loaderIcon.setFocus(true);
}
});
PerformFishAnalyticsServiceAsync.Util.getInstance().callingDataMinerPerformFishAnnualAnalysis(mapParameters,
new AsyncCallback<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, dmInputParameters.getChartType(),
dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
dmInputParameters.getFocusID(), panelContainer, false,oIteration);
}
@Override
public void onFailure(Throwable caught) {
loaderIcon.setVisible(false);
checkTabSpinner(requestPanel, tab);
displayOutputFilesAsStaticEntities(null, dmInputParameters.getChartType(),
dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
dmInputParameters.getFocusID(), panelContainer, true,oIteration);
}
});
}
/**
* Append DM input table.
*
* @param performFishResponseMap
* the perform fish response map
* @param dataInputsFormatter
* the data inputs formatter
* @param table
* the table
* @return the string builder
*/
private StringBuilder appendDMInputTable(Map<String, String> performFishResponseMap,
StringBuilder dataInputsFormatter, PFSERVICE_TO_DM_MAPPING_TABLE table) {
String toDMInputTable = performFishResponseMap.get(table.getPerformFishTable());
if (toDMInputTable != null && !toDMInputTable.isEmpty()) {
dataInputsFormatter.append(table.getDataMinerTable() + "=" + toDMInputTable + ";");
}
return dataInputsFormatter;
}
private 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() + " - on all farm data<br>";
title += "Blue dots indicate the selected farm: " + 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)";
return;
} else {
title = "All farm data in the VRE (including mine)";
}
title += "<br>";
title += "Data aggregation is performed by considering farms as base units";
ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
showResult.showCSVFile(result, cssTableStyle);
displayingOrderedBoxPlot(dmResponse, title, container, showResult);
}
});
break;
default:
break;
}
}
}
private void displayingOrderedBoxPlot(final DataMinerResponse dmResponse, String title, final Panel container,
ShowResult showResult) {
int hashcode = dmResponse.hashCode();
GWT.log("The hascode is: " + hashcode);
FlexTable flex = boxPlotOrderBy.get(hashcode);
if (flex == null) {
GWT.log("The flextable is null");
flex = new FlexTable();
boxPlotOrderBy.put(hashcode, flex);
container.add(flex);
}
if (title.startsWith("My")) {
flex.setWidget(0, 0, showResult);
} else if (title.startsWith("All")) {
flex.setWidget(0, 1, showResult);
} else {
flex.setWidget(0, 2, showResult);
}
}
/**
* Remove the spinner if all DM responses are returned.
*
* @param requestPanel
* the request panel
* @param tab
* the tab
*/
private void checkTabSpinner(SubmitRequestPanel requestPanel, Tab tab) {
requestPanel.incrementCompletedRequests();
int completed = requestPanel.getCompletedRequests();
int total = requestPanel.getTotalRequests();
if (completed >= total) {
viewAnnualController.noSpinner(tab);
}
}
private static native void saveFilePDF(String chartType, String filename, String tabTitle, String tabDescr,
int requestId, int outputIteration, int outputNumber)/*-{
var that = this;
console.log('saveFilePDF()');
console.log('requestId: ' + requestId);
console.log('OutputIteration: ' + outputIteration);
console.log('OutputNumber:' + outputNumber);
var tTitle = tabTitle;
var tDescr = tabDescr;
var pdoc = new jsPDF("p", "mm", "a4");
pdoc.setProperties({
title : 'PerformFish ' + tTitle,
subject : ' Results',
author : 'PerformFish',
keywords : 'PerformFish',
creator : 'D4Science'
});
var lMargin = 15; //left margin in mm
var rMargin = 15; //right margin in mm
var tMargin = 15; //top margin in mm
var bMargin = 15; //bottom margin in mm
var pdfWidthInMM = 210; // width of A4 in mm
var pdfHeightInMM = 297; // height of A4 in mm
var pageCenter = pdfWidthInMM / 2;
pdoc.setFontSize(24);
var title = "PerformFish " + tTitle;
var titleHeight = pdoc.getLineHeight(title) / pdoc.internal.scaleFactor
var xPos = lMargin;
var yPos = tMargin;
pdoc.text(title, pageCenter, yPos, 'center');
yPos += titleHeight;
pdoc.setFontSize(10);
var lineHeight = pdoc.getLineHeight(tDescr) / pdoc.internal.scaleFactor
var splittedAnalysisDescription = pdoc.splitTextToSize(tDescr,
(pdfWidthInMM - lMargin - rMargin));
var lines = splittedAnalysisDescription.length // splitted text is a string array
var analysisDescriptionHeight = lines * lineHeight
pdoc.text(splittedAnalysisDescription, xPos, yPos, 'left');
yPos += analysisDescriptionHeight;
//yPos += 2;
//pdoc.text("Analysis:", xPos, yPos, 'left');
yPos += 6;
for (var i = 1; i <= outputIteration; i++) {
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);
}-*/;
}

View File

@ -0,0 +1,464 @@
package org.gcube.portlets.user.performfishanalytics.client.viewannualbinder;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.user.performfishanalytics.client.DataMinerAlgorithms;
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant;
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE;
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync;
import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.DataMinerInputParameters;
import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.PerformFishAnnualAnalyticsViewController;
import org.gcube.portlets.user.performfishanalytics.client.resources.PerformFishResources;
import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon;
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.ShowResult;
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.SubmitRequestPanel;
import org.gcube.portlets.user.performfishanalytics.shared.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 ScatterAnnualPanelResult {
private PerformFishAnnualAnalyticsViewController viewAnnualController;
private int requestId;
private int outputIteration = 0;
private int outputNumber = 0;
public ScatterAnnualPanelResult(int reqId, PerformFishAnnualAnalyticsViewController viewAnnualController,
PerformFishResponse thePerformFishResponse, final DataMinerAlgorithms algorithm, String focusID,
List<KPI> inputKPI, final List<KPI> outputKPI) {
this.requestId = reqId;
this.viewAnnualController = viewAnnualController;
TextResource algDescr = PerformFishResources.INSTANCE.farm_SCATTER();
String algDesrTxt = algDescr != null ? algDescr.getText() : null;
// TODO
final String tabTitle = algorithm.getTitle();
final String tabDescr = algDesrTxt;
final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
Tab tab = viewAnnualController.createTab(tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1),
algDesrTxt, submitRequestPanel);
HorizontalPanel res = new HorizontalPanel();
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);
DataMinerInputParameters dmInputParams = new DataMinerInputParameters(thePerformFishResponse,
viewAnnualController.getSelectedYears(), inputKPI, outputKPI, algorithm, focusID);
callDataMinerServiceForChart(dmInputParams, submitRequestPanel, submitRequestPanel.getContainerPanel(), tab,
oIteration);
outputIteration = oIteration;
}
/**
* Call data miner service for chart.
*
* @param dmInputParameters
* the dm input parameters
* @param requestPanel
* the request panel
* @param panelContainer
* the panel
* @param tab
* the tab
* @param tabDescr
* @param tabTitle
*/
private void callDataMinerServiceForChart(final DataMinerInputParameters dmInputParameters,
final SubmitRequestPanel requestPanel, final ComplexPanel panelContainer, final Tab tab,
final int oIteration) {
GWT.log("Building DM request with input parameters: " + dmInputParameters);
StringBuilder dataInputsFormatter = new StringBuilder();
dataInputsFormatter
.append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM + "=" + dmInputParameters.getChartType() + ";");
String yearsValue = "";
for (String year : dmInputParameters.getSelectedYears()) {
yearsValue += year + "|";
}
yearsValue = yearsValue.substring(0, yearsValue.length() - 1);
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_YEARS_PARAM + "=" + yearsValue + ";");
dataInputsFormatter
.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM + "=" + dmInputParameters.getFocusID() + ";");
// dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM+"=ID;");
if (dmInputParameters.getInputKPI() != null && dmInputParameters.getInputKPI().size() > 0) {
String kpiCodes = "";
for (KPI kpi : dmInputParameters.getInputKPI()) {
kpiCodes += kpi.getCode() + "|";
}
// remove last |
kpiCodes = kpiCodes.substring(0, kpiCodes.length() - 1);
GWT.log("Input KPICodes: " + kpiCodes);
// ADDING KPIs code
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_INPUT_KPI_PARAM + "=" + kpiCodes + ";");
}
if (dmInputParameters.getOutputKPI() != null && dmInputParameters.getOutputKPI().size() > 0) {
String kpiCodes = "";
for (KPI kpi : dmInputParameters.getOutputKPI()) {
kpiCodes += kpi.getCode() + "|";
}
// remove last |
kpiCodes = kpiCodes.substring(0, kpiCodes.length() - 1);
GWT.log("Output KPICodes: " + kpiCodes);
// ADDING KPIs code
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_OUTPUT_KPI_PARAM + "=" + kpiCodes + ";");
}
Map<String, String> performFishResponseMap = dmInputParameters.getPerformFishResponse().getMapParameters();
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.LethalIncidentsTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AnnualTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntibioticsTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntiparasiticTable);
String dataInParameters = dataInputsFormatter.toString();
GWT.log("Calling DM service with client input parameters: " + dataInParameters);
Map<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 " + dmInputParameters.getChartType().getTitle() + " Analysis...");
loaderIcon.setVisible(true);
panelContainer.setVisible(true);
panelContainer.add(loaderIcon);
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
loaderIcon.setFocus(true);
}
});
PerformFishAnalyticsServiceAsync.Util.getInstance().callingDataMinerPerformFishAnnualAnalysis(mapParameters,
new AsyncCallback<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, dmInputParameters.getChartType(),
dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
dmInputParameters.getFocusID(), panelContainer, false, oIteration);
}
@Override
public void onFailure(Throwable caught) {
loaderIcon.setVisible(false);
checkTabSpinner(requestPanel, tab);
displayOutputFilesAsStaticEntities(null, dmInputParameters.getChartType(),
dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
dmInputParameters.getFocusID(), panelContainer, true, oIteration);
}
});
}
/**
* Append DM input table.
*
* @param performFishResponseMap
* the perform fish response map
* @param dataInputsFormatter
* the data inputs formatter
* @param table
* the table
* @return the string builder
*/
private StringBuilder appendDMInputTable(Map<String, String> performFishResponseMap,
StringBuilder dataInputsFormatter, PFSERVICE_TO_DM_MAPPING_TABLE table) {
String toDMInputTable = performFishResponseMap.get(table.getPerformFishTable());
if (toDMInputTable != null && !toDMInputTable.isEmpty()) {
dataInputsFormatter.append(table.getDataMinerTable() + "=" + toDMInputTable + ";");
}
return dataInputsFormatter;
}
private 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) {
viewAnnualController.noSpinner(tab);
}
}
private static native void saveFilePDF(String chartType, String filename, String tabTitle, String tabDescr,
int requestId, int outputIteration, int outputNumber)/*-{
var that = this;
console.log('saveFilePDF()');
console.log('requestId: ' + requestId);
console.log('OutputIteration: ' + outputIteration);
console.log('OutputNumber:' + outputNumber);
var tTitle = tabTitle;
var tDescr = tabDescr;
var pdoc = new jsPDF("p", "mm", "a4");
pdoc.setProperties({
title : 'PerformFish ' + tTitle,
subject : ' Results',
author : 'PerformFish',
keywords : 'PerformFish',
creator : 'D4Science'
});
var lMargin = 15; //left margin in mm
var rMargin = 15; //right margin in mm
var tMargin = 15; //top margin in mm
var bMargin = 15; //bottom margin in mm
var pdfWidthInMM = 210; // width of A4 in mm
var pdfHeightInMM = 297; // height of A4 in mm
var pageCenter = pdfWidthInMM / 2;
pdoc.setFontSize(24);
var title = "PerformFish " + tTitle;
var titleHeight = pdoc.getLineHeight(title) / pdoc.internal.scaleFactor
var xPos = lMargin;
var yPos = tMargin;
pdoc.text(title, pageCenter, yPos, 'center');
yPos += titleHeight;
pdoc.setFontSize(10);
var lineHeight = pdoc.getLineHeight(tDescr) / pdoc.internal.scaleFactor
var splittedAnalysisDescription = pdoc.splitTextToSize(tDescr,
(pdfWidthInMM - lMargin - rMargin));
var lines = splittedAnalysisDescription.length // splitted text is a string array
var analysisDescriptionHeight = lines * lineHeight
pdoc.text(splittedAnalysisDescription, xPos, yPos, 'left');
yPos += analysisDescriptionHeight;
//yPos += 2;
//pdoc.text("Analysis:", xPos, yPos, 'left');
yPos += 6;
for (var i = 1; i <= outputIteration; i++) {
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);
}-*/;
}

View File

@ -0,0 +1,497 @@
package org.gcube.portlets.user.performfishanalytics.client.viewannualbinder;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.user.performfishanalytics.client.DataMinerAlgorithms;
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant;
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE;
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync;
import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.DataMinerInputParameters;
import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.PerformFishAnnualAnalyticsViewController;
import org.gcube.portlets.user.performfishanalytics.client.resources.PerformFishResources;
import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon;
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.ShowResult;
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.SubmitRequestPanel;
import org.gcube.portlets.user.performfishanalytics.shared.KPI;
import org.gcube.portlets.user.performfishanalytics.shared.OutputFile;
import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile;
import org.gcube.portlets.user.performfishanalytics.shared.dataminer.DataMinerResponse;
import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse;
import com.github.gwtbootstrap.client.ui.Alert;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Tab;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.resources.client.TextResource;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Panel;
public class SpeedometerAnnualPanelResult {
private Map<Integer, FlexTable> boxPlotOrderBy = new HashMap<Integer, FlexTable>();
private PerformFishAnnualAnalyticsViewController viewAnnualController;
private int outputIteration = 0;
private int outputNumber = 0;
private int requestId;
public SpeedometerAnnualPanelResult(int reqId, PerformFishAnnualAnalyticsViewController viewAnnualController,
PerformFishResponse thePerformFishResponse,
final DataMinerAlgorithms algorithm, String focusID, List<KPI> inputKPI, final List<KPI> outputKPI) {
this.requestId = reqId;
this.viewAnnualController = viewAnnualController;
TextResource algDescr = PerformFishResources.INSTANCE.farm_SPEEDOMETER();
String algDesrTxt = algDescr != null ? algDescr.getText() : null;
// TODO
final String tabTitle = algorithm.getTitle();
final String tabDescr = algDesrTxt;
final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
Tab tab = viewAnnualController.createTab(tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1),
algDesrTxt, submitRequestPanel);
HorizontalPanel res = new HorizontalPanel();
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");
DataMinerInputParameters dmInputParams = new DataMinerInputParameters(thePerformFishResponse,
viewAnnualController.getSelectedYears(), Arrays.asList(kpi), null, algorithm, focusID);
callDataMinerServiceForChart(dmInputParams, submitRequestPanel, hp, tab, oIteration);
// resultPanel.add(hp);
submitRequestPanel.addWidget(hp);
}
outputIteration = oIteration;
}
/**
* Call data miner service for chart.
*
* @param dmInputParameters
* the dm input parameters
* @param requestPanel
* the request panel
* @param panelContainer
* the panel
* @param tab
* the tab
* @param tabDescr
* @param tabTitle
*/
private void callDataMinerServiceForChart(final DataMinerInputParameters dmInputParameters,
final SubmitRequestPanel requestPanel, final ComplexPanel panelContainer, final Tab tab, final int oIteration) {
GWT.log("Building DM request with input parameters: " + dmInputParameters);
StringBuilder dataInputsFormatter = new StringBuilder();
dataInputsFormatter
.append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM + "=" + dmInputParameters.getChartType() + ";");
String yearsValue = "";
for (String year : dmInputParameters.getSelectedYears()) {
yearsValue += year + "|";
}
yearsValue = yearsValue.substring(0, yearsValue.length() - 1);
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_YEARS_PARAM + "=" + yearsValue + ";");
dataInputsFormatter
.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM + "=" + dmInputParameters.getFocusID() + ";");
// dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM+"=ID;");
if (dmInputParameters.getInputKPI() != null && dmInputParameters.getInputKPI().size() > 0) {
String kpiCodes = "";
for (KPI kpi : dmInputParameters.getInputKPI()) {
kpiCodes += kpi.getCode() + "|";
}
// remove last |
kpiCodes = kpiCodes.substring(0, kpiCodes.length() - 1);
GWT.log("Input KPICodes: " + kpiCodes);
// ADDING KPIs code
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_INPUT_KPI_PARAM + "=" + kpiCodes + ";");
}
if (dmInputParameters.getOutputKPI() != null && dmInputParameters.getOutputKPI().size() > 0) {
String kpiCodes = "";
for (KPI kpi : dmInputParameters.getOutputKPI()) {
kpiCodes += kpi.getCode() + "|";
}
// remove last |
kpiCodes = kpiCodes.substring(0, kpiCodes.length() - 1);
GWT.log("Output KPICodes: " + kpiCodes);
// ADDING KPIs code
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_OUTPUT_KPI_PARAM + "=" + kpiCodes + ";");
}
Map<String, String> performFishResponseMap = dmInputParameters.getPerformFishResponse().getMapParameters();
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.LethalIncidentsTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AnnualTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntibioticsTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntiparasiticTable);
String dataInParameters = dataInputsFormatter.toString();
GWT.log("Calling DM service with client input parameters: " + dataInParameters);
Map<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 " + dmInputParameters.getChartType().getTitle() + " Analysis...");
loaderIcon.setVisible(true);
panelContainer.setVisible(true);
panelContainer.add(loaderIcon);
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
loaderIcon.setFocus(true);
}
});
PerformFishAnalyticsServiceAsync.Util.getInstance().callingDataMinerPerformFishAnnualAnalysis(mapParameters,
new AsyncCallback<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, dmInputParameters.getChartType(),
dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
dmInputParameters.getFocusID(), panelContainer, false,oIteration);
}
@Override
public void onFailure(Throwable caught) {
loaderIcon.setVisible(false);
checkTabSpinner(requestPanel, tab);
displayOutputFilesAsStaticEntities(null, dmInputParameters.getChartType(),
dmInputParameters.getInputKPI(), dmInputParameters.getOutputKPI(),
dmInputParameters.getFocusID(), panelContainer, true,oIteration);
}
});
}
/**
* Append DM input table.
*
* @param performFishResponseMap
* the perform fish response map
* @param dataInputsFormatter
* the data inputs formatter
* @param table
* the table
* @return the string builder
*/
private StringBuilder appendDMInputTable(Map<String, String> performFishResponseMap,
StringBuilder dataInputsFormatter, PFSERVICE_TO_DM_MAPPING_TABLE table) {
String toDMInputTable = performFishResponseMap.get(table.getPerformFishTable());
if (toDMInputTable != null && !toDMInputTable.isEmpty()) {
dataInputsFormatter.append(table.getDataMinerTable() + "=" + toDMInputTable + ";");
}
return dataInputsFormatter;
}
private 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 Farm: " + focusID + "<br>";
title += "Normalized with respect to all farm data 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;
}
}
}
private void displayingOrderedBoxPlot(final DataMinerResponse dmResponse, String title, final Panel container,
ShowResult showResult) {
int hashcode = dmResponse.hashCode();
GWT.log("The hascode is: " + hashcode);
FlexTable flex = boxPlotOrderBy.get(hashcode);
if (flex == null) {
GWT.log("The flextable is null");
flex = new FlexTable();
boxPlotOrderBy.put(hashcode, flex);
container.add(flex);
}
if (title.startsWith("My")) {
flex.setWidget(0, 0, showResult);
} else if (title.startsWith("All")) {
flex.setWidget(0, 1, showResult);
} else {
flex.setWidget(0, 2, showResult);
}
}
/**
* Remove the spinner if all DM responses are returned.
*
* @param requestPanel
* the request panel
* @param tab
* the tab
*/
private void checkTabSpinner(SubmitRequestPanel requestPanel, Tab tab) {
requestPanel.incrementCompletedRequests();
int completed = requestPanel.getCompletedRequests();
int total = requestPanel.getTotalRequests();
if (completed >= total) {
viewAnnualController.noSpinner(tab);
}
}
private static native void saveFilePDF(String chartType, String filename, String tabTitle, String tabDescr,
int requestId, int outputIteration, int outputNumber)/*-{
var that = this;
console.log('saveFilePDF()');
console.log('requestId: ' + requestId);
console.log('OutputIteration: ' + outputIteration);
console.log('OutputNumber:' + outputNumber);
var tTitle = tabTitle;
var tDescr = tabDescr;
var pdoc = new jsPDF("p", "mm", "a4");
pdoc.setProperties({
title : 'PerformFish ' + tTitle,
subject : ' Results',
author : 'PerformFish',
keywords : 'PerformFish',
creator : 'D4Science'
});
var lMargin = 15; //left margin in mm
var rMargin = 15; //right margin in mm
var tMargin = 15; //top margin in mm
var bMargin = 15; //bottom margin in mm
var pdfWidthInMM = 210; // width of A4 in mm
var pdfHeightInMM = 297; // height of A4 in mm
var pageCenter = pdfWidthInMM / 2;
pdoc.setFontSize(24);
var title = "PerformFish " + tTitle;
var titleHeight = pdoc.getLineHeight(title) / pdoc.internal.scaleFactor
var xPos = lMargin;
var yPos = tMargin;
pdoc.text(title, pageCenter, yPos, 'center');
yPos += titleHeight;
pdoc.setFontSize(10);
var lineHeight = pdoc.getLineHeight(tDescr) / pdoc.internal.scaleFactor
var splittedAnalysisDescription = pdoc.splitTextToSize(tDescr,
(pdfWidthInMM - lMargin - rMargin));
var lines = splittedAnalysisDescription.length // splitted text is a string array
var analysisDescriptionHeight = lines * lineHeight
pdoc.text(splittedAnalysisDescription, xPos, yPos, 'left');
yPos += analysisDescriptionHeight;
//yPos += 2;
//pdoc.text("Analysis:", xPos, yPos, 'left');
yPos += 6;
for (var i = 1; i <= outputIteration; i++) {
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);
}-*/;
}

View File

@ -0,0 +1,434 @@
package org.gcube.portlets.user.performfishanalytics.client.viewannualbinder;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.user.performfishanalytics.client.DataMinerAlgorithms;
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant;
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE;
import org.gcube.portlets.user.performfishanalytics.client.PerformFishAnalyticsServiceAsync;
import org.gcube.portlets.user.performfishanalytics.client.annualcontrollers.PerformFishAnnualAnalyticsViewController;
import org.gcube.portlets.user.performfishanalytics.client.resources.PerformFishResources;
import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon;
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.ShowResult;
import org.gcube.portlets.user.performfishanalytics.client.viewbinder.SubmitRequestPanel;
import org.gcube.portlets.user.performfishanalytics.shared.KPI;
import org.gcube.portlets.user.performfishanalytics.shared.OutputFile;
import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile;
import org.gcube.portlets.user.performfishanalytics.shared.dataminer.DataMinerResponse;
import org.gcube.portlets.user.performfishanalytics.shared.performfishservice.PerformFishResponse;
import com.github.gwtbootstrap.client.ui.Alert;
import com.github.gwtbootstrap.client.ui.Button;
import com.github.gwtbootstrap.client.ui.Tab;
import com.github.gwtbootstrap.client.ui.constants.AlertType;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Panel;
public class SynopticTableAnnualPanelResult {
private Map<Integer, FlexTable> synopticOrderBy = new HashMap<Integer, FlexTable>();
private PerformFishAnnualAnalyticsViewController viewAnnualController;
private int requestId;
private int outputIteration = 0;
private int outputNumber = 0;
public SynopticTableAnnualPanelResult(int reqId, PerformFishAnnualAnalyticsViewController viewAnnualController,
PerformFishResponse performFishResponse) {
this.requestId = reqId;
this.viewAnnualController = viewAnnualController;
final DataMinerAlgorithms algorithm = DataMinerAlgorithms.PERFORMFISH_SYNOPTIC_TABLE_FARM;
final SubmitRequestPanel submitRequestPanel = new SubmitRequestPanel("", 1);
final String tabTitle = "Synoptic Table";
final String tabDescr = PerformFishResources.INSTANCE.synopticTable().getText();
final Tab tab = viewAnnualController.createTab(
tabTitle + " #" + (viewAnnualController.currentNumberOfTab() + 1), tabDescr, submitRequestPanel);
// TODO
HorizontalPanel res = new HorizontalPanel();
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;
StringBuilder dataInputsFormatter = new StringBuilder();
Map<String, String> performFishResponseMap = performFishResponse.getMapParameters();
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.LethalIncidentsTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AnnualTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntibioticsTable);
dataInputsFormatter = appendDMInputTable(performFishResponseMap, dataInputsFormatter,
PerformFishAnalyticsConstant.PFSERVICE_TO_DM_MAPPING_TABLE.AntiparasiticTable);
String yearsValue = "";
for (String year : viewAnnualController.getSelectedYears()) {
yearsValue += year + "#";
}
yearsValue = yearsValue.substring(0, yearsValue.length() - 1);
dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_ALLYEARS_PARAM + "=" + yearsValue + ";");
String dataInParameters = dataInputsFormatter.toString();
GWT.log("Calling DM service with client input parameters: " + dataInParameters);
Map<String, List<String>> mapParameters = new HashMap<String, List<String>>();
mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters));
final HTMLPanel panelContainer = submitRequestPanel.getContainerPanel();
final LoaderIcon loaderIcon = new LoaderIcon("Submitting request to " + algorithm.getTitle() + "...");
loaderIcon.setVisible(true);
panelContainer.setVisible(true);
panelContainer.add(loaderIcon);
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
loaderIcon.setFocus(true);
}
});
PerformFishAnalyticsServiceAsync.Util.getInstance().callDMServiceToLoadSynopticAnnualTable(performFishResponse,
mapParameters, new AsyncCallback<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, algorithm, null, null, null, panelContainer,
false, 1);
}
@Override
public void onFailure(Throwable caught) {
loaderIcon.setVisible(false);
checkTabSpinner(submitRequestPanel, tab);
displayOutputFilesAsStaticEntities(null, algorithm, null, null, null, panelContainer, true, 1);
}
});
}
/**
* Append DM input table.
*
* @param performFishResponseMap
* the perform fish response map
* @param dataInputsFormatter
* the data inputs formatter
* @param table
* the table
* @return the string builder
*/
private StringBuilder appendDMInputTable(Map<String, String> performFishResponseMap,
StringBuilder dataInputsFormatter, PFSERVICE_TO_DM_MAPPING_TABLE table) {
String toDMInputTable = performFishResponseMap.get(table.getPerformFishTable());
if (toDMInputTable != null && !toDMInputTable.isEmpty()) {
dataInputsFormatter.append(table.getDataMinerTable() + "=" + toDMInputTable + ";");
}
return dataInputsFormatter;
}
/**
*
*
*
* Remove the spinner if all DM responses are returned.
*
* @param requestPanel
* the request panel
* @param tab
* the tab
*/
private void checkTabSpinner(SubmitRequestPanel requestPanel, Tab tab) {
requestPanel.incrementCompletedRequests();
int completed = requestPanel.getCompletedRequests();
int total = requestPanel.getTotalRequests();
if (completed >= total) {
viewAnnualController.noSpinner(tab);
}
}
private 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_SYNOPTIC_TABLE_FARM:
if (!result.getFileName().contains("legend")) {
cssTableStyle = "synoptictable-farm";
} else {
cssTableStyle = "simpletable-synoptic";
}
ShowResult showResultSin = new ShowResult(outputId, title,
outputFile.getDataType());
showResultSin.showCSVFile(result, cssTableStyle);
displayingOrderedSynopticTable(dmResponse, result.getFileName(), container,
showResultSin);
return;
case PERFORMFISH_SYNOPTICTABLE_BATCH:
break;
case PERFORMFISH_SYNOPTICTABLE_BATCH_HATCHERY:
break;
case PERFORMFISH_SYNOPTICTABLE_BATCH_PREGROW:
break;
default:
break;
}
ShowResult showResult = new ShowResult(outputId, title, outputFile.getDataType());
showResult.showCSVFile(result, cssTableStyle);
container.add(showResult);
}
});
break;
default:
break;
}
}
}
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);
}-*/;
}