From 2def65fef902138e1a513727097ae222dddf0fca Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Wed, 8 May 2019 15:35:31 +0000 Subject: [PATCH] bug fixing algorithm calling git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/performfish-analytics-portlet@179317 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../PerformFishAnnualAnalyticsController.java | 46 +- .../PerformFishAnalyticsController.java | 13 +- .../AnalyticsAnnualPanelResult.java | 1040 +++++++++++++++++ .../AnalyticsAnnualPanelResult.ui.xml | 104 ++ 4 files changed, 1158 insertions(+), 45 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnalyticsAnnualPanelResult.java create mode 100644 src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnalyticsAnnualPanelResult.ui.xml diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/annualcontrollers/PerformFishAnnualAnalyticsController.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/annualcontrollers/PerformFishAnnualAnalyticsController.java index d97190d..fceb48a 100644 --- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/annualcontrollers/PerformFishAnnualAnalyticsController.java +++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/annualcontrollers/PerformFishAnnualAnalyticsController.java @@ -27,6 +27,7 @@ import org.gcube.portlets.user.performfishanalytics.client.event.SelectedPopulat import org.gcube.portlets.user.performfishanalytics.client.event.SubmitRequestEvent; import org.gcube.portlets.user.performfishanalytics.client.event.SubmitRequestEventHandler; import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon; +import org.gcube.portlets.user.performfishanalytics.client.viewannualbinder.AnalyticsAnnualPanelResult; 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; @@ -248,7 +249,6 @@ public class PerformFishAnnualAnalyticsController { focusValue = row.getListValues().get(indexOfFARM); if(focusValue!=null && !focusValue.isEmpty()) break; - } if(focusValue==null) { @@ -335,38 +335,8 @@ public class PerformFishAnnualAnalyticsController { * @param performFishResponse the perform fish response * @param performFishRequestParameters the perform fish request parameters */ - private void callDataMinerServiceForChartTypeCorrelation(String focusID, List inputKPI, final List outputKPI) { + private void callDataMinerServiceForChartTypeCorrelation(String focusID, final List inputKPI, final List outputKPI) { - /*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> mapParameters = new HashMap>(); - - StringBuilder dataInputsFormatter = new StringBuilder(); - - dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_SCALEP_PARAM+"=BATCH;"); - String theBatchType = viewAnnualController.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+"="+ DataMinerAlgorithms.CORRELATION+";"); - dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FARMFILE_PARAM+"="+batchTableURL+";"); - dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM+"=ID;"); - - String kpiCodes = ""; - for (KPI kpi : viewAnnualController.getSelectedKPIs()) { - kpiCodes+=kpi.getCode()+"|"; - } - //remove last | - kpiCodes = kpiCodes.substring(0, kpiCodes.length()-1); - dataInputsFormatter.append("inputKPI="+kpiCodes+";"); - //dataInputsFormatter.append("outputKPI=;"); - - String dataInParameters = dataInputsFormatter.toString();*/ - DataMinerInputParameters dmInputParameters = new DataMinerInputParameters(thePerformFishResponse, viewAnnualController.getSelectedYears(), inputKPI, outputKPI, DataMinerAlgorithms.CORRELATION, focusID); GWT.log("Building DM request with input parameters: "+dmInputParameters); @@ -435,16 +405,12 @@ public class PerformFishAnnualAnalyticsController { public void onSuccess(DataMinerResponse dmResponse) { submitRequestPanel.showLoader(false, null); checkTabSpinner(submitRequestPanel, tab); - AnalyticsPanelResult analyticsPanelResult = new AnalyticsPanelResult(); + AnalyticsAnnualPanelResult analyticsPanelResult = new AnalyticsAnnualPanelResult(eventBus); //analyticsPanelResult.addSelectedAreas(performFishRequestParameters.get(PerformFishAnalyticsConstant.PERFORM_FISH_AREA_PARAM)); - analyticsPanelResult.addSelectedKPIs(viewAnnualController.getSelectedKPIs()); - - + analyticsPanelResult.addSelectedKPIs(inputKPI); //TODO COMMENTED NOW - //analyticsPanelResult.addListBatchIds(viewController.getListBatchesID()); - - + analyticsPanelResult.addListBatchIds(Arrays.asList(theFocusValue)); analyticsPanelResult.addParameters(PerformFishAnalyticsConstant.DATA_INPUTS, mapParameters, viewAnnualController.getForm().getBatchType()); analyticsPanelResult.addResults(dmResponse); @@ -464,7 +430,7 @@ public class PerformFishAnnualAnalyticsController { analyticsPanelResult.addSelectedKPIs(viewAnnualController.getSelectedKPIs()); //TODO COMMENTED NOW - //analyticsPanelResult.addListBatchIds(viewController.getListBatchesID()); + analyticsPanelResult.addListBatchIds(Arrays.asList(theFocusValue)); analyticsPanelResult.addParameters(PerformFishAnalyticsConstant.DATA_INPUTS, mapParameters, viewAnnualController.getForm().getBatchType()); diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/controllers/PerformFishAnalyticsController.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/controllers/PerformFishAnalyticsController.java index c8be090..1e8dabf 100644 --- a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/controllers/PerformFishAnalyticsController.java +++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/controllers/PerformFishAnalyticsController.java @@ -3,6 +3,7 @@ */ package org.gcube.portlets.user.performfishanalytics.client.controllers; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -344,7 +345,9 @@ public class PerformFishAnalyticsController { submitRequestPanel.showLoader(true, "Submitting "+DataMinerAlgorithms.CORRELATION.getName()+" request to DM Service..."); String tabTitle = DataMinerAlgorithms.CORRELATION.getName().substring(0,1).toUpperCase()+DataMinerAlgorithms.CORRELATION.getName().toLowerCase().substring(1, DataMinerAlgorithms.CORRELATION.getName().length()); //CAMEL CASE final Tab tab = viewController.createTab(submitRequestPanel, tabTitle+" #"+(viewController.currentNumberOfTab()+1)); - + + final List selectedKPI = new ArrayList(viewController.getSelectedKPIs()); + final List batchIDs = new ArrayList(viewController.getListBatchesID()); PerformFishAnalyticsServiceAsync.Util.getInstance().callingDataMinerPerformFishCorrelationAnalysis(performFishResponse, mapParameters, new AsyncCallback() { @Override @@ -353,8 +356,8 @@ public class PerformFishAnalyticsController { checkTabSpinner(submitRequestPanel, tab); AnalyticsPanelResult analyticsPanelResult = new AnalyticsPanelResult(); analyticsPanelResult.addSelectedAreas(performFishRequestParameters.get(PerformFishAnalyticsConstant.PERFORM_FISH_AREA_PARAM)); - analyticsPanelResult.addSelectedKPIs(viewController.getSelectedKPIs()); - analyticsPanelResult.addListBatchIds(viewController.getListBatchesID()); + analyticsPanelResult.addSelectedKPIs(selectedKPI); + analyticsPanelResult.addListBatchIds(batchIDs); analyticsPanelResult.addParameters(PerformFishAnalyticsConstant.DATA_INPUTS, mapParameters, viewController.getForm().getBatchType()); analyticsPanelResult.addResults(dmResponse); submitRequestPanel.addWidget(analyticsPanelResult); @@ -370,8 +373,8 @@ public class PerformFishAnalyticsController { try { AnalyticsPanelResult analyticsPanelResult = new AnalyticsPanelResult(); analyticsPanelResult.addSelectedAreas(performFishRequestParameters.get(PerformFishAnalyticsConstant.PERFORM_FISH_AREA_PARAM)); - analyticsPanelResult.addSelectedKPIs(viewController.getSelectedKPIs()); - analyticsPanelResult.addListBatchIds(viewController.getListBatchesID()); + analyticsPanelResult.addSelectedKPIs(selectedKPI); + analyticsPanelResult.addListBatchIds(batchIDs); analyticsPanelResult.addParameters(PerformFishAnalyticsConstant.DATA_INPUTS, mapParameters, viewController.getForm().getBatchType()); submitRequestPanel.addWidget(analyticsPanelResult); }catch (Exception e) { diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnalyticsAnnualPanelResult.java b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnalyticsAnnualPanelResult.java new file mode 100644 index 0000000..038e477 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnalyticsAnnualPanelResult.java @@ -0,0 +1,1040 @@ +/** + * + */ +package org.gcube.portlets.user.performfishanalytics.client.viewannualbinder; + +import java.util.ArrayList; +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.event.CallAlgorithmEvent; +import org.gcube.portlets.user.performfishanalytics.client.view.LoaderIcon; +import org.gcube.portlets.user.performfishanalytics.client.view.util.CorrelationValueToColourUtil; +import org.gcube.portlets.user.performfishanalytics.client.viewbinder.ShowResult; +import org.gcube.portlets.user.performfishanalytics.shared.KPI; +import org.gcube.portlets.user.performfishanalytics.shared.OutputFile; +import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVFile; +import org.gcube.portlets.user.performfishanalytics.shared.csv.CSVRow; +import org.gcube.portlets.user.performfishanalytics.shared.dataminer.DataMinerResponse; + +import com.github.gwtbootstrap.client.ui.Alert; +import com.github.gwtbootstrap.client.ui.Button; +import com.github.gwtbootstrap.client.ui.CheckBox; +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.ButtonType; +import com.github.gwtbootstrap.client.ui.constants.ControlGroupType; +import com.github.gwtbootstrap.client.ui.constants.IconType; +import com.github.gwtbootstrap.client.ui.resources.ButtonSize; +import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.Scheduler; +import com.google.gwt.dom.client.Style.Unit; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.event.logical.shared.AttachEvent; +import com.google.gwt.event.shared.HandlerManager; +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.rpc.AsyncCallback; +import com.google.gwt.user.client.ui.ComplexPanel; +import com.google.gwt.user.client.ui.Composite; +import com.google.gwt.user.client.ui.FlexTable; +import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HTMLPanel; +import com.google.gwt.user.client.ui.HorizontalPanel; +import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.Panel; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.Widget; + + +/** + * The Class AnalyticsPanelResult. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Jan 29, 2019 + */ +public class AnalyticsAnnualPanelResult extends Composite { + + /** + * + */ + + + private static AnalyticsPanelResultUiBinder uiBinder = + GWT.create(AnalyticsPanelResultUiBinder.class); + + /** + * The Interface AnalyticsPanelResultUiBinder. + * + * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) + * Jan 30, 2019 + */ + interface AnalyticsPanelResultUiBinder + extends UiBinder { + } + + @UiField + HTMLPanel field_html_panel; + + @UiField + VerticalPanel field_parameters_container; + + @UiField + VerticalPanel uib_vp_correlation_results_container; + + @UiField + VerticalPanel field_unary_algorithm_container; + + @UiField + VerticalPanel field_binary_algorithm; + + @UiField + VerticalPanel field_binary_algorithm_container; + + @UiField + VerticalPanel field_unary_algorithm; + + @UiField + ControlGroup cg_list_dea_input_kpi; + + @UiField + ControlGroup cg_list_dea_output_kpi; + + @UiField + ListBox list_dea_input_kpi; + + @UiField + ListBox list_dea_output_kpi; + + @UiField + Label uib_label_focus_id; + +// @UiField +// ControlGroup cg_focus_id_dea; + + @UiField + HorizontalPanel uib_vp_deanalanlysis_request_container; + + @UiField + ControlGroup cg_focus_id_correlation; + +// @UiField +// ListBox field_list_focus_id_dea; + + @UiField + VerticalPanel uib_vp_deanalanlysis_algorithm; + + @UiField + VerticalPanel uib_vp_deanalanlysis_algorithm_container; + + @UiField + ListBox field_list_focus_id_correlation; + + @UiField + Button button_dea_analys_request; + + @UiField + CheckBox uib_check_all_input_kpi; + + @UiField + CheckBox uib_check_all_output_kpi; + + private Map dataInputParameters; + + private DataMinerResponse dmResponse; + + private Map> kpiMapPointers = new HashMap>(); + + private List selectedKPIs; + + private List selectedAreas; + + private HandlerManager theEventBus; + + /** + * Because this class has a default constructor, it can + * be used as a binder template. In other words, it can be used in other + * *.ui.xml files as follows: + * + * Hello! + * + * Note that depending on the widget that is used, it may be necessary to + * implement HasHTML instead of HasText. + */ + public AnalyticsAnnualPanelResult(HandlerManager eventBus) { + + initWidget(uiBinder.createAndBindUi(this)); + this.theEventBus = eventBus; + + button_dea_analys_request.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + cg_list_dea_input_kpi.setType(ControlGroupType.NONE); + cg_list_dea_output_kpi.setType(ControlGroupType.NONE); + + if(list_dea_input_kpi.getSelectedIndex()==-1){ + showAlert("You must select at least one Input KPI", AlertType.ERROR, true, uib_vp_deanalanlysis_request_container); + cg_list_dea_input_kpi.setType(ControlGroupType.ERROR); + return; + } + + if(list_dea_output_kpi.getSelectedIndex()==-1){ + showAlert("You must select at least one Output KPI", AlertType.ERROR, true, uib_vp_deanalanlysis_request_container); + cg_list_dea_output_kpi.setType(ControlGroupType.ERROR); + return; + } + + List inputKPINames = getSelected(list_dea_input_kpi); + List outputKPINames = getSelected(list_dea_output_kpi); + callDeaAnalysis(inputKPINames, outputKPINames, button_dea_analys_request); + } + }); + + uib_check_all_input_kpi.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + boolean isChecked = uib_check_all_input_kpi.getValue(); + selectAllFields(list_dea_input_kpi, isChecked); + } + }); + + uib_check_all_output_kpi.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + boolean isChecked = uib_check_all_output_kpi.getValue(); + selectAllFields(list_dea_output_kpi, isChecked); + } + }); + } + + /** + * Select all fields. + * + * @param listBox the list box + * @param selected the selected + */ + private void selectAllFields(ListBox listBox, boolean selected){ + + for (int i=0; i getSelected(ListBox listBox){ + List selected = new ArrayList(); + for (int i=0; i listAreas) { + + this.selectedAreas = listAreas; + + } + + + /** + * Gets the data miner response. + * + * @return the data miner response + */ + public DataMinerResponse getDataMinerResponse(){ + return dmResponse; + } + + + + /** + * Gets the data input parameters. + * + * @return the data input parameters + */ + public Map getDataInputParameters() { + + return dataInputParameters; + } + + /** + * Show alert. + * + * @param error the error + * @param type the type + * @param closable the closable + * @param panel the panel + */ + private void showAlert(String error, AlertType type, boolean closable, ComplexPanel panel){ + Alert alert = new Alert(error); + alert.setType(type); + alert.setClose(closable); + alert.getElement().getStyle().setMargin(10, Unit.PX); + panel.add(alert); + } + + + /** + * Adds the selected kp is. + * + * @param selectedKPIs the selected kp is + */ + public void addSelectedKPIs(List selectedKPIs) { + + this.selectedKPIs = selectedKPIs; + + } + + +// /** +// * Gets the KPI for name. +// * +// * @param name the name +// * @return the KPI for name +// */ +// public KPI getKPIForName(String name){ +// +// //GWT.log("Selected KPIs: "+selectedKPIs); +// GWT.log("Searching KPI name: "+name); +// KPI foundKPI = null; +// //String purgedName = name.replaceAll("\\%", "").trim(); +// String purgedName = name.trim(); +// for (KPI kpi : selectedKPIs) { +// //String purgedKPIName = kpi.getName().replaceAll("\\%", "").trim(); +// String purgedKPIName = kpi.getName().trim(); +// if(purgedKPIName.compareToIgnoreCase(purgedName)==0) { +// foundKPI = kpi; +// break; +// } +// +// } +// GWT.log("FOUND KPI: "+foundKPI); +// return foundKPI; +// } + + public KPI getKPIForName(String name){ + + GWT.log("Searching KPI name: "+name); + KPI foundKPI = null; + String purgedName = name.trim(); + for (KPI kpi : selectedKPIs) { + String purgedKPIName = kpi.getName().trim(); + if(purgedKPIName.compareToIgnoreCase(purgedName)==0) { + foundKPI = kpi; + break; + } + } + GWT.log("FOUND KPI: "+foundKPI); + return foundKPI; + } + + /** + * Adds the parameters. + * + * @param keyToGet the key to get + * @param parameters the parameters + * @param toShowBatchTypeValue label to show batch type value + */ + public void addParameters(String keyToGet, Map> parameters, String toShowBatchTypeValue) { + + + final FlexTable flexTable = new FlexTable(); + flexTable.setStyleName("colgrouptable"); + + try{ + List dataInputs = parameters.get(keyToGet); + + if(dataInputs==null || dataInputs.isEmpty()) + return; + + dataInputParameters = new HashMap(); + + String theDataInputs = dataInputs.get(0); + String[] splittedParams = theDataInputs.split(";"); + + for (String splitParam : splittedParams) { + try{ + String[] keyvalue = splitParam.split("="); + dataInputParameters.put(keyvalue[0], keyvalue[1]); + }catch(Exception e){ + + } + } + + flexTable.setWidget(0, 0, new HTML(dataInputParameters.get(PerformFishAnalyticsConstant.DM_SCALEP_PARAM))); + flexTable.setWidget(1, 0, new HTML(toShowBatchTypeValue)); + + String KPINames = ""; + for (KPI kpi: selectedKPIs) { + KPINames+=kpi.getName() +", "; + } + KPINames = KPINames.substring(0, KPINames.length()-2); + flexTable.setWidget(2,0, new HTML(KPINames)); + + fillDeaListBoxes(); + + //TODO MUST BE REVISITED + //CHANGING LABEL TEXT TO SCAPE_PARAM + //uib_label_focus_id.setText(dataInputParameters.get(PerformFishAnalyticsConstant.DM_SCALEP_PARAM) + " ID"); + + uib_label_focus_id.setText("FOCUS ID"); + + }catch(Exception e){ + //silent + } + + field_parameters_container.add(flexTable); + } + + + /** + * Fill dea list boxes. + */ + private void fillDeaListBoxes(){ + + for (KPI kpi: selectedKPIs) { + list_dea_input_kpi.addItem(kpi.getName()); + list_dea_output_kpi.addItem(kpi.getName()); + } + } + + + /** + * Adds the list batch ids. + * + * @param listBatchesID the list batches id + */ + public void addListBatchIds(List listBatchesID){ + for (String batchID : listBatchesID) { + field_list_focus_id_correlation.addItem(batchID, batchID); + } + } + + /** + * Adds the results. + * + * @param dmResponse the dm response + */ + public void addResults(DataMinerResponse dmResponse) { + this.dmResponse = dmResponse; + + for (final OutputFile outputFile : dmResponse.getListOutput()) { + + switch (outputFile.getDataType()) { + case IMAGE: + PerformFishAnalyticsServiceAsync.Util.getInstance().getImageFile(outputFile, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + showAlert(caught.getMessage(), AlertType.ERROR, true, uib_vp_correlation_results_container); + + } + + @Override + public void onSuccess(String base64Content) { + ShowResult showResult = new ShowResult(outputFile.getName()); + showResult.showImage(base64Content); + uib_vp_correlation_results_container.add(showResult); + + } + }); + break; + case CSV: + + //CORRELATION MATRIX + PerformFishAnalyticsServiceAsync.Util.getInstance().getCSVFile(outputFile, true, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + showAlert(caught.getMessage(), AlertType.ERROR, true, uib_vp_correlation_results_container); + + } + + @Override + public void onSuccess(CSVFile result) { + + GWT.log("Displaying: "+result); + HorizontalPanel hp = new HorizontalPanel(); + final FlexTable flexTable = new FlexTable(); + flexTable.setStyleName("fixedtable"); + flexTable.getElement().getStyle().setMarginBottom(10, Unit.PX); + + flexTable.setWidget(0, 0,new Label("")); + +// for (KPI kpi : selectedKPIs) { +// GWT.log("Selected KPIs are: "+kpi); +// } + + CSVRow headerRow = result.getHeaderRow(); + //HEADER + for (int i=1; i 0 + }else{ + KPI columnKPI = getKPIForName(headerRow.getListValues().get(columnIndex)); + //Here the first index is the KPI name + KPI rowKPI = getKPIForName(row.getListValues().get(0)); + fillKPIReferenceForIndex(rowIndex, columnIndex, Arrays.asList(columnKPI, rowKPI)); + button.setText(" "); + button.setIcon(IconType.COMPASS); + button.setSize(ButtonSize.LARGE); + + button.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + //callScatterAndDeaChart(rowIndex, columnIndex, button); + callScatter(rowIndex, columnIndex, button); + } + }); + } + + button.setType(ButtonType.LINK); + //APPLYING STYLE ONLY ON INTERNAL VALUES OF CSV + if(j>0) + button.getElement().getStyle().setColor("#000"); + + button.addAttachHandler(new AttachEvent.Handler() { + + @Override + public void onAttachOrDetach(AttachEvent event) { + if(theColor.startsWith("#")){ + GWT.log("Setting backgrounf color: "+theColor); + button.getElement().getParentElement().getStyle().setBackgroundColor(theColor); + } + } + }); + + flexTable.setWidget(rowIndex, j,button); + } + + } + + hp.add(flexTable); + + final FlexTable flexLegend = new FlexTable(); + flexLegend.setStyleName("simpletable"); + //flexLegend.getElement().getStyle().setBorderWidth(0, Unit.PX); + Map map = CorrelationValueToColourUtil.getMap(); + flexLegend.setWidget(0, 0, new Label("Legend")); + flexLegend.setWidget(0, 1, new HTML("")); + int i = 1; + for (String key : map.keySet()) { + final String rgbColor = map.get(key); + final HTML theLegendColor = new HTML(""); + flexLegend.setWidget(i, 0, theLegendColor); + flexLegend.setWidget(i, 1, new HTML(key)); + theLegendColor.addAttachHandler(new AttachEvent.Handler() { + + @Override + public void onAttachOrDetach(AttachEvent event) { + theLegendColor.getElement().getParentElement().getStyle().setBackgroundColor(rgbColor); + } + }); + + i++; + } + + flexLegend.getElement().getStyle().setMarginLeft(15, Unit.PX); + hp.add(flexLegend); + uib_vp_correlation_results_container.insert(hp,0); + } + }); + break; + + default: + break; + } + + } + } + + /** + * Fill kpi reference for index. + * + * @param rowIndex the row index + * @param columnIndex the column index + * @param listKPI the list kpi + */ + private void fillKPIReferenceForIndex(int rowIndex, int columnIndex, List listKPI){ + + String key = generateKey(rowIndex, columnIndex); + kpiMapPointers.put(key, listKPI); + +// String kpiNames = ""; +// if(listKPI!=null && listKPI.size()>0){ +// for (KPI kpi : listKPI) { +// +// if(kpi!=null){ +// kpiNames+=" "+kpi.getName() +";"; +// }else +// GWT.log("KPI NULL for "+key); +// +// +// } +// GWT.log("FILLING kpiMapPointers with key: "+key +" and value: "+kpiNames); +// }else +// GWT.log("FILLING kpiMapPointers with key: "+key +" and value: "+listKPI); + + } + + /** + * Gets the KPI for indexes. + * + * @param rowIndex the row index + * @param columnIndex the column index + * @return the KPI for indexes + */ + public List getKPIForIndexes(int rowIndex, int columnIndex){ + String key = generateKey(rowIndex, columnIndex); + return kpiMapPointers.get(key); + } + + private String generateKey(int rowIndex, int columnIndex) { + return rowIndex+"-"+columnIndex; + } + + + /** + * Call box plot and speedo meter. + * + * @param rowIndex the row index + * @param columnIndex the column index + * @param button the button + */ + private void callBoxPlotAndSpeedoMeter(int rowIndex, int columnIndex, Button button){ + + String focusID = checkValidFocusID(); + + if(focusID==null) + return; + + GWT.log("Called BoxPlotAndSpeedoMeter at rowIndex: "+rowIndex +", columnIndex: "+columnIndex); + HorizontalPanel hp = new HorizontalPanel(); + hp.getElement().addClassName("ext-horizontal-panel"); + HorizontalPanel boxPlot = new HorizontalPanel(); + HorizontalPanel speedometer = new HorizontalPanel(); + hp.add(boxPlot); + hp.add(speedometer); + //hp.getElement().addClassName("ext-horizontal-panel"); + field_unary_algorithm_container.add(hp); + //KPI selectKPI = getKPIForName(button.getText()); + List selectedKPI = getKPIForIndexes(rowIndex, columnIndex); + GWT.log("Selected KPI: "+selectedKPI); + field_unary_algorithm.setVisible(true); + callDataMinerServiceForChart(dataInputParameters, selectedKPI, null, DataMinerAlgorithms.BOXPLOT, focusID, boxPlot); + callDataMinerServiceForChart(dataInputParameters, selectedKPI, null, DataMinerAlgorithms.SPEEDOMETER, focusID, speedometer); + } + + + /** + * Check valid focus id. + * + * @return the FocusID if it is valid, null otherwise. + */ + public String checkValidFocusID(){ + + cg_focus_id_correlation.setType(ControlGroupType.NONE); + + //CHECK THE FOCUS ID VALUE + String focusID = field_list_focus_id_correlation.getSelectedItemText(); + + if(focusID==null || focusID.isEmpty()){ + + String msgError = "Could not execute a valid Analysis."; + + //TODO TO BE REVISITED + /* + if(selectedAreas==null || selectedAreas.isEmpty()){ + msgError+=" Please select another parameters computation"; + }else{ + msgError+=" Select at least the Area of your FARM"; + }*/ + + showAlert(msgError, AlertType.ERROR, true, uib_vp_correlation_results_container); + cg_focus_id_correlation.setType(ControlGroupType.ERROR); + return null; + } + + return focusID; + } + + + /** + * Call scatter and dea chart. + * + * @param rowIndex the row index + * @param columnIndex the column index + * @param button the button + */ + private void callScatterAndDeaChart(int rowIndex, int columnIndex, Button button){ + + String focusID = checkValidFocusID(); + + if(focusID==null) + return; + + GWT.log("Called ScatterAndDeaChart at rowIndex: "+rowIndex +", columnIndex: "+columnIndex); + HorizontalPanel hp = new HorizontalPanel(); + hp.getElement().addClassName("ext-horizontal-panel"); + HorizontalPanel scatter = new HorizontalPanel(); + HorizontalPanel deaChart = new HorizontalPanel(); + hp.add(scatter); + hp.add(deaChart); + //hp.getElement().addClassName("ext-horizontal-panel"); + field_binary_algorithm_container.add(hp); + List selectedKPI = getKPIForIndexes(rowIndex, columnIndex); + GWT.log("Selected KPI: "+selectedKPI); + field_binary_algorithm.setVisible(true); + callDataMinerServiceForChart(dataInputParameters, selectedKPI, null, DataMinerAlgorithms.SCATTER, focusID, scatter); + callDataMinerServiceForChart(dataInputParameters, selectedKPI, null, DataMinerAlgorithms.DEA_CHART, focusID, deaChart); + } + + + /** + * Call scatter. + * + * @param rowIndex the row index + * @param columnIndex the column index + * @param button the button + */ + private void callScatter(int rowIndex, int columnIndex, Button button){ + + String focusID = checkValidFocusID(); + + if(focusID==null) + return; + + GWT.log("Called ScatterChart at rowIndex: "+rowIndex +", columnIndex: "+columnIndex); + List selectedKPI = getKPIForIndexes(rowIndex, columnIndex); + GWT.log("Selected KPI: "+selectedKPI); + theEventBus.fireEvent(new CallAlgorithmEvent(DataMinerAlgorithms.SCATTER, focusID, selectedKPI, null)); + } + + + /** + * Call dea analysis. + * + * @param inputKPINames the input kpi names + * @param outputKPINames the output kpi names + * @param button the button + */ + private void callDeaAnalysis(List inputKPINames, List outputKPINames, Button button){ + + HorizontalPanel hp = new HorizontalPanel(); + hp.getElement().addClassName("ext-horizontal-panel"); + HorizontalPanel deaAnalysis = new HorizontalPanel(); + hp.add(deaAnalysis); + //hp.getElement().addClassName("ext-horizontal-panel"); + uib_vp_deanalanlysis_algorithm_container.add(hp); + + List inputKPI = new ArrayList(); + for (String kpiName : inputKPINames) { + inputKPI.add(getKPIForName(kpiName)); + } + + List outputKPI = new ArrayList(); + for (String kpiName : outputKPINames) { + outputKPI.add(getKPIForName(kpiName)); + } + + + GWT.log("Calling Dea Analysys... with input: "+inputKPI+" and output: "+outputKPI); + uib_vp_deanalanlysis_algorithm.setVisible(true); + callDataMinerServiceForChart(dataInputParameters, inputKPI, outputKPI, DataMinerAlgorithms.DEA_ANALYSIS, "ID", deaAnalysis); + } + + + /** + * 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(DataMinerResponse dmResponse, final DataMinerAlgorithms chartType, List inputKPIs, List outputKPIs, final String focusID, final Panel container, boolean displayError){ + + String title = displayError?"No results ":""; + title+=chartType; + title+=inputKPIs.size()>1?" [Input KPIs: ":" [Input KPI: "; + + for (KPI kpi : inputKPIs) { + title+=" "+kpi.getName()+","; + } + + title = title.substring(0,title.length()-1)+"]"; + + + if(outputKPIs!=null && outputKPIs.size()>0){ + title+=inputKPIs.size()>1?" [Output KPIs: ":" [Output KPI: "; + for (KPI kpi : outputKPIs) { + title+=" "+kpi.getName()+","; + } + title = title.substring(0,title.length()-1)+"]"; + } + + //title+= " Focus "+focusID; + + 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; + + for (final OutputFile outputFile : dmResponse.getListOutput()) { + + switch (outputFile.getDataType()) { + case IMAGE: + PerformFishAnalyticsServiceAsync.Util.getInstance().getImageFile(outputFile, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + showAlert(caught.getMessage(), AlertType.ERROR, true, uib_vp_deanalanlysis_request_container); + + } + + @Override + public void onSuccess(String base64Content) { + + String title = toTitle; + switch (chartType) { + case BOXPLOT: + break; + case SPEEDOMETER: + title+= " "+uib_label_focus_id.getText()+": "+focusID; + break; + default: + break; + } + + + ShowResult showResult = new ShowResult(title); + showResult.showImage(base64Content); + container.add(showResult); + + } + }); + break; + case CSV: + PerformFishAnalyticsServiceAsync.Util.getInstance().getCSVFile(outputFile, true, new AsyncCallback() { + + @Override + public void onFailure(Throwable caught) { + showAlert(caught.getMessage(), AlertType.ERROR, true, uib_vp_deanalanlysis_request_container); + } + + @Override + public void onSuccess(CSVFile result) { + GWT.log("Displaying: "+result); + + String title = toTitle; + switch (chartType) { + case BOXPLOT: + title+= " Statistics on all data"; + break; + case SPEEDOMETER: + title+= " "+uib_label_focus_id.getText()+": "+focusID; + break; + default: + break; + } + + ShowResult showResult = new ShowResult(title); + showResult.showCSVFile(result); + container.add(showResult); + } + }); + break; + + default: + break; + } + + } + + } + + /** + * Call data miner service for chart. + * + * @param dataInputParameters the data input parameters + * @param inputKPI the input kpi + * @param outputKPI the output kpi + * @param chartType the chart type + * @param focusID the focus id + * @param panel the panel + */ + private void callDataMinerServiceForChart(Map dataInputParameters, final List inputKPI, final List outputKPI, final DataMinerAlgorithms chartType, final String focusID, final ComplexPanel panel) { + + GWT.log("Call DM wiht Selected KPI: "+inputKPI); + StringBuilder dataInputsFormatter = new StringBuilder(); + String scalePValue = dataInputParameters.get(PerformFishAnalyticsConstant.DM_SCALEP_PARAM); + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_SCALEP_PARAM+"="+scalePValue+";"); + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_BATCHTYPE_PARAM+"="+dataInputParameters.get(PerformFishAnalyticsConstant.DM_BATCHTYPE_PARAM)+";"); + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_CHARTTYPE_PARAM+"="+chartType+";"); + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FARMFILE_PARAM+"="+dataInputParameters.get(PerformFishAnalyticsConstant.DM_FARMFILE_PARAM)+";"); + + + 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+";"); + + } + + dataInputsFormatter.append(PerformFishAnalyticsConstant.DM_FOCUS_PARAM+"="+focusID+";"); + + String dataInParameters = dataInputsFormatter.toString(); + GWT.log("Calling DM service with client input parameters: "+dataInParameters); + + Map> mapParameters = new HashMap>(); + mapParameters.put(PerformFishAnalyticsConstant.DATA_INPUTS, Arrays.asList(dataInParameters)); + + final LoaderIcon loaderIcon = new LoaderIcon("Submitting request to "+chartType+" Analysis..."); + loaderIcon.setVisible(true); + panel.setVisible(true); + panel.add(loaderIcon); + Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() { + @Override + public void execute() { + loaderIcon.setFocus(true); + }}); + + PerformFishAnalyticsServiceAsync.Util.getInstance().callingDataMinerPerformFishAnalysis(mapParameters, new AsyncCallback() { + + @Override + public void onSuccess(DataMinerResponse dmResponse) { + loaderIcon.setVisible(false); + //field_unary_algorithm.setVisible(true); + GWT.log("I'm displaying: "+dmResponse); + displayOutputFilesAsStaticEntities(dmResponse, chartType, inputKPI, outputKPI, focusID, panel, false); + } + + @Override + public void onFailure(Throwable caught) { + loaderIcon.setVisible(false); + displayOutputFilesAsStaticEntities(dmResponse, chartType, inputKPI, outputKPI, focusID, panel, true); + + } + }); + } +} diff --git a/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnalyticsAnnualPanelResult.ui.xml b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnalyticsAnnualPanelResult.ui.xml new file mode 100644 index 0000000..7f773b4 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/performfishanalytics/client/viewannualbinder/AnalyticsAnnualPanelResult.ui.xml @@ -0,0 +1,104 @@ + + + + .paddingLeft { + padding-left: 10px; + } + + + + + + + + + + + + + + Focus ID + + + + + + + + + + + + + + Input KPI + + + + + + + + + + + + Output + KPI + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file