Example usage for org.apache.solr.client.solrj.response FieldStatsInfo getMin

List of usage examples for org.apache.solr.client.solrj.response FieldStatsInfo getMin

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.response FieldStatsInfo getMin.

Prototype

public Object getMin() 

Source Link

Usage

From source file:com.frank.search.solr.core.ResultHelper.java

License:Apache License

private static <T extends SimpleStatsResult> T populateStatsResultWithFieldStatsInfo(T statsResult,
        FieldStatsInfo value) {

    statsResult.setMax(value.getMax());//from w ww . jav  a  2  s  .c om
    statsResult.setMin(value.getMin());
    statsResult.setCount(value.getCount());
    statsResult.setMissing(value.getMissing());
    statsResult.setStddev(value.getStddev());
    statsResult.setSumOfSquares((Double) new DirectFieldAccessor(value).getPropertyValue("sumOfSquares"));

    Object mean = value.getMean();
    if (mean instanceof Double) {
        statsResult.setMean((Double) mean);
    }

    Object sum = value.getSum();
    if (sum instanceof Double) {
        statsResult.setSum((Double) sum);
    }

    return statsResult;
}

From source file:com.nridge.ds.solr.SolrResponseBuilder.java

License:Open Source License

private void populateStatistic(QueryResponse aQueryResponse) {
    Object statObject;/*from www  .ja v a 2  s. c  o  m*/
    DataField schemaField;
    FieldStatsInfo fieldStatsInfo;
    String fieldName, fieldTitle, fieldValue;
    Logger appLogger = mAppMgr.getLogger(this, "populateStatistic");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    Map<String, FieldStatsInfo> mapFieldStatsInfo = aQueryResponse.getFieldStatsInfo();
    if (mapFieldStatsInfo != null) {
        mDocument.addRelationship(Solr.RESPONSE_STATISTIC, createStatisticsBag());
        Relationship statisticRelationship = mDocument.getFirstRelationship(Solr.RESPONSE_STATISTIC);
        if (statisticRelationship != null) {
            DataBag statisticsBag = new DataBag(statisticRelationship.getBag());
            statisticsBag.setAssignedFlagAll(false);
            DataTable statisticTable = new DataTable(statisticsBag);
            DataBag resultBag = mBag;

            for (Map.Entry<String, FieldStatsInfo> entry : mapFieldStatsInfo.entrySet()) {
                statisticTable.newRow();
                fieldName = entry.getKey();
                fieldStatsInfo = entry.getValue();
                statisticTable.setValueByName("field_name", fieldName);
                schemaField = resultBag.getFieldByName(fieldName);
                if (schemaField == null)
                    fieldTitle = Field.nameToTitle(fieldName);
                else
                    fieldTitle = schemaField.getTitle();
                statisticTable.setValueByName("field_title", fieldTitle);
                statObject = fieldStatsInfo.getMin();
                if (statObject == null)
                    fieldValue = StringUtils.EMPTY;
                else
                    fieldValue = statObject.toString();
                statisticTable.setValueByName("min", fieldValue);
                statObject = fieldStatsInfo.getMax();
                if (statObject == null)
                    fieldValue = StringUtils.EMPTY;
                else
                    fieldValue = statObject.toString();
                statisticTable.setValueByName("max", fieldValue);
                statObject = fieldStatsInfo.getCount();
                if (statObject == null)
                    fieldValue = StringUtils.EMPTY;
                else
                    fieldValue = statObject.toString();
                statisticTable.setValueByName("count", fieldValue);
                statObject = fieldStatsInfo.getMissing();
                if (statObject == null)
                    fieldValue = StringUtils.EMPTY;
                else
                    fieldValue = statObject.toString();
                statisticTable.setValueByName("missing", fieldValue);
                statObject = fieldStatsInfo.getSum();
                if (statObject == null)
                    fieldValue = StringUtils.EMPTY;
                else
                    fieldValue = statObject.toString();
                statisticTable.setValueByName("sum", fieldValue);
                statObject = fieldStatsInfo.getMean();
                if (statObject == null)
                    fieldValue = StringUtils.EMPTY;
                else
                    fieldValue = statObject.toString();
                statisticTable.setValueByName("mean", fieldValue);
                statObject = fieldStatsInfo.getStddev();
                if (statObject == null)
                    fieldValue = StringUtils.EMPTY;
                else
                    fieldValue = statObject.toString();
                statisticTable.setValueByName("standard_deviation", fieldValue);
                statisticTable.addRow();
            }

            Document facetDocument = new Document(Solr.RESPONSE_STATISTIC, statisticTable);
            statisticRelationship.add(facetDocument);
        }
    }

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);
}

