Package org.dspace.statistics

Examples of org.dspace.statistics.ObjectCount


                        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){
View Full Code Here


                    }
                    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{
View Full Code Here

                        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){
View Full Code Here

                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

TOP

Related Classes of org.dspace.statistics.ObjectCount

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.