Package it.eng.spagobi.engines.chart.utils

Examples of it.eng.spagobi.engines.chart.utils.DatasetMap


  @Override
  public DatasetMap calculateValue() throws Exception {
    logger.debug("IN");
    super.calculateValue();
    DatasetMap datasetMap=new DatasetMap();
    String res=DataSetAccessFunctions.getDataSetResultFromId(profile, getData(),parametersObject);

    ArrayList<Activity> activities=new ArrayList<Activity>();


    RegularTimePeriod timePeriod = null;

    SourceBean sbRows=SourceBean.fromXMLString(res);
    List listAtts=sbRows.getAttributeAsList("ROW");
    // Run all rows
    if(listAtts==null){
      logger.error("Null rows retrieved from dataset");
      return null;
    }
    int j=0;
    // for each activity
    logger.debug("retrieved number rows: "+listAtts.size());
    for (Iterator iterator = listAtts.iterator(); iterator.hasNext();) {
      SourceBean row = (SourceBean) iterator.next();
      Activity activity=new Activity(row, beginDateFormat, beginHourFormat);
      activities.add(activity);
      logger.debug("Activity built from "+activity.getBeginDate()+" minutes"+activity.getMinutes()!=null?activity.getMinutes().toString():"");
      if(maxDateFound!=null && !activity.getBeginDate().after(maxDateFound)){
      }
      else{
        maxDateFound=activity.getBeginDate();
      }

      if(minDateFound!=null && !activity.getBeginDate().before(minDateFound)){
      }
      else{
        minDateFound=activity.getBeginDate();
      }
    }

    //    count days
    long daysBetween;
    if(dateMin!=null && dateMax!=null){
      logger.debug("use date limit defined in template: from "+dateMin.toString()+" to "+dateMax.toString());
      daysBetween=daysBetween(dateMin,dateMax);
    }
    else{
      logger.debug("use date limit found: from "+minDateFound.toString()+" to "+maxDateFound.toString());
      daysBetween=daysBetween(minDateFound,maxDateFound);
    }
    logger.debug("Days between the two dates "+daysBetween);
    // add a date to include extremis
    long minutesBetweenLong=daysBetween*24*60*2; // raddoppio in caso di sovrapposizioni
    int mbl=Long.valueOf(minutesBetweenLong).intValue();

    DefaultXYZDataset dataset = new DefaultXYZDataset();

    ArrayList<Long> xValuesList=new ArrayList<Long>();
    ArrayList<Double> yValuesList=new ArrayList<Double>();
    ArrayList<Double> zValuesList=new ArrayList<Double>();


    annotations=new HashMap<String, AnnotationBlock>();
    // run all the activities
    for (Iterator iterator = activities.iterator(); iterator.hasNext();) {
      Activity activity = (Activity) iterator.next();

      // insert only if activty falls inside the min and max Range (idf defined)
      if(dateMin!=null && dateMax!=null && (activity.getBeginDate().after(dateMax) || activity.getBeginDate().before(dateMin))){
        logger.debug("Activity discarde because starting out of selected bounds in "+activity.getBeginDate());
      }
      else
        logger.debug("Inserting activity with begin date "+activity.getBeginDate()+" adn pattern "+activity.getPattern());
        RegularTimePeriod rtp = new Day(activity.getBeginDate());
        long secondmills= rtp.getFirstMillisecond();

        Minute minute=activity.getMinutes();
        for(int i=0;i<activity.getDuration();i++){
          // convert from hour to number axis (da sessantesimi a centesimi!)
          Integer hour=Integer.valueOf(minute.getHourValue());
          Integer minuteValue=Integer.valueOf(minute.getMinute());
          Double doubleMinuteValue=Double.valueOf(((double)minuteValue.intValue()));
          // minuteValue : 60 = x :100
          double convertedMinuteValue=(doubleMinuteValue*100)/60.0;
          double convertedMinuteValueCent=convertedMinuteValue/100;

          double hourD=(double)hour.intValue();
          double converted=hourD+convertedMinuteValueCent;

          String yVal=Double.valueOf(converted).toString();

          xValuesList.add(new Long(secondmills));
          yValuesList.add(Double.valueOf(yVal));

          Object cosa=patternRangeIndex.get(activity.getPattern());

          if(cosa!=null){
            zValuesList.add(Double.valueOf(patternRangeIndex.get(activity.getPattern())).doubleValue()+0.5);
          }
          else{
            zValuesList.add(-1.0);
          }
          //          xvalues[j]=secondmills;
//          yvalues[j]=Double.valueOf(yVal);
//          zvalues[j]=patternRangeIndex.get(activity.getPattern())+0.5;

          //System.out.println("Date: "+activity.getBeginDate()+":"+Double.valueOf(xvalues[j]).toString()+", Hour: "+Double.valueOf(yvalues[j]).toString()+", Value: "+Double.valueOf(zvalues[j]).toString());
          if(annotations.get(activity.getCode())==null){
            AnnotationBlock annotation=new AnnotationBlock(activity.getCode());
            annotation.setXPosition(xValuesList.get(j).doubleValue());
            annotation.setYPosition(yValuesList.get(j).doubleValue());
            annotations.put(annotation.getAnnotation(), annotation);
          }
          minute=(Minute)minute.next();
          j++;
        }
      }

    }