From source file:org.apache.drill.exec.store.solr.SolrAggrReader.java

License:Apache License

@Override
public int next() {
    logger.debug("SolrAggrReader :: next");

    int counter = 0;

    if (!vectors.isEmpty()) {
        for (SolrAggrParam solrAggrParam : solrAggrParams) {
            String functionName = solrAggrParam.getFunctionName();
            String key = functionName + "_" + counter;
            ValueVector vv = vectors.get(functionName + "_" + counter);
            String solrField = solrAggrParam.getFieldName();
            FieldStatsInfo fieldStats = fieldStatsInfoMap.get(solrField);

            if (vv.getClass().equals(NullableBigIntVector.class)) {
                NullableBigIntVector v = (NullableBigIntVector) vv;

                Object value = null;

                if (functionName.equalsIgnoreCase("sum")) {
                    value = fieldStats.getSum();
                } else if (functionName.equalsIgnoreCase("count")) {
                    value = fieldStats.getCount();
                } else if (functionName.equalsIgnoreCase("min")) {
                    value = fieldStats.getMin();
                } else if (functionName.equalsIgnoreCase("max")) {
                    value = fieldStats.getMax();
                } else {
                    logger.debug("yet to implement function type [ " + functionName + " ]");
                }/*from  w ww  .  j av a 2  s.com*/

                Long l = 0L;

                if (value != null) {
                    BigDecimal bd = new BigDecimal(value.toString());
                    l = bd.longValue();
                }

                logger.debug("functionName [ " + functionName + " ] value is " + l + " index " + counter);
                v.getMutator().setSafe(counter, l);
            }

            counter++;
        }

        for (String functionName : vectors.keySet()) {
            ValueVector vv = vectors.get(functionName);
            vv.getMutator().setValueCount((counter > 0) ? counter : 0);
        }

        vectors.clear();
    }

    return counter;
}

From source file:org.apache.drill.exec.store.solr.SolrRecordReader.java

License:Apache License

private void processStatsRecord(FieldStatsInfo fieldStatsInfo, String functionName, int statsRecordCounter,
        int recordCounter, boolean isGroup) {
    Object fieldValue = null;/*from w ww  .  jav  a2s .c o m*/
    ValueVector vv1 = vectors.get(String.valueOf(statsRecordCounter));

    if (vv1 != null) {
        if (functionName.equalsIgnoreCase("sum")) {
            fieldValue = fieldStatsInfo.getSum();
        } else if (functionName.equalsIgnoreCase("count")) {
            fieldValue = fieldStatsInfo.getCount();
        } else if (functionName.equalsIgnoreCase("min")) {
            fieldValue = fieldStatsInfo.getMin();
        } else if (functionName.equalsIgnoreCase("max")) {
            fieldValue = fieldStatsInfo.getMax();
        } else if (functionName.equalsIgnoreCase("avg")) {
            fieldValue = fieldStatsInfo.getMean();
        } else {
            SolrRecordReader.logger.debug("Yet to implement function type [ " + functionName + " ]");
        }
    }
    processRecord(vv1, fieldValue, recordCounter);
}

From source file:org.apache.nifi.processors.solr.QuerySolr.java

License:Apache License

private static void addStatsFromSolrResponseToJsonWriter(final QueryResponse response, final JsonWriter writer)
        throws IOException {
    writer.beginObject();//from   w  ww .  ja  va 2  s  .c o m
    writer.name("stats_fields");
    writer.beginObject();
    for (Map.Entry<String, FieldStatsInfo> entry : response.getFieldStatsInfo().entrySet()) {
        FieldStatsInfo fsi = entry.getValue();
        writer.name(entry.getKey());
        writer.beginObject();
        writer.name("min").value(fsi.getMin().toString());
        writer.name("max").value(fsi.getMax().toString());
        writer.name("count").value(fsi.getCount());
        writer.name("missing").value(fsi.getMissing());
        writer.name("sum").value(fsi.getSum().toString());
        writer.name("mean").value(fsi.getMean().toString());
        writer.name("sumOfSquares").value(fsi.getSumOfSquares());
        writer.name("stddev").value(fsi.getStddev());
        writer.endObject();
    }
    writer.endObject();
    writer.endObject();
}

From source file:org.dspace.util.SolrImportExport.java

