Package org.dspace.statistics

Examples of org.dspace.statistics.Dataset


      throws SAXException, WingException, SQLException,
      SolrServerException, IOException, ParseException {

    String title = display.getTitle();

    Dataset dataset = display.getDataset();

    if (dataset == null) {
      /** activate dataset query */
      dataset = display.getDataset(context);
    }

    if (dataset != null) {

      String[][] matrix = dataset.getMatrixFormatted();

      /** Generate Table */
      Division wrapper = mainDiv.addDivision("tablewrapper");
      Table table = wrapper.addTable("list-table", 1, 1,
          title == null ? "" : "tableWithTitle");
      if (title != null)
        table.setHead(message(title));

      /** Generate Header Row */
      Row headerRow = table.addRow();
      headerRow.addCell("spacer", Cell.ROLE_DATA, "labelcell");

      String[] cLabels = dataset.getColLabels().toArray(new String[0]);
      for (int row = 0; row < cLabels.length; row++) {
        Cell cell = headerRow.addCell(0 + "-" + row + "-h",
            Cell.ROLE_DATA, "labelcell");
        cell.addContent(cLabels[row]);
      }

      /** Generate Table Body */
      for (int row = 0; row < matrix.length; row++) {
        Row valListRow = table.addRow();

        /** Add Row Title */
        valListRow.addCell("" + row, Cell.ROLE_DATA, "labelcell")
            .addContent(dataset.getRowLabels().get(row));

        /** Add Rest of Row */
        for (int col = 0; col < matrix[row].length; col++) {
          Cell cell = valListRow.addCell(row + "-" + col,
              Cell.ROLE_DATA, "datacell");
View Full Code Here


      throws SAXException, WingException, SQLException,
      SolrServerException, IOException, ParseException {

    String title = display.getTitle();

    Dataset dataset = display.getDataset();

    if (dataset == null) {
      /** activate dataset query */
      dataset = display.getDataset(context);
    }

    if (dataset != null) {

      String[][] matrix = dataset.getMatrixFormatted();

      // String[] rLabels = dataset.getRowLabels().toArray(new String[0]);

      Table table = mainDiv.addTable("list-table", matrix.length, 2,
          title == null ? "" : "tableWithTitle");
      if (title != null)
        table.setHead(message(title));

      Row headerRow = table.addRow();

      headerRow.addCell("", Cell.ROLE_DATA, "labelcell");
     
      headerRow.addCell("", Cell.ROLE_DATA, "labelcell").addContent(message(T_head_visits_views));

      /** Generate Table Body */
      for (int col = 0; col < matrix[0].length; col++) {
        Row valListRow = table.addRow();

        Cell catCell = valListRow.addCell(col + "1", Cell.ROLE_DATA,
            "labelcell");
        catCell.addContent(dataset.getColLabels().get(col));

        Cell valCell = valListRow.addCell(col + "2", Cell.ROLE_DATA,
            "datacell");
        valCell.addContent(matrix[0][col]);

View Full Code Here

                filterQuery += " AND ";
        }
//        System.out.println("FILTERQUERY: " + filterQuery);

        //We determine our values on the querys resolved above
        Dataset dataset = null;

        //Run over our queries
        //First how many queries do we have ?
        if(dateFacet != null){
            //So do all the queries and THEN do the date facet
            for (int i = 0; i < datasetQueries.size(); i++) {
                DatasetQuery dataSetQuery = datasetQueries.get(i);
                if(dataSetQuery.getQueries().size() != 1){
                    //TODO: do this
                }else{
                    String query = dataSetQuery.getQueries().get(0).getQuery();
                    if(dataSetQuery.getMax() == -1){
                        //We are asking from our current query all the visits faceted by date
                        ObjectCount[] results = SolrLogger.queryFacetDate(query, filterQuery, dataSetQuery.getMax(), dateFacet.getDateType(), dateFacet.getStartDate(), dateFacet.getEndDate(), showTotal);
                        dataset = new Dataset(1, results.length);
                        //Now that we have our results put em in a matrix
                        for(int j = 0; j < results.length; j++){
                            dataset.setColLabel(j, results[j].getValue());
                            dataset.addValueToMatrix(0, j, results[j].getCount());
                        }
                        //TODO: change this !
                        //Now add the column label
                        dataset.setRowLabel(0, getResultName(dataSetQuery.getName(), dataSetQuery, context));
                        dataset.setRowLabelAttr(0, getAttributes(dataSetQuery.getName(), dataSetQuery, context));
                    }else{
                        //We need to get the max objects and the next part of the query on them (next part beeing the datasettimequery
                        ObjectCount[] maxObjectCounts = SolrLogger.queryFacetField(query, filterQuery, dataSetQuery.getFacetField(), dataSetQuery.getMax(), false, null);
                        for (int j = 0; j < maxObjectCounts.length; j++) {
                            ObjectCount firstCount = maxObjectCounts[j];
                            String newQuery = dataSetQuery.getFacetField() + ": " + ClientUtils.escapeQueryChars(firstCount.getValue()) + " AND " + query;
                            ObjectCount[] maxDateFacetCounts = SolrLogger.queryFacetDate(newQuery, filterQuery, dataSetQuery.getMax(), dateFacet.getDateType(), dateFacet.getStartDate(), dateFacet.getEndDate(), showTotal);


                            //Make sure we have a dataSet
                            if(dataset == null)
                                dataset = new Dataset(maxObjectCounts.length, maxDateFacetCounts.length);

                            //TODO: this is a very dirty fix chance this ! ! ! ! ! !
                            dataset.setRowLabel(j, getResultName(firstCount.getValue(), dataSetQuery, context));
                            dataset.setRowLabelAttr(j, getAttributes(firstCount.getValue(), dataSetQuery, context));

                            for (int k = 0; k < maxDateFacetCounts.length; k++) {
                                ObjectCount objectCount = maxDateFacetCounts[k];
                                //No need to add this many times
                                if(j == 0)
                                    dataset.setColLabel(k, objectCount.getValue());
                                dataset.addValueToMatrix(j, k, objectCount.getCount());
                            }
                        }
                        if(dataset != null && !(getDatasetGenerators().get(0) instanceof DatasetTimeGenerator)){
                            dataset.flipRowCols();
                        }
                    }
                }
            }
        }else{
            //We do NOT have a datefacet so just do querys after eachother
            /*
            for (int i = 0; i < datasetQueries.size(); i++) {
                DatasetQuery datasetQuery = datasetQueries.get(i);
                if(datasetQuery.getQueries().size() != 1){
                    //TODO: do this
                }else{
                    String query = datasetQuery.getQueries().get(0);
                    //Loop over the queries & do em
//                    ObjectCount[] topCounts = SolrLogger.queryFacetField(query, );
                }
            }
            */
            DatasetQuery firsDataset = datasetQueries.get(0);
            //Do the first query

            ObjectCount[] topCounts1 = null;
//            if(firsDataset.getQueries().size() == 1){
            topCounts1 = queryFacetField(firsDataset, firsDataset.getQueries().get(0).getQuery(), filterQuery);
//            }else{
//                TODO: do this
//            }
            //Check if we have more queries that need to be done
            if(datasetQueries.size() == 2){
                DatasetQuery secondDataSet = datasetQueries.get(1);
                //Now do the second one
                ObjectCount[] topCounts2 = queryFacetField(secondDataSet, secondDataSet.getQueries().get(0).getQuery(), filterQuery);
                //Now that have results for both of them lets do x.y queries
                List<String> facetQueries = new ArrayList<String>();
                for (ObjectCount count2 : topCounts2) {
                    String facetQuery = secondDataSet.getFacetField() + ":" + ClientUtils.escapeQueryChars(count2.getValue());
                    //Check if we also have a type present (if so this should be put into the query
                    if ("id".equals(secondDataSet.getFacetField()) && secondDataSet.getQueries().get(0).getDsoType() != -1)
                        facetQuery += " AND type:" + secondDataSet.getQueries().get(0).getDsoType();

                    facetQueries.add(facetQuery);
                }
                for (int i = 0; i < topCounts1.length; i++){
                    ObjectCount count1 = topCounts1[i];
                    ObjectCount[] currentResult = new ObjectCount[topCounts2.length];

                    //Make sure we have a dataSet
                    if(dataset == null)
                        dataset = new Dataset(topCounts2.length, topCounts1.length);
                    dataset.setColLabel(i, getResultName(count1.getValue(), firsDataset, context));
                    dataset.setColLabelAttr(i, getAttributes(count1.getValue(), firsDataset, context));

                    String query = firsDataset.getFacetField() + ":" + ClientUtils.escapeQueryChars(count1.getValue());
                    //Check if we also have a type present (if so this should be put into the query
                    if("id".equals(firsDataset.getFacetField()) && firsDataset.getQueries().get(0).getDsoType() != -1)
                        query += " AND type:" + firsDataset.getQueries().get(0).getDsoType();

                    Map<String, Integer> facetResult = SolrLogger.queryFacetQuery(query, filterQuery, facetQueries);
                   
                   
                    //TODO: the show total
                    //No need to add this many times
                    //TODo: dit vervangen door te displayen value
                    for (int j = 0; j < topCounts2.length; j++) {
                        ObjectCount count2 = topCounts2[j];
                        if(i == 0) {
                            dataset.setRowLabel(j, getResultName(count2.getValue(), secondDataSet, context));
                            dataset.setRowLabelAttr(j, getAttributes(count2.getValue(), secondDataSet, context));

                        }
                        //Get our value the value is the same as the query
                        String facetQuery = secondDataSet.getFacetField() + ":" + ClientUtils.escapeQueryChars(count2.getValue());
                        //Check if we also have a type present (if so this should be put into the query
                        if ("id".equals(secondDataSet.getFacetField()) && secondDataSet.getQueries().get(0).getDsoType() != -1)
                            facetQuery += " AND type:" + secondDataSet.getQueries().get(0).getDsoType();

                        //We got our query so now get the value
                        dataset.addValueToMatrix(j, i, facetResult.get(facetQuery));
                    }

                    /*
                    for (int j = 0; j < topCounts2.length; j++) {
                        ObjectCount count2 = topCounts2[j];
                        String query = firsDataset.getFacetField() + ":" + count1.getValue();
                        //Check if we also have a type present (if so this should be put into the query
                        if("id".equals(firsDataset.getFacetField()) && firsDataset.getQueries().get(0).getDsoType() != -1)
                            query += " AND type:" + firsDataset.getQueries().get(0).getDsoType();

                        query += " AND " + secondDataSet.getFacetField() + ":" + count2.getValue();
                        //Check if we also have a type present (if so this should be put into the query
                        if("id".equals(secondDataSet.getFacetField()) && secondDataSet.getQueries().get(0).getDsoType() != -1)
                            query += " AND type:" + secondDataSet.getQueries().get(0).getDsoType();

                        long count = SolrLogger.queryFacetQuery(query, filterQuery);

                        //TODO: the show total
                        //No need to add this many times
                        //TODo: dit vervangen door te displayen value
                        if(i == 0) {
                            dataset.setRowLabel(j, getResultName(count2.getValue(), secondDataSet, context));
                            dataset.setRowLabelAttr(j, getAttributes(count2.getValue(), secondDataSet, context));

                        }

                        dataset.addValueToMatrix(j, i, count);
                    }
                    */
                }

//                System.out.println("BOTH");

            } else{
                //Make sure we have a dataSet
                dataset = new Dataset(1, topCounts1.length);
                for (int i = 0; i < topCounts1.length; i++) {
                    ObjectCount count = topCounts1[i];
                    dataset.setColLabel(i, getResultName(count.getValue(), firsDataset, context));
                    dataset.setColLabelAttr(i, getAttributes(count.getValue(), firsDataset, context));
                    dataset.addValueToMatrix(0, i, count.getCount());
                }
            }

        }
        if(dataset != null){
            dataset.setRowTitle("Dataset 1");
            dataset.setColTitle("Dataset 2");
        }else
            dataset = new Dataset(0,0);
        return dataset;
    }
View Full Code Here

            statListing.setId("list1");

            DatasetDSpaceObjectGenerator dsoAxis = new DatasetDSpaceObjectGenerator();
            dsoAxis.addDsoChild(dso.getType(), 10, false, -1);
            statListing.addDatasetGenerator(dsoAxis);
            Dataset dataset = statListing.getDataset(context);

            dataset = statListing.getDataset();

            if (dataset == null)
            {
   
    dataset = statListing.getDataset(context);
            }

            if (dataset != null)
            {
                String[][] matrix = dataset.getMatrixFormatted();
                List<String> colLabels = dataset.getColLabels();
                List<String> rowLabels = dataset.getRowLabels();

                statsVisits.setMatrix(matrix);
                statsVisits.setColLabels(colLabels);
                statsVisits.setRowLabels(rowLabels);
            }


  } catch (Exception e)
        {
    log.error(
                    "Error occured while creating statistics for dso with ID: "
                            + dso.getID() + " and type " + dso.getType()
                            + " and handle: " + dso.getHandle(), e);
  }
       

  try
        {

            StatisticsTable statisticsTable = new StatisticsTable(new StatisticsDataVisits(dso));

            statisticsTable.setTitle("Total Visits Per Month");
            statisticsTable.setId("tab1");

            DatasetTimeGenerator timeAxis = new DatasetTimeGenerator();
            timeAxis.setDateInterval("month", "-6", "+1");
            statisticsTable.addDatasetGenerator(timeAxis);

            DatasetDSpaceObjectGenerator dsoAxis = new DatasetDSpaceObjectGenerator();
            dsoAxis.addDsoChild(dso.getType(), 10, false, -1);
            statisticsTable.addDatasetGenerator(dsoAxis);
            Dataset dataset = statisticsTable.getDataset(context);

            dataset = statisticsTable.getDataset();

            if (dataset == null)
            {
   
    dataset = statisticsTable.getDataset(context);
            }

            if (dataset != null)
            {
                String[][] matrix = dataset.getMatrixFormatted();
                List<String> colLabels = dataset.getColLabels();
                List<String> rowLabels = dataset.getRowLabels();

                statsMonthlyVisits.setMatrix(matrix);
                statsMonthlyVisits.setColLabels(colLabels);
                statsMonthlyVisits.setRowLabels(rowLabels);
            }
  } catch (Exception e)
        {
            log.error(
                "Error occured while creating statistics for dso with ID: "
                                + dso.getID() + " and type " + dso.getType()
                                + " and handle: " + dso.getHandle(), e);
  }

        if(dso instanceof org.dspace.content.Item)
        {
            isItem = true;

            try
            {

                StatisticsListing statisticsTable = new StatisticsListing(new StatisticsDataVisits(dso));

                statisticsTable.setTitle("File Downloads");
                statisticsTable.setId("tab1");

                DatasetDSpaceObjectGenerator dsoAxis = new DatasetDSpaceObjectGenerator();
                dsoAxis.addDsoChild(Constants.BITSTREAM, 10, false, -1);
                statisticsTable.addDatasetGenerator(dsoAxis);

                Dataset dataset = statisticsTable.getDataset(context);

                dataset = statisticsTable.getDataset();

                if (dataset == null)
                {

                    dataset = statisticsTable.getDataset(context);
                }

                if (dataset != null)
                {
                    String[][] matrix = dataset.getMatrixFormatted();
                    List<String> colLabels = dataset.getColLabels();
                    List<String> rowLabels = dataset.getRowLabels();

                    statsFileDownloads.setMatrix(matrix);
                    statsFileDownloads.setColLabels(colLabels);
                    statsFileDownloads.setRowLabels(rowLabels);
                }
            }
            catch (Exception e)
            {
                log.error(
                    "Error occured while creating statistics for dso with ID: "
                                    + dso.getID() + " and type " + dso.getType()
                                    + " and handle: " + dso.getHandle(), e);
            }
        }

        try
            {

                StatisticsListing statisticsTable = new StatisticsListing(new StatisticsDataVisits(dso));

                statisticsTable.setTitle("Top country views");
                statisticsTable.setId("tab1");

                DatasetTypeGenerator typeAxis = new DatasetTypeGenerator();
                typeAxis.setType("countryCode");
                typeAxis.setMax(10);
                statisticsTable.addDatasetGenerator(typeAxis);

                Dataset dataset = statisticsTable.getDataset(context);

                dataset = statisticsTable.getDataset();

                if (dataset == null)
                {

                    dataset = statisticsTable.getDataset(context);
                }

                if (dataset != null)
                {
                    String[][] matrix = dataset.getMatrixFormatted();
                    List<String> colLabels = dataset.getColLabels();
                    List<String> rowLabels = dataset.getRowLabels();

                    statsCountryVisits.setMatrix(matrix);
                    statsCountryVisits.setColLabels(colLabels);
                    statsCountryVisits.setRowLabels(rowLabels);
                }
            }
            catch (Exception e)
            {
                log.error(
                    "Error occured while creating statistics for dso with ID: "
                                    + dso.getID() + " and type " + dso.getType()
                                    + " and handle: " + dso.getHandle(), e);
            }

        try
            {

                StatisticsListing statisticsTable = new StatisticsListing(new StatisticsDataVisits(dso));

                statisticsTable.setTitle("Top city views");
                statisticsTable.setId("tab1");

                DatasetTypeGenerator typeAxis = new DatasetTypeGenerator();
                typeAxis.setType("city");
                typeAxis.setMax(10);
                statisticsTable.addDatasetGenerator(typeAxis);

                Dataset dataset = statisticsTable.getDataset(context);

                dataset = statisticsTable.getDataset();

                if (dataset == null)
                {

                    dataset = statisticsTable.getDataset(context);
                }

                if (dataset != null)
                {
                    String[][] matrix = dataset.getMatrixFormatted();
                    List<String> colLabels = dataset.getColLabels();
                    List<String> rowLabels = dataset.getRowLabels();

                    statsCityVisits.setMatrix(matrix);
                    statsCityVisits.setColLabels(colLabels);
                    statsCityVisits.setRowLabels(rowLabels);
                }
View Full Code Here

        String defaultFilterQuery = StringUtils.join(defaultFilters.iterator(), " AND ");

        String query = getQuery();

        Dataset dataset = new Dataset(0,0);
        List<DatasetGenerator> datasetGenerators = getDatasetGenerators();
        if(0 < datasetGenerators.size()){
            //At the moment we can only have one dataset generator
            DatasetGenerator datasetGenerator = datasetGenerators.get(0);
            if(datasetGenerator instanceof DatasetSearchGenerator){
                DatasetSearchGenerator typeGenerator = (DatasetSearchGenerator) datasetGenerator;

                if(typeGenerator.getMode() == DatasetSearchGenerator.Mode.SEARCH_OVERVIEW){
                    StringBuilder fqBuffer = new StringBuilder(defaultFilterQuery);
                    if(0 < fqBuffer.length())
                    {
                        fqBuffer.append(" AND ");
                    }
                    fqBuffer.append(getSearchFilterQuery());

                    ObjectCount[] topCounts = SolrLogger.queryFacetField(query, fqBuffer.toString(), typeGenerator.getType(), typeGenerator.getMax(), (typeGenerator.isPercentage() || typeGenerator.isIncludeTotal()), null);
                    long totalCount = -1;
                    if(typeGenerator.isPercentage() && 0 < topCounts.length){
                        //Retrieve the total required to calculate the percentage
                        totalCount = topCounts[topCounts.length - 1].getCount();
                        //Remove the total count from view !
                        topCounts = (ObjectCount[]) ArrayUtils.subarray(topCounts, 0, topCounts.length - 1);
                    }

                    int nrColumns = 2;
                    if(typeGenerator.isPercentage()){
                        nrColumns++;
                    }
                    if(typeGenerator.isRetrievePageViews()){
                        nrColumns++;
                    }

                    dataset = new Dataset(topCounts.length, nrColumns);
                    dataset.setColLabel(0, "search-terms");
                    dataset.setColLabel(1, "searches");
                    if(typeGenerator.isPercentage()){
                        dataset.setColLabel(2, "percent-total");
                    }
                    if(typeGenerator.isRetrievePageViews()){
                        dataset.setColLabel(3, "views-search");
                    }
                    for (int i = 0; i < topCounts.length; i++) {
                        ObjectCount queryCount = topCounts[i];

                        dataset.setRowLabel(i, String.valueOf(i + 1));
                        String displayedValue = queryCount.getValue();
                        if(new DSpace().getConfigurationService().getPropertyAsType("usage-statistics.search.statistics.unescape.queries", Boolean.TRUE)){
                            displayedValue = displayedValue.replace("\\", "");
                        }
                        dataset.addValueToMatrix(i, 0, displayedValue);
                        dataset.addValueToMatrix(i, 1, queryCount.getCount());
                        if(typeGenerator.isPercentage()){
                            //Calculate our percentage from the total !
                            dataset.addValueToMatrix(i, 2, percentageFormat.format(((float) queryCount.getCount() / totalCount)));
                        }
                        if(typeGenerator.isRetrievePageViews()){
                            String queryString = ClientUtils.escapeQueryChars(queryCount.getValue());
                            if(queryString.equals("")){
                                queryString = "\"\"";
                            }

                            ObjectCount totalPageViews = getTotalPageViews("query:" + queryString, defaultFilterQuery);
                            dataset.addValueToMatrix(i, 3, pageViewFormat.format((float) totalPageViews.getCount() / queryCount.getCount()));
                        }
                    }
                }else
                if(typeGenerator.getMode() == DatasetSearchGenerator.Mode.SEARCH_OVERVIEW_TOTAL){
                    //Retrieve the total counts !
                    ObjectCount totalCount = SolrLogger.queryTotal(query, getSearchFilterQuery());

                    //Retrieve the filtered count by using the default filter query
                    StringBuilder fqBuffer = new StringBuilder(defaultFilterQuery);
                    if(0 < fqBuffer.length())
                    {
                        fqBuffer.append(" AND ");
                    }
                    fqBuffer.append(getSearchFilterQuery());

                    ObjectCount totalFiltered = SolrLogger.queryTotal(query, fqBuffer.toString());


                    fqBuffer = new StringBuilder(defaultFilterQuery);
                    if(0 < fqBuffer.length())
                    {
                        fqBuffer.append(" AND ");
                    }
                    fqBuffer.append("statistics_type:").append(SolrLogger.StatisticsType.SEARCH_RESULT.text());

                    ObjectCount totalPageViews = getTotalPageViews(query, defaultFilterQuery);

                    dataset = new Dataset(1, 3);
                    dataset.setRowLabel(0, "");


                    dataset.setColLabel(0, "searches");
                    dataset.addValueToMatrix(0, 0, totalFiltered.getCount());
                    dataset.setColLabel(1, "percent-total");
                    //Ensure that we do NOT divide by 0
                    float percentTotal;
                    if(totalCount.getCount() == 0){
                        percentTotal = 0;
                    }else{
                        percentTotal = (float) totalFiltered.getCount() / totalCount.getCount();
                    }


                    dataset.addValueToMatrix(0, 1, percentageFormat.format(percentTotal));
                    dataset.setColLabel(2, "views-search");
                    //Ensure that we do NOT divide by 0
                    float pageViews;
                    if(totalFiltered.getCount() == 0){
                        pageViews = 0;
                    }else{
                        pageViews = (float) totalPageViews.getCount() / totalFiltered.getCount();
                    }

                    dataset.addValueToMatrix(0, 2, pageViewFormat.format(pageViews));
                }
            }else{
                throw new IllegalArgumentException("Data generator with class" + datasetGenerator.getClass().getName() + " is not supported by the statistics search engine !");
            }
        }
View Full Code Here


//        System.out.println("FILTERQUERY: " + filterQuery);

        // We determine our values on the queries resolved above
        Dataset dataset = null;

        // Run over our queries.
        // First how many queries do we have ?
        if(dateFacet != null){
            // So do all the queries and THEN do the date facet
            for (int i = 0; i < datasetQueries.size(); i++) {
                DatasetQuery dataSetQuery = datasetQueries.get(i);
                if(dataSetQuery.getQueries().size() != 1){
                    // TODO: do this
                }else{
                    String query = dataSetQuery.getQueries().get(0).getQuery();
                    if(dataSetQuery.getMax() == -1){
                        // We are asking from our current query all the visits faceted by date
                        ObjectCount[] results = SolrLogger.queryFacetDate(query, filterQuery, dataSetQuery.getMax(), dateFacet.getDateType(), dateFacet.getStartDate(), dateFacet.getEndDate(), showTotal, context);
                        dataset = new Dataset(1, results.length);
                        // Now that we have our results put em in a matrix
                        for(int j = 0; j < results.length; j++){
                            dataset.setColLabel(j, results[j].getValue());
                            dataset.addValueToMatrix(0, j, results[j].getCount());
                        }
                        // TODO: change this !
                        // Now add the column label
                        dataset.setRowLabel(0, getResultName(dataSetQuery.getName(), dataSetQuery, context));
                        dataset.setRowLabelAttr(0, getAttributes(dataSetQuery.getName(), dataSetQuery, context));
                    }else{
                        // We need to get the max objects and the next part of the query on them (next part beeing the datasettimequery
                        ObjectCount[] maxObjectCounts = SolrLogger.queryFacetField(query, filterQuery, dataSetQuery.getFacetField(), dataSetQuery.getMax(), false, null);
                        for (int j = 0; j < maxObjectCounts.length; j++) {
                            ObjectCount firstCount = maxObjectCounts[j];
                            String newQuery = dataSetQuery.getFacetField() + ": " + ClientUtils.escapeQueryChars(firstCount.getValue()) + " AND " + query;
                            ObjectCount[] maxDateFacetCounts = SolrLogger.queryFacetDate(newQuery, filterQuery, dataSetQuery.getMax(), dateFacet.getDateType(), dateFacet.getStartDate(), dateFacet.getEndDate(), showTotal, context);


                            // Make sure we have a dataSet
                            if(dataset == null)
                            {
                                dataset = new Dataset(maxObjectCounts.length, maxDateFacetCounts.length);
                            }

                            // TODO: this is a very dirty fix change this ! ! ! ! ! !
                            dataset.setRowLabel(j, getResultName(firstCount.getValue(), dataSetQuery, context));
                            dataset.setRowLabelAttr(j, getAttributes(firstCount.getValue(), dataSetQuery, context));

                            for (int k = 0; k < maxDateFacetCounts.length; k++) {
                                ObjectCount objectCount = maxDateFacetCounts[k];
                                // No need to add this many times
                                if(j == 0)
                                {
                                    dataset.setColLabel(k, objectCount.getValue());
                                }
                                dataset.addValueToMatrix(j, k, objectCount.getCount());
                            }
                        }
                        if(dataset != null && !(getDatasetGenerators().get(0) instanceof DatasetTimeGenerator)){
                            dataset.flipRowCols();
                        }
                    }
                }
            }
        }else{
            // We do NOT have a date facet so just do queries after each other
            /*
            for (int i = 0; i < datasetQueries.size(); i++) {
                DatasetQuery datasetQuery = datasetQueries.get(i);
                if(datasetQuery.getQueries().size() != 1){
                    // TODO: do this
                }else{
                    String query = datasetQuery.getQueries().get(0);
                    // Loop over the queries & do em
//                    ObjectCount[] topCounts = SolrLogger.queryFacetField(query, );
                }
            }
            */
            DatasetQuery firsDataset = datasetQueries.get(0);
            //Do the first query

            ObjectCount[] topCounts1 = null;
//            if(firsDataset.getQueries().size() == 1){
            topCounts1 = queryFacetField(firsDataset, firsDataset.getQueries().get(0).getQuery(), filterQuery);
//            }else{
//                TODO: do this
//            }
            // Check if we have more queries that need to be done
            if(datasetQueries.size() == 2){
                DatasetQuery secondDataSet = datasetQueries.get(1);
                // Now do the second one
                ObjectCount[] topCounts2 = queryFacetField(secondDataSet, secondDataSet.getQueries().get(0).getQuery(), filterQuery);
                // Now that have results for both of them lets do x.y queries
                List<String> facetQueries = new ArrayList<String>();
                for (ObjectCount count2 : topCounts2) {
                    String facetQuery = secondDataSet.getFacetField() + ":" + ClientUtils.escapeQueryChars(count2.getValue());
                    // Check if we also have a type present (if so this should be put into the query)
                    if ("id".equals(secondDataSet.getFacetField()) && secondDataSet.getQueries().get(0).getDsoType() != -1)
                    {
                        facetQuery += " AND type:" + secondDataSet.getQueries().get(0).getDsoType();
                    }

                    facetQueries.add(facetQuery);
                }
                for (int i = 0; i < topCounts1.length; i++){
                    ObjectCount count1 = topCounts1[i];
                    ObjectCount[] currentResult = new ObjectCount[topCounts2.length];

                    // Make sure we have a dataSet
                    if(dataset == null)
                    {
                        dataset = new Dataset(topCounts2.length, topCounts1.length);
                    }
                    dataset.setColLabel(i, getResultName(count1.getValue(), firsDataset, context));
                    dataset.setColLabelAttr(i, getAttributes(count1.getValue(), firsDataset, context));

                    String query = firsDataset.getFacetField() + ":" + ClientUtils.escapeQueryChars(count1.getValue());
                    // Check if we also have a type present (if so this should be put into the query)
                    if("id".equals(firsDataset.getFacetField()) && firsDataset.getQueries().get(0).getDsoType() != -1)
                    {
                        query += " AND type:" + firsDataset.getQueries().get(0).getDsoType();
                    }

                    Map<String, Integer> facetResult = SolrLogger.queryFacetQuery(query, filterQuery, facetQueries);
                   
                   
                    // TODO: the show total
                    // No need to add this many times
                    // TODO: dit vervangen door te displayen value
                    for (int j = 0; j < topCounts2.length; j++) {
                        ObjectCount count2 = topCounts2[j];
                        if(i == 0) {
                            dataset.setRowLabel(j, getResultName(count2.getValue(), secondDataSet, context));
                            dataset.setRowLabelAttr(j, getAttributes(count2.getValue(), secondDataSet, context));

                        }
                        // Get our value the value is the same as the query
                        String facetQuery = secondDataSet.getFacetField() + ":" + ClientUtils.escapeQueryChars(count2.getValue());
                        // Check if we also have a type present (if so this should be put into the query
                        if ("id".equals(secondDataSet.getFacetField()) && secondDataSet.getQueries().get(0).getDsoType() != -1)
                        {
                            facetQuery += " AND type:" + secondDataSet.getQueries().get(0).getDsoType();
                        }

                        // We got our query so now get the value
                        dataset.addValueToMatrix(j, i, facetResult.get(facetQuery));
                    }

                    /*
                    for (int j = 0; j < topCounts2.length; j++) {
                        ObjectCount count2 = topCounts2[j];
                        String query = firsDataset.getFacetField() + ":" + count1.getValue();
                        // Check if we also have a type present (if so this should be put into the query
                        if("id".equals(firsDataset.getFacetField()) && firsDataset.getQueries().get(0).getDsoType() != -1)
                            query += " AND type:" + firsDataset.getQueries().get(0).getDsoType();

                        query += " AND " + secondDataSet.getFacetField() + ":" + count2.getValue();
                        // Check if we also have a type present (if so this should be put into the query
                        if("id".equals(secondDataSet.getFacetField()) && secondDataSet.getQueries().get(0).getDsoType() != -1)
                            query += " AND type:" + secondDataSet.getQueries().get(0).getDsoType();

                        long count = SolrLogger.queryFacetQuery(query, filterQuery);

                        // TODO: the show total
                        // No need to add this many times
                        // TODO: dit vervangen door te displayen value
                        if(i == 0) {
                            dataset.setRowLabel(j, getResultName(count2.getValue(), secondDataSet, context));
                            dataset.setRowLabelAttr(j, getAttributes(count2.getValue(), secondDataSet, context));

                        }

                        dataset.addValueToMatrix(j, i, count);
                    }
                    */
                }

//                System.out.println("BOTH");

            } else{
                // Make sure we have a dataSet
                dataset = new Dataset(1, topCounts1.length);
                for (int i = 0; i < topCounts1.length; i++) {
                    ObjectCount count = topCounts1[i];
                    dataset.setColLabel(i, getResultName(count.getValue(), firsDataset, context));
                    dataset.setColLabelAttr(i, getAttributes(count.getValue(), firsDataset, context));
                    dataset.addValueToMatrix(0, i, count.getCount());
                }
            }

        }
        if(dataset != null){
            dataset.setRowTitle("Dataset 1");
            dataset.setColTitle("Dataset 2");
        }else
        {
            dataset = new Dataset(0, 0);
        }
        return dataset;
    }
View Full Code Here

        String defaultFilterQuery = StringUtils.join(defaultFilters.iterator(), " AND ");

        String query = getQuery();

        Dataset dataset = new Dataset(0,0);
        List<DatasetGenerator> datasetGenerators = getDatasetGenerators();
        if(0 < datasetGenerators.size()){
            //At the moment we can only have one dataset generator
            DatasetGenerator datasetGenerator = datasetGenerators.get(0);
            if(datasetGenerator instanceof DatasetTypeGenerator){
                DatasetTypeGenerator typeGenerator = (DatasetTypeGenerator) datasetGenerator;
                ObjectCount[] topCounts = SolrLogger.queryFacetField(query, defaultFilterQuery, typeGenerator.getType(), typeGenerator.getMax(), typeGenerator.isIncludeTotal(), null);

                //Retrieve our total field counts
                Map<String, Long> totalFieldCounts = new HashMap<String, Long>();
                if(averageMonths != -1){
                    totalFieldCounts = getTotalFacetCounts(typeGenerator);
                }
                long monthDifference = 1;
                if(getOldestWorkflowItemDate() != null){
                    monthDifference = getMonthsDifference(new Date(), getOldestWorkflowItemDate());
                }

                dataset = new Dataset(topCounts.length, (averageMonths != -1 ? 3 : 2));
                dataset.setColLabel(0, "step");
                dataset.setColLabel(1, "performed");
                if(averageMonths != -1){
                    dataset.setColLabel(2, "average");
                }
                for (int i = 0; i < topCounts.length; i++) {
                    ObjectCount topCount = topCounts[i];
                    dataset.setRowLabel(i, String.valueOf(i + 1));
                    dataset.addValueToMatrix(i, 0, topCount.getValue());
                    dataset.addValueToMatrix(i, 1, topCount.getCount());
                    if(averageMonths != -1){
                        //Calculate the average of one month
                        long monthlyAverage = 0;
                        if(totalFieldCounts.get(topCount.getValue()) != null){
                            monthlyAverage = totalFieldCounts.get(topCount.getValue()) / monthDifference;
                        }
                        //We multiple our average for one month by the number of
                        dataset.addValueToMatrix(i, 2, (monthlyAverage * averageMonths));
                    }

                }
            }
        }
View Full Code Here

            statListing.setId("list1");

            DatasetDSpaceObjectGenerator dsoAxis = new DatasetDSpaceObjectGenerator();
            dsoAxis.addDsoChild(dso.getType(), 10, false, -1);
            statListing.addDatasetGenerator(dsoAxis);
            Dataset dataset = statListing.getDataset(context);

            dataset = statListing.getDataset();

            if (dataset == null)
            {
   
    dataset = statListing.getDataset(context);
            }

            if (dataset != null)
            {
                String[][] matrix = dataset.getMatrix();
                List<String> colLabels = dataset.getColLabels();
                List<String> rowLabels = dataset.getRowLabels();

                statsVisits.setMatrix(matrix);
                statsVisits.setColLabels(colLabels);
                statsVisits.setRowLabels(rowLabels);
            }


  } catch (Exception e)
        {
    log.error(
                    "Error occured while creating statistics for dso with ID: "
                            + dso.getID() + " and type " + dso.getType()
                            + " and handle: " + dso.getHandle(), e);
  }
       

  try
        {

            StatisticsTable statisticsTable = new StatisticsTable(new StatisticsDataVisits(dso));

            statisticsTable.setTitle("Total Visits Per Month");
            statisticsTable.setId("tab1");

            DatasetTimeGenerator timeAxis = new DatasetTimeGenerator();
            timeAxis.setDateInterval("month", "-6", "+1");
            statisticsTable.addDatasetGenerator(timeAxis);

            DatasetDSpaceObjectGenerator dsoAxis = new DatasetDSpaceObjectGenerator();
            dsoAxis.addDsoChild(dso.getType(), 10, false, -1);
            statisticsTable.addDatasetGenerator(dsoAxis);
            Dataset dataset = statisticsTable.getDataset(context);

            dataset = statisticsTable.getDataset();

            if (dataset == null)
            {
   
    dataset = statisticsTable.getDataset(context);
            }

            if (dataset != null)
            {
                String[][] matrix = dataset.getMatrix();
                List<String> colLabels = dataset.getColLabels();
                List<String> rowLabels = dataset.getRowLabels();

                statsMonthlyVisits.setMatrix(matrix);
                statsMonthlyVisits.setColLabels(colLabels);
                statsMonthlyVisits.setRowLabels(rowLabels);
            }
  } catch (Exception e)
        {
            log.error(
                "Error occured while creating statistics for dso with ID: "
                                + dso.getID() + " and type " + dso.getType()
                                + " and handle: " + dso.getHandle(), e);
  }

        if(dso instanceof org.dspace.content.Item)
        {
            isItem = true;
            try
            {

                StatisticsListing statisticsTable = new StatisticsListing(new StatisticsDataVisits(dso));

                statisticsTable.setTitle("File Downloads");
                statisticsTable.setId("tab1");

                DatasetDSpaceObjectGenerator dsoAxis = new DatasetDSpaceObjectGenerator();
                dsoAxis.addDsoChild(Constants.BITSTREAM, 10, false, -1);
                statisticsTable.addDatasetGenerator(dsoAxis);

                Dataset dataset = statisticsTable.getDataset(context);

                dataset = statisticsTable.getDataset();

                if (dataset == null)
                {

                    dataset = statisticsTable.getDataset(context);
                }

                if (dataset != null)
                {
                    String[][] matrix = dataset.getMatrix();
                    List<String> colLabels = dataset.getColLabels();
                    List<String> rowLabels = dataset.getRowLabels();

                    statsFileDownloads.setMatrix(matrix);
                    statsFileDownloads.setColLabels(colLabels);
                    statsFileDownloads.setRowLabels(rowLabels);
                }
            }
            catch (Exception e)
            {
                log.error(
                    "Error occured while creating statistics for dso with ID: "
                                    + dso.getID() + " and type " + dso.getType()
                                    + " and handle: " + dso.getHandle(), e);
            }
        }

        try
            {

                StatisticsListing statisticsTable = new StatisticsListing(new StatisticsDataVisits(dso));

                statisticsTable.setTitle("Top country views");
                statisticsTable.setId("tab1");

                DatasetTypeGenerator typeAxis = new DatasetTypeGenerator();
                typeAxis.setType("countryCode");
                typeAxis.setMax(10);
                statisticsTable.addDatasetGenerator(typeAxis);

                Dataset dataset = statisticsTable.getDataset(context);

                dataset = statisticsTable.getDataset();

                if (dataset == null)
                {

                    dataset = statisticsTable.getDataset(context);
                }

                if (dataset != null)
                {
                    String[][] matrix = dataset.getMatrix();
                    List<String> colLabels = dataset.getColLabels();
                    List<String> rowLabels = dataset.getRowLabels();

                    statsCountryVisits.setMatrix(matrix);
                    statsCountryVisits.setColLabels(colLabels);
                    statsCountryVisits.setRowLabels(rowLabels);
                }
            }
            catch (Exception e)
            {
                log.error(
                    "Error occured while creating statistics for dso with ID: "
                                    + dso.getID() + " and type " + dso.getType()
                                    + " and handle: " + dso.getHandle(), e);
            }

        try
            {

                StatisticsListing statisticsTable = new StatisticsListing(new StatisticsDataVisits(dso));

                statisticsTable.setTitle("Top city views");
                statisticsTable.setId("tab1");

                DatasetTypeGenerator typeAxis = new DatasetTypeGenerator();
                typeAxis.setType("city");
                typeAxis.setMax(10);
                statisticsTable.addDatasetGenerator(typeAxis);

                Dataset dataset = statisticsTable.getDataset(context);

                dataset = statisticsTable.getDataset();

                if (dataset == null)
                {

                    dataset = statisticsTable.getDataset(context);
                }

                if (dataset != null)
                {
                    String[][] matrix = dataset.getMatrix();
                    List<String> colLabels = dataset.getColLabels();
                    List<String> rowLabels = dataset.getRowLabels();

                    statsCityVisits.setMatrix(matrix);
                    statsCityVisits.setColLabels(colLabels);
                    statsCityVisits.setRowLabels(rowLabels);
                }
View Full Code Here

            throws SAXException, WingException, SQLException,
            SolrServerException, IOException, ParseException {

        String title = display.getTitle();

        Dataset dataset = display.getDataset();

        if (dataset == null)
        {
            /** activate dataset query */
            dataset = display.getDataset(context);
        }

        if (dataset != null)
        {

            String[][] matrix = dataset.getMatrix();

            if(matrix.length == 0){
                //If no results are found alert the user of this !
                mainDiv.addPara(getNoResultsMessage());
                return;
            }

            /** Generate Table */
            Division wrapper = mainDiv.addDivision("tablewrapper");
            Table table = wrapper.addTable("list-table", 1, 1,
                    title == null ? "detailtable" : "tableWithTitle detailtable");
            if (title != null)
            {
                table.setHead(message(title));
            }

            /** Generate Header Row */
            Row headerRow = table.addRow();
            if(addRowTitles)
            {
                headerRow.addCell("spacer", Cell.ROLE_HEADER, "labelcell");
            }

            String[] cLabels = dataset.getColLabels().toArray(new String[0]);
            for (int row = 0; row < cLabels.length; row++)
            {
                Cell cell = headerRow.addCell(0 + "-" + row + "-h", Cell.ROLE_HEADER, "labelcell");
                cell.addContent(message("xmlui.statistics.display.table.column-label." + cLabels[row]));
            }

            /** Generate Table Body */
            for (int row = 0; row < matrix.length; row++) {
                Row valListRow = table.addRow();

                if(addRowTitles){
                    /** Add Row Title */
                    valListRow.addCell("" + row, Cell.ROLE_DATA, "labelcell")
                        .addContent(dataset.getRowLabels().get(row));
                }

                /** Add Rest of Row */
                for (int col = 0; col < matrix[row].length; col++) {
                    Cell cell = valListRow.addCell(row + "-" + col,
View Full Code Here

      throws SAXException, WingException, SQLException,
      SolrServerException, IOException, ParseException {

    String title = display.getTitle();

    Dataset dataset = display.getDataset();

    if (dataset == null) {
      /** activate dataset query */
      dataset = display.getDataset(context);
    }

    if (dataset != null) {

      String[][] matrix = dataset.getMatrix();

      /** Generate Table */
      Division wrapper = mainDiv.addDivision("tablewrapper");
      Table table = wrapper.addTable("list-table", 1, 1,
          title == null ? "detailtable" : "tableWithTitle detailtable");
      if (title != null)
            {
                table.setHead(message(title));
            }

      /** Generate Header Row */
      Row headerRow = table.addRow();
      headerRow.addCell("spacer", Cell.ROLE_HEADER, "labelcell");

      String[] cLabels = dataset.getColLabels().toArray(new String[0]);
      for (int row = 0; row < cLabels.length; row++) {
        Cell cell = headerRow.addCell(0 + "-" + row + "-h",
                        Cell.ROLE_HEADER, "labelcell");
        cell.addContent(cLabels[row]);
      }

      /** Generate Table Body */
      for (int row = 0; row < matrix.length; row++) {
        Row valListRow = table.addRow();

        /** Add Row Title */
        valListRow.addCell("" + row, Cell.ROLE_DATA, "labelcell")
            .addContent(dataset.getRowLabels().get(row));

        /** Add Rest of Row */
        for (int col = 0; col < matrix[row].length; col++) {
          Cell cell = valListRow.addCell(row + "-" + col,
              Cell.ROLE_DATA, "datacell");
View Full Code Here

TOP

Related Classes of org.dspace.statistics.Dataset

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.