List of usage examples for org.apache.commons.lang.time DateUtils round
public static Date round(Object date, int field)
Round this date, leaving the field specified as the most significant field.
For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if this was passed with HOUR, it would return 28 Mar 2002 14:00:00.000.
From source file:org.sonatype.nexus.integrationtests.nexus810.Nexus810PackageNamesInNexusConfIT.java
@Test public void checkNexusConfForPackageNames() throws Exception { // create a task ScheduledServiceAdvancedResource scheduledTask = new ScheduledServiceAdvancedResource(); scheduledTask.setEnabled(true);/*from w w w . j a va2 s.co m*/ scheduledTask.setId(null); scheduledTask.setName("taskAdvanced"); scheduledTask.setSchedule("advanced"); // A future date Date startDate = DateUtils.addDays(new Date(), 10); startDate = DateUtils.round(startDate, Calendar.DAY_OF_MONTH); scheduledTask.setCronCommand("0 0 12 ? * WED"); scheduledTask.setTypeId(UpdateIndexTaskDescriptor.ID); ScheduledServicePropertyResource prop = new ScheduledServicePropertyResource(); prop.setKey("repositoryId"); prop.setValue("all_repo"); scheduledTask.addProperty(prop); Assert.assertTrue("Expected task to be created: ", TaskScheduleUtil.create(scheduledTask).isSuccess()); // now check the conf List<CScheduledTask> tasks = getNexusConfigUtil().getNexusConfig().getTasks(); Assert.assertTrue("Expected at least 1 task in nexus.xml", tasks.size() > 0); for (CScheduledTask task : tasks) { Assert.assertFalse("Found package name in nexus.xml for task type: " + task.getType(), task.getType().contains("org.sonatype.")); } }
From source file:ubic.gemma.analysis.preprocess.svd.SVDServiceHelperImpl.java
/** * Do the factor comparisons for one component. * /* ww w . j a v a2 s .co m*/ * @param svo * @param componentNumber * @param vMatrix * @param bioMaterialDates * @param bioMaterialFactorMap Map of factors to biomaterials to the value we're going to use. Even for * non-continuous factors the value is a double. * @param svdBioMaterials */ private void analyzeComponent(SVDValueObject svo, int componentNumber, DoubleMatrix<Long, Integer> vMatrix, Map<Long, Date> bioMaterialDates, Map<ExperimentalFactor, Map<Long, Double>> bioMaterialFactorMap, Long[] svdBioMaterials) { DoubleArrayList eigenGene = new DoubleArrayList(vMatrix.getColumn(componentNumber)); // since we use rank correlation/anova, we just use the casted ids (two-groups) or dates as the covariate int numWithDates = 0; for (Long id : bioMaterialDates.keySet()) { if (bioMaterialDates.get(id) != null) { numWithDates++; } } if (numWithDates > 2) { /* * Get the dates in order, rounded to the nearest hour. */ boolean initializingDates = svo.getDates().isEmpty(); double[] dates = new double[svdBioMaterials.length]; for (int j = 0; j < svdBioMaterials.length; j++) { Date date = bioMaterialDates.get(svdBioMaterials[j]); if (date == null) { log.warn("Incomplete date information, missing for biomaterial " + svdBioMaterials[j]); dates[j] = Double.NaN; } else { dates[j] = DateUtils.round(date, Calendar.MINUTE).getTime(); // make int, cast to double } if (initializingDates) svo.getDates().add(date); } initializingDates = false; if (eigenGene.size() != dates.length) { log.warn("Could not compute correlation, dates and eigenGene had different lengths."); return; } double dateCorrelation = Distance.spearmanRankCorrelation(eigenGene, new DoubleArrayList(dates)); svo.setPCDateCorrelation(componentNumber, dateCorrelation); svo.setPCDateCorrelationPval(componentNumber, CorrelationStats.spearmanPvalue(dateCorrelation, eigenGene.size())); } /* * Compare each factor (including batch information that is somewhat redundant with the dates) to the * eigengenes. Using rank statistics. */ for (ExperimentalFactor ef : bioMaterialFactorMap.keySet()) { Map<Long, Double> bmToFv = bioMaterialFactorMap.get(ef); double[] fvs = new double[svdBioMaterials.length]; assert fvs.length > 0; int numNotMissing = 0; boolean initializing = false; if (!svo.getFactors().containsKey(ef.getId())) { svo.getFactors().put(ef.getId(), new ArrayList<Double>()); initializing = true; } for (int j = 0; j < svdBioMaterials.length; j++) { fvs[j] = bmToFv.get(svdBioMaterials[j]).doubleValue(); if (!Double.isNaN(fvs[j])) { numNotMissing++; } // note that this is a double. In the case of categorical factors, it's the Doubleified ID of the factor // value. if (initializing) { if (log.isDebugEnabled()) log.debug("EF:" + ef.getId() + " fv=" + bmToFv.get(svdBioMaterials[j])); svo.getFactors().get(ef.getId()).add(bmToFv.get(svdBioMaterials[j])); } } if (fvs.length != eigenGene.size()) { log.debug(fvs.length + " factor values (biomaterials) but " + eigenGene.size() + " values in the eigengene"); continue; } initializing = false; if (numNotMissing < MINIMUM_POINTS_TO_COMARE_TO_EIGENGENE) { log.debug("Insufficient values to compare " + ef + " to eigengenes"); continue; } if (ExperimentalDesignUtils.isContinuous(ef)) { double factorCorrelation = Distance.spearmanRankCorrelation(eigenGene, new DoubleArrayList(fvs)); svo.setPCFactorCorrelation(componentNumber, ef, factorCorrelation); // FIXME might need to deal with missing values here too. svo.setPCFactorCorrelationPval(componentNumber, ef, CorrelationStats.spearmanPvalue(factorCorrelation, eigenGene.size())); } else { Collection<Integer> groups = new HashSet<Integer>(); IntArrayList groupings = new IntArrayList(fvs.length); int k = 0; DoubleArrayList eigenGeneWithoutMissing = new DoubleArrayList(); for (double d : fvs) { if (Double.isNaN(d)) { k++; continue; } groupings.add((int) d); groups.add((int) d); eigenGeneWithoutMissing.add(eigenGene.get(k)); k++; } if (groups.size() < 2) { log.debug("Factor had less than two groups: " + ef + ", SVD comparison can't be done."); continue; } if (eigenGeneWithoutMissing.size() < MINIMUM_POINTS_TO_COMARE_TO_EIGENGENE) { log.debug("Too few non-missing values for factor to compare to eigengenes: " + ef); continue; } if (groups.size() == 2) { // use the one that still has missing values. double factorCorrelation = Distance.spearmanRankCorrelation(eigenGene, new DoubleArrayList(fvs)); svo.setPCFactorCorrelation(componentNumber, ef, factorCorrelation); svo.setPCFactorCorrelationPval(componentNumber, ef, CorrelationStats.spearmanPvalue(factorCorrelation, eigenGeneWithoutMissing.size())); } else { // one-way ANOVA on ranks. double kwpval = KruskalWallis.test(eigenGeneWithoutMissing, groupings); svo.setPCFactorCorrelationPval(componentNumber, ef, kwpval); double factorCorrelation = Distance.spearmanRankCorrelation(eigenGene, new DoubleArrayList(fvs)); double corrPvalue = CorrelationStats.spearmanPvalue(factorCorrelation, eigenGeneWithoutMissing.size()); assert Math.abs(factorCorrelation) < 1.0 + 1e-2; // sanity. /* * Avoid storing a pvalue, as it's hard to compare. If the regular linear correlation is strong, * then we should just use that -- basically, it means the order we have the groups happens to be a * good one. Of course we could just store pvalues, but that's not easy to use either. */ if (corrPvalue <= kwpval) { svo.setPCFactorCorrelation(componentNumber, ef, factorCorrelation); } else { // hack. A bit like turning pvalues into probit double approxCorr = CorrelationStats.correlationForPvalue(kwpval, eigenGeneWithoutMissing.size()); svo.setPCFactorCorrelation(componentNumber, ef, approxCorr); } } } } }
From source file:uk.ac.ebi.metabolights.repository.dao.hibernate.StudyDAO.java
public List<String> getStudiesToGoLiveList(String userToken, int numberOfDays) throws DAOException { // Hibernate left join: // from Cat as cat left join cat.mate.kittens as kittens // https://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html/ch16.html#queryhql-joins String query = "select study.acc from " + StudyData.class.getSimpleName() + " study" + " left join study.users user"; // is the user a curator? boolean isCurator = usersDAO.hasUserThisRole(AppRole.ROLE_SUPER_USER, userToken); // Query to check date... StudyData study = new StudyData(); // Calculate the date limits Date todayMidNight = DateUtils.round(new Date(), Calendar.DAY_OF_MONTH); // 0 will get all studies until today Date lLimit = null;/*from ww w . j av a 2 s. co m*/ if (numberOfDays != 0) { lLimit = DateUtils.addDays(todayMidNight, numberOfDays); } else { lLimit = DateUtils.addDays(todayMidNight, -3000); } Date uLimit = DateUtils.addDays(todayMidNight, numberOfDays + 1); query = query + " where (study.releaseDate <:ulimit and study.releaseDate >=:llimit and study.status= " + Study.StudyStatus.INREVIEW.ordinal() + ")"; // Create an empty filter Filter filter = new Filter(); // Add the date filter. filter.fieldValuePairs.put("ulimit", uLimit); filter.fieldValuePairs.put("llimit", lLimit); // If not... if (!isCurator) { query = query + " AND (user.apiToken=:apiToken) "; // Add clause to where.. filter.fieldValuePairs.put("apiToken", userToken); } List<String> studies = this.getList(query, filter); return studies; }