License:BSD License

/**
 * Exports documents from the given index to the specified target directory in batches of #ROWS_PER_FILE, starting at fromWhen (or all documents).
 * See #makeExportFilename for the file names that are generated.
 *
 * @param indexName The index to export.
 * @param toDir The target directory for the export. Will be created if it doesn't exist yet. The directory must be writeable.
 * @param solrUrl The solr URL for the index to export. Must not be null.
 * @param timeField The time field to use for sorting the export. Must not be null.
 * @param fromWhen Optionally, from when to export. See options for allowed values. If null or empty, all documents will be exported.
 * @throws SolrServerException if there is a problem with exporting the index.
 * @throws IOException if there is a problem creating the files or communicating with Solr.
 * @throws SolrImportExportException if there is a problem in communicating with Solr.
 *//*from   ww w.  j a  va2  s  .  c  om*/
public static void exportIndex(String indexName, File toDir, String solrUrl, String timeField, String fromWhen)
        throws SolrServerException, IOException, SolrImportExportException {
    if (StringUtils.isBlank(solrUrl)) {
        throw new SolrImportExportException(
                "Could not construct solr URL for index" + indexName + ", aborting export.");
    }

    if (!toDir.exists() || !toDir.canWrite()) {
        throw new SolrImportExportException("Target directory " + toDir
                + " doesn't exist or is not writable, aborting export of index " + indexName);
    }

    HttpSolrServer solr = new HttpSolrServer(solrUrl);

    SolrQuery query = new SolrQuery("*:*");
    if (StringUtils.isNotBlank(fromWhen)) {
        String lastValueFilter = makeFilterQuery(timeField, fromWhen);
        if (StringUtils.isNotBlank(lastValueFilter)) {
            query.addFilterQuery(lastValueFilter);
        }
    }

    query.setRows(0);
    query.setGetFieldStatistics(timeField);
    Map<String, FieldStatsInfo> fieldInfo = solr.query(query).getFieldStatsInfo();
    if (fieldInfo == null || !fieldInfo.containsKey(timeField)) {
        log.warn("Cannot get earliest date, not exporting index " + indexName + ", time field " + timeField
                + ", from " + fromWhen);
        return;
    }
    FieldStatsInfo timeFieldInfo = fieldInfo.get(timeField);
    if (timeFieldInfo == null || timeFieldInfo.getMin() == null) {
        log.warn("Cannot get earliest date, not exporting index " + indexName + ", time field " + timeField
                + ", from " + fromWhen);
        return;
    }
    Date earliestTimestamp = (Date) timeFieldInfo.getMin();

    query.setGetFieldStatistics(false);
    query.clearSorts();
    query.setRows(0);
    query.setFacet(true);
    query.add(FacetParams.FACET_RANGE, timeField);
    query.add(FacetParams.FACET_RANGE_START, SOLR_DATE_FORMAT.format(earliestTimestamp) + "/MONTH");
    query.add(FacetParams.FACET_RANGE_END, "NOW/MONTH+1MONTH");
    query.add(FacetParams.FACET_RANGE_GAP, "+1MONTH");
    query.setFacetMinCount(1);

    List<RangeFacet.Count> monthFacets = solr.query(query).getFacetRanges().get(0).getCounts();

    for (RangeFacet.Count monthFacet : monthFacets) {
        Date monthStartDate;
        String monthStart = monthFacet.getValue();
        try {
            monthStartDate = SOLR_DATE_FORMAT_NO_MS.parse(monthStart);
        } catch (java.text.ParseException e) {
            throw new SolrImportExportException("Could not read start of month batch as date: " + monthStart,
                    e);
        }
        int docsThisMonth = monthFacet.getCount();

        SolrQuery monthQuery = new SolrQuery("*:*");
        monthQuery.setRows(ROWS_PER_FILE);
        monthQuery.set("wt", "csv");
        monthQuery.set("fl", "*");

        monthQuery.addFilterQuery(timeField + ":[" + monthStart + " TO " + monthStart + "+1MONTH]");

        for (int i = 0; i < docsThisMonth; i += ROWS_PER_FILE) {
            monthQuery.setStart(i);
            URL url = new URL(solrUrl + "/select?" + monthQuery.toString());

            File file = new File(toDir.getCanonicalPath(),
                    makeExportFilename(indexName, monthStartDate, docsThisMonth, i));
            if (file.createNewFile()) {
                FileUtils.copyURLToFile(url, file);
                log.info("Exported batch " + i + " to " + file.getCanonicalPath());
            } else {
                throw new SolrImportExportException("Could not create file " + file.getCanonicalPath()
                        + " while exporting index " + indexName + ", month" + monthStart + ", batch " + i);
            }
        }
    }
}