//    create arrays
    double[] xvalues = new double[xValuesList.size()];   
    double[] yvalues = new double[yValuesList.size()];   
    double[] zvalues = new double[zValuesList.size()];

    for (int i = 0; i < zValuesList.size(); i++) {
      Long l=xValuesList.get(i);
      xvalues[i]=l;
      Double d2=yValuesList.get(i);
      yvalues[i]=d2;     
      Double d=zValuesList.get(i);
      zvalues[i]=d;
    }

    logger.debug("adding the serie");
    dataset.addSeries("Series 1",
        new double[][] { xvalues, yvalues, zvalues });

    datasetMap.getDatasets().put("1", dataset);
    logger.debug("OUT");
    return datasetMap;
  }
View Full Code Here


      return null;
    }

    if(yearsDefined.isEmpty()){
      logger.warn("dataset returned no rows");
      return new DatasetMap();
    }
   
    // Set the first and the last periods

    TimeSeriesDataItem item1=timeSeries.getDataItem(0);
    firstMonth=(Month)item1.getPeriod();
    TimeSeriesDataItem item2=timeSeries.getDataItem(timeSeries.getItemCount()-1);
    lastMonth=(Month)item2.getPeriod();
    lastYear=yearsDefined.last();

    DatasetMap datasets=new DatasetMap();
    logger.debug("OUT");
    return datasets;
  }
View Full Code Here

        annotationMap.put(catValue, seriesT);
      }

    }
    logger.debug("OUT");
    DatasetMap datasets=new DatasetMap();
    datasets.addDataset("1",dataset);
    return datasets;
  }
