本文整理汇总了Java中org.apache.commons.math3.util.Precision.round方法的典型用法代码示例。如果您正苦于以下问题:Java Precision.round方法的具体用法?Java Precision.round怎么用?Java Precision.round使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.util.Precision
的用法示例。
在下文中一共展示了Precision.round方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRoundedValue
import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
/**
* Rounds a value. If the given parameters has skip rounding, the value is
* returned unchanged. If the given number of decimals is specified, the
* value is rounded to the given decimals. If skip rounding is specified
* in the given data query parameters, 10 decimals is used. Otherwise,
* default rounding is used.
*
* @param params the query parameters.
* @param decimals the number of decimals.
* @param value the value.
* @return a double.
*/
public static Double getRoundedValue( DataQueryParams params, Integer decimals, Double value )
{
if ( value == null )
{
return value;
}
else if ( params.isSkipRounding() )
{
return Precision.round( value, DECIMALS_NO_ROUNDING );
}
else if ( decimals != null && decimals > 0 )
{
return Precision.round( value, decimals );
}
else
{
return MathUtils.getRounded( value );
}
}
示例2: printResults
import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
private void printResults(Map<String, Map<String, Sig>> sampleSigs, Map<String, Integer> geneSigs) {
int j = 0;
for (Map.Entry<String, Map<String, Sig>> entry : sampleSigs.entrySet()) {
String sample = entry.getKey();
int samplesNumber = sampleSigs.size();
for (Map.Entry<String, Sig> sigs : entry.getValue().entrySet()) {
String gene = sigs.getKey();
Sig sig = sigs.getValue();
Locus locus = genes.get(gene);
StringBuilder locStr = new StringBuilder();
locStr.append(sample).append("\t").append(gene).append("\t").append(locus.getName()).append("\t").append(Precision.round(sig.getLrMed(), 3)).append("\t");
if (sig.getSig() != -1) {
double bpPercent = 0.0;
int bpNumber = 0;
if (sig.getBp().equals("BP")) {
String key = (gene + " " + sig.getSigseg()).intern();
bpNumber = geneSigs.get(key);
bpPercent = Precision.round(bpNumber/(double)samplesNumber, 3);
}
if (Double.compare(bpPercent, 0.0) != 0 && Double.compare(bpPercent, MAXRATE) > 0
&& bpNumber > MAXCNT) {
locStr.append("\t\t\t\t\t").append(sig.getTotal());
} else {
locStr.append(sig.getName().append("\t").append(bpNumber).append("\t").append(bpPercent));
}
} else {
locStr.append("\t\t\t\t").append(sig.getTotal());
}
if (j == 0)
System.out.println("Sample\tGene\tChr\tStart\tEnd\tLength\tLog2ratio\tSig\tBP_Whole\tAmp_Del\tAb_Seg\tTotal_Seg\tAb_log2ratio\tLog2r_Diff\tAb_Seg_Loc\tAb_Samples\tAb_Samples_Pcnt");
j++;
System.out.println(locStr);
}
}
}
示例3: readCoverageAndGetMedDepth
import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
/**
* Read samples from coverage file, put them in map, calculates median depth and fill in map {@link Cov2lr#geneStatistics}
* @param samp set of sample names from coverage file; empty
* @return median depth
*/
//perl version: 63 str
double readCoverageAndGetMedDepth(Set<String> samp) {
List<Double> depth = new ArrayList<>();
CloseableIterator<Sample> iterator = getFileDataIterator();
while (iterator.hasNext()) {
Sample sample = iterator.next();
double norm1 = Precision.round((sample.getCov() * factor.get(sample.getSample())), 2);
depth.add(norm1);
samp.add(sample.getSample());
putInMap(sample, norm1); //perl version: 68 str
}
iterator.close();
return median.evaluate(toDoubleArray(depth));
}
示例4: getRoundedValueObject
import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
/**
* Rounds a value. If the given parameters has skip rounding, the value is
* returned unchanged. If the given number is null or not of class Double,
* the value is returned unchanged. If skip rounding is specified in the
* given data query parameters, 10 decimals is used. Otherwise, default
* rounding is used.
*
* @param params the query parameters.
* @param value the value.
* @return a value.
*/
public static Object getRoundedValueObject( DataQueryParams params, Object value )
{
if ( value == null || !Double.class.equals( value.getClass() ) )
{
return value;
}
else if ( params.isSkipRounding() )
{
return Precision.round( (Double) value, DECIMALS_NO_ROUNDING );
}
return MathUtils.getRounded( (Double) value );
}
示例5: roundSignificant
import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
/**
* Rounds a number, keeping at least 3 significant digits.
* <p>
* <ul>
* <li>If value is >= 10 or <= -10 it will have 1 decimal.</li>
* <li>If value is between -10 and 10 it will have three significant digits.</li>
* </ul>
*
* @param value the value to round off.
* @return a rounded off number.
*/
public static double roundSignificant( double value )
{
if ( value >= 10.0 || value <= -10.0 )
{
return Precision.round( value, 1 );
}
else
{
return roundToSignificantDigits( value, 3 );
}
}
示例6: getNextRandomValue
import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
@Override
public Double getNextRandomValue() {
double range = max - min;
double scaled = rand.nextDouble() * range;
double shifted = scaled + min;
return Precision.round(shifted, decimalPlaces);
}
示例7: getRoundedGrade
import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
public static String getRoundedGrade(Double theGrade, Double points) throws Exception {
if ( theGrade < 0.0 || theGrade > 1.0 ) {
throw new Exception("Grade out of range");
}
theGrade = theGrade * points;
theGrade = Precision.round(theGrade,2);
return String.valueOf(theGrade);
}
示例8: getPointsDisplayString
import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
/**
* If we display the score, return it, followed by a slash.
*
* @return either, a) the score followed by a slash, or, b) "" (empty
* string)
*/
public String getPointsDisplayString() {
String pointsDisplayString = "";
if (showStudentQuestionScore) {
pointsDisplayString = Precision.round(points, 2) + "/";
}
return pointsDisplayString;
}
示例9: getPointsDisplayString
import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
/**
* If we display the score, return it, followed by a slash.
* @return either, a) the score followed by a slash, or, b) "" (empty string)
*/
public String getPointsDisplayString()
{
String pointsDisplayString = "";
if (showStudentQuestionScore)
{
pointsDisplayString = Precision.round(points, 2) + "/";
}
return pointsDisplayString;
}
示例10: getPointsDisplayString
import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
/**
* If we display the current score, return it, otherwise an empty string.
* Not currently used, provided if we need it later.
* @return either, a) the current score, otherwise, b) "" (empty string)
*/
public String getPointsDisplayString()
{
String pointsDisplayString = "";
if (showStudentScore)
{
pointsDisplayString = "" + Precision.round(currentScore, 2);
}
return pointsDisplayString;
}
示例11: fromNanoTime
import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
private static String fromNanoTime(double nanoTime)
{
if (nanoTime > 1000000d) {
return Precision.round(nanoTime/1000000d, PRECISION) + " millis";
} else if (nanoTime > 1000d) {
return Precision.round(nanoTime/1000d, PRECISION) + " micros";
} else {
return Precision.round(nanoTime, PRECISION) + " nanos";
}
}
示例12: getHistory
import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
@Override
public DataElementHistory getHistory( DataElement dataElement, DataElementCategoryOptionCombo optionCombo,
DataElementCategoryOptionCombo attributeOptionCombo, OrganisationUnit organisationUnit, Period lastPeriod, int historyLength )
{
if ( !dataElement.getValueType().isNumeric() )
{
return null; // TODO
}
// ---------------------------------------------------------------------
// Initialise history
// ---------------------------------------------------------------------
DataElementHistory history = new DataElementHistory();
history.setDataElement( dataElement );
history.setOptionCombo( optionCombo );
history.setAttributeOptionComboOptionCombo( attributeOptionCombo );
history.setOrganisationUnit( organisationUnit );
history.setHistoryLength( historyLength );
addMinMaxLimits( organisationUnit, dataElement, optionCombo, history );
// ---------------------------------------------------------------------
// Create history points
// ---------------------------------------------------------------------
List<Period> periods = periodService.getPeriods( lastPeriod, historyLength );
double max = 1;
double average = 0;
double total = 0;
int count = 0;
if ( history.getMaxLimit() != null )
{
max = Math.max( max, history.getMaxLimit() );
}
for ( Period period : periods )
{
DataElementHistoryPoint historyPoint = new DataElementHistoryPoint();
historyPoint.setPeriod( period );
Double value = getValue( dataElement, optionCombo, attributeOptionCombo, organisationUnit, period );
if ( value != null )
{
historyPoint.setValue( value );
}
if ( historyPoint.getValue() != null )
{
max = Math.max( max, historyPoint.getValue() );
total += historyPoint.getValue();
average = total / ++count;
average = Precision.round( average, 1 );
}
historyPoint.setAverage( average );
history.getHistoryPoints().add( historyPoint );
}
history.setMaxHistoryValue( max );
double maxValue = getMaxValue( history );
if ( !MathUtils.equals( maxValue, Double.NEGATIVE_INFINITY ) )
{
history.setMaxValue( maxValue );
double minValue = getMinValue( history );
history.setMinValue( minValue );
}
return history;
}
示例13: getHistory
import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
@Override
public DataElementHistory getHistory( DataElement dataElement, DataElementCategoryOptionCombo optionCombo,
OrganisationUnit organisationUnit, Period lastPeriod, int historyLength )
{
if ( !dataElement.getValueType().isNumeric() )
{
return null; // TODO
}
// ---------------------------------------------------------------------
// Initialise history
// ---------------------------------------------------------------------
DataElementHistory history = new DataElementHistory();
history.setDataElement( dataElement );
history.setOptionCombo( optionCombo );
history.setOrganisationUnit( organisationUnit );
history.setHistoryLength( historyLength );
addMinMaxLimits( organisationUnit, dataElement, optionCombo, history );
// ---------------------------------------------------------------------
// Create history points
// ---------------------------------------------------------------------
List<Period> periods = periodService.getPeriods( lastPeriod, historyLength );
double max = 1;
double average = 0;
double total = 0;
int count = 0;
if ( history.getMaxLimit() != null )
{
max = Math.max( max, history.getMaxLimit() );
}
for ( Period period : periods )
{
DataElementHistoryPoint historyPoint = new DataElementHistoryPoint();
historyPoint.setPeriod( period );
Double value = getValue( dataElement, optionCombo, organisationUnit, period );
if ( value != null )
{
historyPoint.setValue( value );
}
if ( historyPoint.getValue() != null )
{
max = Math.max( max, historyPoint.getValue() );
total += historyPoint.getValue();
average = total / ++count;
average = Precision.round( average, 1 );
}
historyPoint.setAverage( average );
history.getHistoryPoints().add( historyPoint );
}
history.setMaxHistoryValue( max );
double maxValue = getMaxValue( history );
if ( !MathUtils.equals( maxValue, Double.NEGATIVE_INFINITY ) )
{
history.setMaxValue( maxValue );
double minValue = getMinValue( history );
history.setMinValue( minValue );
}
return history;
}
示例14: updateExternalAssessmentScore
import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
/**
* Update the grading of the assessment.
* @param ag the assessment grading.
* @param g the Gradebook Service
* @throws java.lang.Exception
*/
public void updateExternalAssessmentScore(AssessmentGradingData ag,
GradebookExternalAssessmentService g) throws
Exception
{
boolean testErrorHandling=false;
PublishedAssessmentService pubService = new PublishedAssessmentService();
GradingService gradingService = new GradingService();
//Following line seems just for the need of getting publishedAssessmentId
//use ag.getPublishedAssessmentId() instead of pub.getPublishedAssessmentId() to
//get publishedAssessmentId
//comment out following 3 lines since it returns null for not submitted students which we
//need not save to assessmentgrading table but will need to notify gradebook only
/* PublishedAssessmentIfc pub = (PublishedAssessmentIfc) gradingService.getPublishedAssessmentByAssessmentGradingId(ag.getAssessmentGradingId().toString());
String gradebookUId = pubService.getPublishedAssessmentOwner(
pub.getPublishedAssessmentId());*/
String gradebookUId = pubService.getPublishedAssessmentOwner(
ag.getPublishedAssessmentId());
if (gradebookUId == null)
{
return;
}
//Will pass to null value when last submission is deleted
String points = null;
if(ag.getFinalScore() != null) {
//SAM-1562 We need to round the double score and covert to a double -DH
double fScore = Precision.round(ag.getFinalScore(), 2);
Double score = Double.valueOf(fScore).doubleValue();
points = score.toString();
log.info("rounded: " + ag.getFinalScore() + " to: " + score.toString() );
}
g.updateExternalAssessmentScore(gradebookUId,
ag.getPublishedAssessmentId().toString(),
ag.getAgentId(), points);
if (testErrorHandling){
throw new Exception("Encountered an error in update ExternalAssessmentScore.");
}
}
示例15: getUpdatedScore
import org.apache.commons.math3.util.Precision; //导入方法依赖的package包/类
public Double getUpdatedScore () {
if (itemData.getScore() == null)
return 0.0;
else
return Precision.round(itemData.getScore(), 2);
}