From source file:uk.ac.ebi.phenotype.web.controller.BaselineChartsController.java

License:Apache License

private String generateBaselineChartBoxStyle(String parameterStableId,
        List<FieldStatsInfo> baselinesForParameter) throws SolrServerException, IOException {
    ParameterDTO parameter = impressService.getParameterByStableId(parameterStableId);
    //String procedureName = parameter.getProcedures().iterator().next().getName();
    System.out.println("procedure names=" + parameter.getProcedureNames());

    String yAxisTitle = parameter.getUnitX();
    List<String> xAxisLabels = new ArrayList<>();
    List<List<String>> boxColumns = new ArrayList<>();
    //get the number of decimal places to display
    int decimalPlaces = getDecimalPlacesToDisplay(baselinesForParameter);
    System.out.println("decimalPlaces=" + decimalPlaces);

    Double yMin = new Double(0);
    Double yMax = new Double(0);

    for (FieldStatsInfo baseLine : baselinesForParameter) {
        List<String> boxColumn = new ArrayList<String>();
        xAxisLabels.add("'" + baseLine.getName() + "'");
        if ((Double) baseLine.getMin() < yMin) {
            yMin = (Double) baseLine.getMin();
        }/* w w  w  . ja v a 2s.  c  o m*/
        if ((Double) baseLine.getMax() > yMax) {
            yMax = (Double) baseLine.getMax();
        }
        boxColumn.add(Double
                .toString(ChartUtils.getDecimalAdjustedDouble((Double) baseLine.getMin(), decimalPlaces)));
        double lower = (double) baseLine.getMean() - (double) baseLine.getStddev();
        boxColumn.add(Double.toString(ChartUtils.getDecimalAdjustedDouble((Double) lower, decimalPlaces)));
        boxColumn.add(Double
                .toString(ChartUtils.getDecimalAdjustedDouble((Double) baseLine.getMean(), decimalPlaces)));
        double upper = (double) baseLine.getMean() + (double) baseLine.getStddev();
        boxColumn.add(Double.toString(ChartUtils.getDecimalAdjustedDouble((Double) upper, decimalPlaces)));
        boxColumn.add(Double
                .toString(ChartUtils.getDecimalAdjustedDouble((Double) baseLine.getMax(), decimalPlaces)));
        //System.out.println(baseLine.getMin()+ " " +baseLine.getGenotypeEffect()+" "+baseLine.getMax());
        boxColumns.add(boxColumn);
        //System.out.println("boxColumn="+boxColumn);
    }

    List<String> colors = ChartColors.getHighDifferenceColorsRgba(ChartColors.alphaOpaque);

    String seriesData = "{" + " name: 'Observations'," + " data:" + boxColumns
    //                + " ["
    //                + " [760, 801, 848, 895, 965],"
    //                + " [733, 853, 939, 980, 1080],"
    //                + " [714, 762, 817, 870, 918],"
    //                + " [834, 836, 864, 882, 910] ]"
            + "," + " tooltip: {" + " headerFormat: '<em>Experiment No {point.key}</em><br/>'" + " }" + " }";

    String chartString = "$('#baseline-chart-div').highcharts({" + " colors:" + colors
            + ", chart: { type: 'boxplot'},  "
            + " tooltip: { formatter: function () { if(typeof this.point.high === 'undefined')"
            + "{ return '<b>Observation</b><br/>' + this.point.y; } "
            + "else { return '<b>Center: ' + this.key + '</b>" + "<br/>Max: ' + this.point.options.high + '"
            + "<br/>Mean + SD: ' + this.point.options.q3 + '" + "<br/>Mean: ' + this.point.options.median + '"
            + "<br/>Mean - SD: ' + this.point.options.q1 +'" + "<br/>Min: ' + this.point.options.low"
            + "; } } }    ," + " title: {  text: '" + parameter.getName()
            + " WT Variation By Center', useHTML:true } ,  subtitle: {  text: '"
            + parameter.getProcedureNames().get(0) + "' }, " + " credits: { enabled: false },  "
            + " legend: { enabled: false }, " + " xAxis: { categories:  " + xAxisLabels + "," + " labels: { "
            + "           rotation: -45, " + "           align: 'right', " + "           style: { "
            + "              fontSize: '15px'," + "              fontFamily: '\"Roboto\", sans-serif'"
            + "         } " + "     }, " + " }, \n" + " plotOptions: {" + "series:"
            + "{ groupPadding: 0.25, pointPadding: -0.5 }" + "}," + " yAxis: {  " + "max: " + yMax + ",  min: "
            + yMin + "," + " labels: { },title: { text: '" + yAxisTitle + "' }, tickAmount: 5 }, "
            + "\n series: [" + seriesData + "] });";

    return chartString;

}

