List of usage examples for org.joda.time DateTime getHourOfDay
public int getHourOfDay()
From source file:eu.itesla_project.cases.EntsoeCaseRepository.java
License:Mozilla Public License
private <R> R scanRepository(DateTime date, CaseType type, Country country, Function<List<ImportContext>, R> handler) { Collection<UcteGeographicalCode> geographicalCodes = country != null ? forCountryHacked(country) : Collections.singleton(UcteGeographicalCode.UX); for (EntsoeFormat format : formats) { Path formatDir = config.getRootDir().resolve(format.getDirName()); if (Files.exists(formatDir)) { Path typeDir = formatDir.resolve(type.name()); if (Files.exists(typeDir)) { Path dayDir = typeDir.resolve(String.format("%04d", date.getYear())) .resolve(String.format("%02d", date.getMonthOfYear())) .resolve(String.format("%02d", date.getDayOfMonth())); if (Files.exists(dayDir)) { List<ImportContext> importContexts = null; for (UcteGeographicalCode geographicalCode : geographicalCodes) { Collection<String> forbiddenFormats = config.getForbiddenFormatsByGeographicalCode() .get(geographicalCode); if (!forbiddenFormats.contains(format.getImporter().getFormat())) { for (int i = 9; i >= 0; i--) { String baseName = String.format( "%04d%02d%02d_%02d%02d_" + type + "%01d_" + geographicalCode.name() + "%01d", date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(), date.getMinuteOfHour(), date.getDayOfWeek(), i); ReadOnlyDataSource ds = dataSourceFactory.create(dayDir, baseName); if (importContexts == null) { importContexts = new ArrayList<>(); }/*from w ww . j av a2 s . c o m*/ if (format.getImporter().exists(ds)) { importContexts.add(new ImportContext(format.getImporter(), ds)); } } } } if (importContexts != null) { R result = handler.apply(importContexts); if (result != null) { return result; } } } } } } return null; }
From source file:eu.itesla_project.entsoe.cases.EntsoeCaseRepository.java
License:Mozilla Public License
private <R> R scanRepository(DateTime date, CaseType type, Country country, Function<List<ImportContext>, R> handler) { Collection<EntsoeGeographicalCode> geographicalCodes = country != null ? forCountryHacked(country) : Collections.singleton(EntsoeGeographicalCode.UX); for (EntsoeFormat format : formats) { Path formatDir = config.getRootDir().resolve(format.getDirName()); if (Files.exists(formatDir)) { Path typeDir = formatDir.resolve(type.name()); if (Files.exists(typeDir)) { Path dayDir = typeDir.resolve(String.format("%04d", date.getYear())) .resolve(String.format("%02d", date.getMonthOfYear())) .resolve(String.format("%02d", date.getDayOfMonth())); if (Files.exists(dayDir)) { List<ImportContext> importContexts = null; for (EntsoeGeographicalCode geographicalCode : geographicalCodes) { Collection<String> forbiddenFormats = config.getForbiddenFormatsByGeographicalCode() .get(geographicalCode); if (!forbiddenFormats.contains(format.getImporter().getFormat())) { for (int i = 9; i >= 0; i--) { String baseName = String.format( "%04d%02d%02d_%02d%02d_" + type + "%01d_" + geographicalCode.name() + "%01d", date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), date.getHourOfDay(), date.getMinuteOfHour(), date.getDayOfWeek(), i); ReadOnlyDataSource ds = dataSourceFactory.create(dayDir, baseName); if (importContexts == null) { importContexts = new ArrayList<>(); }/* w w w .j av a2s. com*/ if (format.getImporter().exists(ds)) { importContexts.add(new ImportContext(format.getImporter(), ds)); } } } } if (importContexts != null) { R result = handler.apply(importContexts); if (result != null) { return result; } } } } } } return null; }
From source file:eu.uqasar.web.dashboard.widget.datadeviation.DataDeviationWidget.java
License:Apache License
public Options getQualityParameterOptions() { Project proj = null;//from www .j av a2s . c om String projName = ""; String qualityParameterChoice = ""; proj = getProject(settings.get("project")); if (proj != null) { projName = proj.getName(); System.out.println("projName: " + projName); } qualityParameterChoice = settings.get("qualityParams"); // if (qualityParameterChoice == null || qualityParameterChoice.isEmpty()) { // qualityParameterChoice = OBJS; // } System.out.println("qualityParameterChoice: " + qualityParameterChoice); Options options = new Options(); ChartOptions chartOptions = new ChartOptions(); // DATA List<HistoricValuesBaseIndicator> historicValues = getHistoricalValues(); List<HistoricValuesBaseIndicator> qualityParam = new LinkedList<>(); List<Float> baseIndicatorValues = new LinkedList<>(); // get and save parameter values for (HistoricValuesBaseIndicator hv : historicValues) { if (hv.getBaseIndicator().getName().equals(qualityParameterChoice)) { qualityParam.add(hv); baseIndicatorValues.add(hv.getBaseIndicator().getValue()); } } // calculate deviations // test: overwrite values // baseIndicatorValues.set(0, 40087.0f); // baseIndicatorValues.set(1, 39457.0f); // baseIndicatorValues.set(2, 41347.0f); // baseIndicatorValues.set(3, 44777.0f); System.out.println("baseIndicatorValues: " + baseIndicatorValues); List<Float> deviations = calculateDeviations(baseIndicatorValues); System.out.println("deviations: " + deviations); SeriesType seriesType = SeriesType.SPLINE; chartOptions.setType(seriesType); chartTitle = new Title("Deviations of " + qualityParameterChoice); options.setTitle(chartTitle); PointSeries series = new PointSeries(); series.setType(seriesType); List<String> xAxisLabels = new ArrayList<>(); for (int f = 0; f < deviations.size(); f++) { String name = qualityParam.get(f).getBaseIndicator().getName(); float value = deviations.get(f); series.addPoint(new Point(name, value)); //xAxis Label DateTime dateTime = new DateTime(qualityParam.get(f).getDate()); String dateFormated = String.valueOf(dateTime.getMonthOfYear()) + "/" + String.valueOf(dateTime.dayOfMonth().get()) + "/" + String.valueOf(dateTime.getYear()) + " - " + String.valueOf(dateTime.getHourOfDay()) + ":" + String.valueOf(dateTime.getMinuteOfHour()); xAxisLabels.add(dateFormated); } // Date on xAxis Axis xAxis = new Axis(); xAxis.setType(AxisType.DATETIME); xAxis.setCategories(xAxisLabels); xAxis.setLabels(new Labels().setRotation(-60).setAlign(HorizontalAlignment.RIGHT).setStyle( new CssStyle().setProperty("font-size", "10px").setProperty("font-family", "Verdana, sans-serif"))); options.setxAxis(xAxis); options.addSeries(series); options.setChartOptions(chartOptions); return options; }
From source file:eu.uqasar.web.dashboard.widget.uqasardatavisualization.UqasarDataVisualizationWidget.java
License:Apache License
public Options getQualityParameterOptions() { Project proj = null;/* w w w. j a v a 2 s . c o m*/ String projName = ""; Map<String, List<TreeNode>> qualityParameters = new HashMap<>(); String qualityParameterChoice = ""; proj = getProject(settings.get("project")); if (proj != null) { projName = proj.getName(); } qualityParameterChoice = settings.get("qualityParams"); if (qualityParameterChoice == null || qualityParameterChoice.isEmpty()) { qualityParameterChoice = ALL.get(0); // all params } System.out.println("qualityParameterChoice: " + qualityParameterChoice); Options options = new Options(); ChartOptions chartOptions = new ChartOptions(); if (qualityParameterChoice.equals(ALL.get(0))) { // DATA qualityParameters = getQualityParametersFromProject(proj); SeriesType seriesType = SeriesType.COLUMN; // CHART chartOptions.setType(seriesType); chartTitle = new Title(ALL.get(0) + " of " + projName); options.setTitle(chartTitle); for (String key : qualityParameters.keySet()) { PointSeries series = new PointSeries(); series.setType(seriesType); int siz = qualityParameters.get(key).size(); series.addPoint(new Point(key, siz)); series.setName(key); options.addSeries(series); } options.setChartOptions(chartOptions); } else { // DATA List<HistoricValuesBaseIndicator> HistoricValuesBaseIndicator = getHistoricalValues(); List<HistoricValuesBaseIndicator> data = new LinkedList<>(); for (HistoricValuesBaseIndicator hv : HistoricValuesBaseIndicator) { if (hv.getBaseIndicator().getName().equals(qualityParameterChoice)) { data.add(hv); } } SeriesType seriesType = SeriesType.SPLINE; chartOptions.setType(seriesType); chartTitle = new Title(qualityParameterChoice + " of " + projName); options.setTitle(chartTitle); PointSeries series = new PointSeries(); series.setType(seriesType); List<String> xAxisLabels = new ArrayList<>(); for (HistoricValuesBaseIndicator dat : data) { String name = dat.getBaseIndicator().getName(); float value = dat.getBaseIndicator().getValue(); series.addPoint(new Point(name, value)); //xAxis Label //xAxis Label DateTime dateTime = new DateTime(dat.getDate()); String dateFormated = String.valueOf(dateTime.getMonthOfYear()) + "/" + String.valueOf(dateTime.dayOfMonth().get()) + "/" + String.valueOf(dateTime.getYear()) + " - " + String.valueOf(dateTime.getHourOfDay()) + ":" + String.valueOf(dateTime.getMinuteOfHour()); xAxisLabels.add(dateFormated); } // Date on xAxis Axis xAxis = new Axis(); xAxis.setType(AxisType.DATETIME); xAxis.setCategories(xAxisLabels); xAxis.setLabels( new Labels().setRotation(-60).setAlign(HorizontalAlignment.RIGHT).setStyle(new CssStyle() .setProperty("font-size", "10px").setProperty("font-family", "Verdana, sans-serif"))); options.setxAxis(xAxis); options.addSeries(series); options.setChartOptions(chartOptions); } return options; }
From source file:external.ExchangeRatesUpdateActor.java
License:Open Source License
static void doIt() { DateTime dt = new DateTime(); if (isSuccess != null && (dt.getHourOfDay() < 7 || dt.getHourOfDay() > 20 || Settings.getGlobal().exchangePeriod.equals(ExchangeRatePeriod.Manual))) { log.debug("There is no exchange support!"); return;//from www.java2s . c o m } ExchangeRateSource exchangeSource = Settings.getGlobal().exchangeSource; ExchangeRatePeriod exchangePeriod = Settings.getGlobal().exchangePeriod; log.info("Exchange rate source and refresh period -> [" + exchangeSource + ", " + exchangePeriod + "]"); boolean isSuitable = false; switch (exchangePeriod) { case Hourly: { isSuitable = true; break; } case Every_3_Hours: { isSuitable = (dt.getHourOfDay() % 3 == 0 || isSuccess == null); break; } case Once_A_Day: { isSuitable = (dt.getHourOfDay() == 16 || isSuccess == null); break; } } if (isSuccess != null && !isSuccess) isSuitable = true; if (isSuitable) { log.info("Exchange refresher was triggered : " + DateUtils.formatDate(new Date(), "yyyy-MM-dd hh:mm:ss")); isSuccess = false; try { switch (exchangeSource) { case TCMB_Exchange: { CurrencyRates.pullTCMBExcange(); isSuccess = true; break; } case TCMB_Effective: { CurrencyRates.pullTCMBEffective(); isSuccess = true; break; } } } catch (Exception e) { log.error("ERROR", e); } } }
From source file:fr.amap.commons.animation.Timeline.java
public static double getDecimalHour(DateTime time) { return getDecimalHour(time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute()); }
From source file:fr.ybonnel.model.ScoreWithHistory.java
License:Apache License
private void aggregateOneTypeOfScore(DateTime now, Iterator<Score> itScores) { Set<String> hoursKept = new HashSet<>(); while (itScores.hasNext()) { Score score = itScores.next();/* ww w . j a v a2s.c om*/ DateTime dateTimeOfScore = new DateTime(score.getTimeOfScore()); String hourOfScore = dateTimeOfScore.toString("yyyyMMddHH"); String hoursForPast1Day = dateTimeOfScore.withHourOfDay((dateTimeOfScore.getHourOfDay() / 4) * 4) .toString("yyyyMMddHH"); if (dateTimeOfScore.compareTo(now.minusHours(2)) < 0 && hoursKept.contains(hourOfScore) || dateTimeOfScore.compareTo(now.minusDays(1)) < 0 && hoursKept.contains(hoursForPast1Day)) { itScores.remove(); } else { hoursKept.add(hourOfScore); hoursKept.add(hoursForPast1Day); } } }
From source file:gov.usgs.anss.query.filefactory.SacHeaders.java
License:Open Source License
public static SacTimeSeries setEventHeader(SacTimeSeries sac, DateTime eventOrigin, Double eventLat, Double eventLon, Double eventDepth, Double eventMag, int sacMagType, int sacEventType) { if (eventLat == null) { eventLat = -12345.0;//from www . j ava 2 s .c om } if (eventLon == null) { eventLon = -12345.0; } if (eventDepth == null) { eventDepth = -12345.0; } if (eventMag == null) { eventMag = -12345.0; } // SAC stores year day (nzjday) but not month and day. DateTime start = new DateTime(sac.nzyear, 1, 1, sac.nzhour, sac.nzmin, sac.nzsec, sac.nzmsec, DateTimeZone.UTC); start = start.withDayOfYear(sac.nzjday); double timeDiff = (start.getMillis() - eventOrigin.getMillis()) / 1000.0d; sac.nzyear = eventOrigin.getYear(); sac.nzjday = eventOrigin.getDayOfYear(); sac.nzhour = eventOrigin.getHourOfDay(); sac.nzmin = eventOrigin.getMinuteOfHour(); sac.nzsec = eventOrigin.getSecondOfMinute(); sac.nzmsec = eventOrigin.getMillisOfSecond(); sac.b = sac.b + timeDiff; sac.e = sac.e + timeDiff; sac.iztype = SacTimeSeries.IO; sac.evla = eventLat; sac.evlo = eventLon; sac.evdp = eventDepth; sac.mag = eventMag; sac.imagtyp = sacMagType; sac.ievtyp = sacEventType; sac.lcalda = 1; return sac; }
From source file:influent.server.dataaccess.DataAccessHelper.java
License:MIT License
public static String format(DateTime dateTime) { if (dateTime == null) { return null; }//w ww . ja v a 2 s. c o m StringBuilder s = new StringBuilder(10); s.append(dateTime.getYear()); s.append('-'); pad00(dateTime.getMonthOfYear(), s); s.append('-'); pad00(dateTime.getDayOfMonth(), s); s.append(' '); pad00(dateTime.getHourOfDay(), s); s.append(':'); pad00(dateTime.getMinuteOfHour(), s); s.append(':'); pad00(dateTime.getSecondOfMinute(), s); s.append('.'); int ms = dateTime.getMillisOfSecond(); if (ms < 100) { s.append('0'); } pad00(ms, s); return s.toString(); }
From source file:influent.server.utilities.ConstrainedDateRange.java
License:MIT License
/** * Constructs a date range that is constrained to begin and end on instances of the specified * interval, and that is guaranteed to include the range specified. * /*w w w . ja v a2s. c om*/ * @param start * @param interval * @param numBins */ public ConstrainedDateRange(DateTime start, FL_DateInterval interval, long numBins) { super(start.getMillis(), interval, numBins); DateTime constrained = start; // constrain to start of interval. switch (interval) { case SECONDS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), start.getDayOfMonth(), start.getHourOfDay(), start.getMinuteOfHour(), start.getSecondOfMinute(), DateTimeZone.UTC); break; case HOURS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), start.getDayOfMonth(), start.getHourOfDay(), 0, DateTimeZone.UTC); break; case DAYS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), start.getDayOfMonth(), 0, 0, DateTimeZone.UTC); break; case WEEKS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), start.getDayOfMonth(), 0, 0, DateTimeZone.UTC); final int days = start.getDayOfWeek() % 7; final long rewindMillis = days * DateTimeConstants.MILLIS_PER_DAY; constrained = new DateTime(constrained.getMillis() - rewindMillis, constrained.getZone()); break; case MONTHS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), 1, 0, 0, DateTimeZone.UTC); break; case QUARTERS: constrained = new DateTime(start.getYear(), 1 + 3 * ((start.getMonthOfYear() - 1) / 3), 1, 0, 0, DateTimeZone.UTC); break; case YEARS: constrained = new DateTime(start.getYear(), start.getMonthOfYear(), 1, 0, 0, DateTimeZone.UTC); break; } // add an extra partial interval at the end when not large enough. if (!start.equals(constrained)) { //System.out.println(start + " -> " + constrained); setStartDate(constrained.getMillis()); setNumBins(numBins + 1); } }