View Full Code Here

      sbi.setParametersObject(parametersMap);
      // configure the chart with template parameters
      sbi.configureChart(content);


      DatasetMap datasets=null;
      try{
        datasets=sbi.calculateValue();
     
      catch (Exception e) {
        logger.error("Error in reading the value, check the dataset",e);
View Full Code Here

  public File executeChartCode(RequestContainer requestContainer, BIObject obj, SourceBean response, IEngUserProfile userProfile) throws EMFUserError{
    logger.debug("IN");
   
    File toReturn = null;
    Locale locale = GeneralUtilities.getDefaultLocale();
    DatasetMap datasets = null;
    ChartImpl sbi = null;

    String documentId=obj.getId().toString();

    //    **************get the template*****************
    logger.debug("getting template");
    SourceBean serviceRequest=requestContainer.getServiceRequest();

    try{
      //SourceBean content = getTemplate(documentId);
      SourceBean content = null;
      byte[] contentBytes = null;
      try{
        ObjTemplate template = DAOFactory.getObjTemplateDAO().getBIObjectActiveTemplate(Integer.valueOf(documentId));
        if(template==null) throw new Exception("Active Template null");
        contentBytes = template.getContent();
        if(contentBytes==null) {
          logger.error("TEMPLATE DOESN'T EXIST !!!!!!!!!!!!!!!!!!!!!!!!!!!");
          EMFUserError userError = new EMFUserError(EMFErrorSeverity.ERROR, 2007);
          userError.setBundle("messages");
          throw userError;
        }

        // get bytes of template and transform them into a SourceBean

        String contentStr = new String(contentBytes);
        content = SourceBean.fromXMLString(contentStr);
      } catch (Exception e) {
        logger.error("Error while converting the Template bytes into a SourceBean object");
        EMFUserError userError = new EMFUserError(EMFErrorSeverity.ERROR, 2003);
        userError.setBundle("messages");
        throw userError;
      }
      //    **************take informations on the chart type*****************
      String type=content.getName();
      String subtype = (String)content.getAttribute("type");

      //if it's an highcharts document get the png file by the svg content presents into the
      // description of the biobject
      if (type != null && type.startsWith(HIGHCHART_TEMPLATE)){       
        //create the png file using the svg
        InputStream inputStream = null;
          OutputStream outputStream = null;
          try{
          String svg = obj.getDescription();
          //svg = svg.replaceAll("\\\\", "");       
          inputStream = new ByteArrayInputStream(svg.getBytes("UTF-8"));
          File dir = new File(System.getProperty("java.io.tmpdir"));
          Random generator = new Random();
          int randomInt = generator.nextInt();
          toReturn = File.createTempFile(Integer.valueOf(randomInt).toString(), ".png", dir);
          outputStream = new FileOutputStream(toReturn);
          ExportHighCharts.transformSVGIntoPNG(inputStream, outputStream)
          } catch (Exception e) {
          logger.error(e);
          return null;
        }finally {
            if (inputStream != null) {
              try {
                inputStream.close();
              } catch (IOException e) {
                logger.error(e);
              }
            }
            if (outputStream != null) {
              try {
                outputStream.close();
              } catch (IOException e) {
                logger.error(e);
              }
            }
            logger.debug("OUT");
         
        logger.debug("OUT");
        return toReturn;
      }

      String data="";
      try{
        logger.debug("Getting Data Set ID");
        data=obj.getDataSetId().toString();
      }catch (Exception e) {
        logger.error("Error while getting the dataset ",e);
        return null;
      }

      //Map parametersMap=getParametersCode(obj);
      Map parametersMap=getParameters(obj);

      try{
        logger.debug("create the chart");
        // set the right chart type
        sbi=ChartImpl.createChart(type, subtype);
        sbi.setProfile(userProfile);
        sbi.setType(type);
        sbi.setSubtype(subtype);
        sbi.setData(data);
        sbi.setLocale(locale);
        sbi.setParametersObject(parametersMap);
        // configure the chart with template parameters
        sbi.configureChart(content);
        sbi.setLocalizedTitle();

        //        Don't care for linkable charts configuration because we are building for static exporting

      }
      catch (Exception e) {
        logger.error("Error while creating the chart",e);
        EMFUserError userError = new EMFUserError(EMFErrorSeverity.ERROR, 2004);
        userError.setBundle("messages");
        throw userError;
      }


      datasets=retrieveDatasetValue(sbi);

      String series=null;
      String categories=null;
      String catGroups=null;
      String n_visualization=null;

      //check if serie or categories or cat_group have been set, here you have to check among parameters
      if(parametersMap.get("serie")!=null)
      {// check what happens in case of multivalue! 
        series=parametersMap.get("serie").toString();
      }
      if(parametersMap.get("cat_group")!=null)
      {// check what happens in case of multivalue! 
        catGroups=parametersMap.get("cat_group").toString();
      }

      if(parametersMap.get("categoryAll")!=null)
      {
        categories="0";   
      }
      else if(parametersMap.get("category")!=null){
        categories=parametersMap.get("category").toString();
        if(categories.equals("0")) categories="1";
      }

      if(parametersMap.get("n_visualization")!=null)
      {// check what happens in case of multivalue! 
        n_visualization=parametersMap.get("n_visualization").toString();
      }


      // Now I have to filter the dataset and draw the image!
      AttributesContainer attCont=new AttributesContainer(parametersMap);
      DatasetMap copyDatasets=null;


      // use the same code used in chart.jsp to filter various type of chart
      datasets.setSelectedSeries(new Vector());
      if(sbi.getType().equalsIgnoreCase("BARCHART") || sbi.getType().equalsIgnoreCase("CLUSTERCHART")){
View Full Code Here

   *
   * @throws EMFUserError the EMF user error
   */

  public void executeChart(RequestContainer requestContainer, BIObject obj, SourceBean response, IEngUserProfile userProfile, Locale locale) throws EMFUserError{
    DatasetMap datasets=null;
    ChartImpl sbi=null;

    //RequestContainer requestContainer=RequestContainer.getRequestContainer();
    SourceBean serviceRequest=requestContainer.getServiceRequest();
    ResponseContainer responseContainer=ResponseContainer.getResponseContainer();
View Full Code Here

    return JSONPars;
  }


  public DatasetMap retrieveDatasetValue(ChartImpl sbi) throws EMFUserError{
    DatasetMap datasets=null;
    // calculate values for the chart
    try{
      logger.debug("Retrieve value by executing the dataset");
      datasets=sbi.calculateValue();
   
View Full Code Here

TOP

Related Classes of it.eng.spagobi.engines.chart.utils.DatasetMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.