From source file:uk.ac.ebi.phenotype.web.controller.BaselineChartsController.java

License:Apache License

private int getDecimalPlacesToDisplay(List<FieldStatsInfo> baselinesForParameter) {
    List<String> minAndMaxStrings = new ArrayList<>();
    for (FieldStatsInfo baseLine : baselinesForParameter) {
        String min = Double.toString((Double) baseLine.getMin());
        String max = Double.toString((Double) baseLine.getMax());
        minAndMaxStrings.add(min);/* w w w  . j  a  va 2 s  .co  m*/
        minAndMaxStrings.add(max);
    }
    int decimalPlaces = ChartUtils.getDecimalPlacesFromStrings(minAndMaxStrings);
    return decimalPlaces;
}

From source file:uk.ac.ebi.phenotype.web.controller.BaselineChartsController.java

License:Apache License

private String generateBaselineChartBarStyle(String parameterStableId,
        List<FieldStatsInfo> baselinesForParameter) throws SolrServerException, IOException {
    ParameterDTO parameter = impressService.getParameterByStableId(parameterStableId);
    //String procedureName = parameter.getProcedures().iterator().next().getName();
    System.out.println("procedure names=" + parameter.getProcedureNames());

    String yAxisTitle = parameter.getUnitX();
    List<String> xAxisLabels = new ArrayList();

    List<String> means = new ArrayList();
    for (FieldStatsInfo baseLine : baselinesForParameter) {
        xAxisLabels.add("'" + baseLine.getName() + "'");
        means.add(baseLine.getMean().toString());
        System.out.println(baseLine.getMin() + " " + baseLine.getMax() + " " + baseLine.getMean());
    }//from  w  w  w . jav  a  2 s  .c  o m
    //[-9.7, 9.4],
    int decimalPlaces = ChartUtils.getDecimalPlacesFromStrings(means);
    System.out.println("decimalPlaces=" + decimalPlaces);
    List<Float> meanFloats = getDecimalAdjustedValues(means, decimalPlaces);

    List<String> minAndMax = new ArrayList<>();
    for (FieldStatsInfo baseLine : baselinesForParameter) {
        minAndMax.add(
                "[" + ChartUtils.getDecimalAdjustedFloat(new Float(baseLine.getMin().toString()), decimalPlaces)
                        + "," + new Float(baseLine.getMax().toString()) + "]");
    }
    String minAndMaxData = StringUtils.join(minAndMax, ",");
    System.out.println("minAndMaxData=" + minAndMaxData);
    System.out.println("means=" + means);
    List<String> colors = ChartColors.getHighDifferenceColorsRgba(ChartColors.alphaOpaque);
    String chartString = "$('#baseline-chart-div').highcharts({" + " colors:" + colors + ", " +

            " chart: {  " + " type: 'columnrange',  inverted: false },  title: { text: '" + parameter.getName()
            + " WT Variation By Center' }, subtitle: {  text: '" + parameter.getProcedureNames().get(0) + "' },"
            + " plotOptions: {   series: {  states: { hover: { enabled: false  }   }  } }," + "  xAxis: {"
            + " categories: " + xAxisLabels + "}," + "  yAxis: {" + " title: { text: '" + yAxisTitle + "' }"
            + "  }," + "  tooltip: {" + "  valueSuffix: '" + yAxisTitle + "' }," + "  plotOptions: {"
            + " columnrange: { " + "dataLabels: {"
            + "  enabled: false,   formatter: function () { return this.y + '" + yAxisTitle + "'; }" + "   }"
            + "  }" + "}, legend: { enabled: false  }, tooltip: { enabled: false }," + " series: "
            + "[ {  name: '" + parameter.getName() + yAxisTitle + "',  data: [  " + minAndMaxData + " ] },"
            + " {  type: 'scatter', name: 'Observations', data: " + meanFloats + ", marker: { radius: 4 } }]"
            + "  });";

    System.out.println("chartString=" + chartString);
    return chartString;

}