List of usage examples for org.joda.time DateTime getMonthOfYear
public int getMonthOfYear()
From source file:eu.uqasar.web.dashboard.widget.datadeviation.DataDeviationWidget.java
License:Apache License
public Options getQualityParameterOptions() { Project proj = null;/*from w ww .j a va 2 s .c o m*/ 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.java 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:fi.craplab.roameo.ui.StatisticsWeekFragment.java
License:Open Source License
private void setupData() { DateTime dateTime = getFirstDayOfWeek(); DebugLog.d(TAG, String.format(Locale.US, "Setting up data for week %2d %d starting %s", mWeekNumber, mWeekYear, dateTime));//from w w w .j a va 2s .com for (int day = 0; day < DateTimeConstants.DAYS_PER_WEEK; day++) { DateTime dt = dateTime.plusDays(day); long steps = CallSession.getStepsForDay(dt.getMillis()); float duration = CallSession.getDurationsForDay(dt.getMillis()) / 1000; float pace = (duration > 0) ? (steps / (duration / 60f)) : 0.0f; mStepValues.add(new PointValue(day, steps)); mDurationValues.add(new PointValue(day, duration)); mPaceValues.add(new PointValue(day, pace)); mDayNameValues.add(day, new AxisValue(day).setLabel(dt.dayOfWeek().getAsShortText())); mDateValues.add(day, new AxisValue(day) .setLabel(String.format(Locale.US, "%02d/%02d", dt.getDayOfMonth(), dt.getMonthOfYear()))); } }
From source file:fi.craplab.roameo.ui.view.ExportDatePickerDialog.java
License:Open Source License
public ExportDatePickerDialog(@NonNull Context context, @NonNull OnDateSetListener listener, int datePickerType, DateTime dateTime) { mDialog = new DatePickerDialog(context, this, dateTime.getYear(), dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth());/*from ww w . j a v a 2 s . c o m*/ mListener = listener; mPickerType = datePickerType; }
From source file:gobblin.ingestion.google.DayPartitioner.java
License:Apache License
@Override public GenericRecord partitionForRecord(GenericRecord record) { GenericRecord partition = new GenericData.Record(_partitionSchema); String dateString = record.get(_dateColumn).toString(); DateTime date = _dateFormatter.parseDateTime(dateString); if (_withPrefix) { if (_withColumnNames) { partition.put(PARTITION_COLUMN_PREFIX, PARTITION_COLUMN_PREFIX + "=" + _prefix); } else {/*w w w . j ava2 s . c o m*/ partition.put(PARTITION_COLUMN_PREFIX, _prefix); } } if (_withColumnNames) { partition.put(PARTITION_COLUMN_YEAR, PARTITION_COLUMN_YEAR + "=" + date.getYear()); partition.put(PARTITION_COLUMN_MONTH, PARTITION_COLUMN_MONTH + "=" + date.getMonthOfYear()); partition.put(PARTITION_COLUMN_DAY, PARTITION_COLUMN_DAY + "=" + date.getDayOfMonth()); } else { partition.put(PARTITION_COLUMN_YEAR, date.getYear()); partition.put(PARTITION_COLUMN_MONTH, date.getMonthOfYear()); partition.put(PARTITION_COLUMN_DAY, date.getDayOfMonth()); } return partition; }
From source file:gobblin.ingestion.google.webmaster.GoogleWebmasterDayPartitioner.java
License:Apache License
@Override public GenericRecord partitionForRecord(GenericRecord record) { GenericRecord partition = new GenericData.Record(_partitionSchema); String dateString = record.get(DATE_COLUMN).toString(); DateTime date = GoogleWebmasterExtractor.dateFormatter.parseDateTime(dateString); if (_withPrefix) { if (_withColumnNames) { partition.put(PARTITION_COLUMN_PREFIX, PARTITION_COLUMN_PREFIX + "=" + _prefix); } else {//from w w w.ja v a 2 s . c o m partition.put(PARTITION_COLUMN_PREFIX, _prefix); } } if (_withColumnNames) { partition.put(PARTITION_COLUMN_YEAR, PARTITION_COLUMN_YEAR + "=" + date.getYear()); partition.put(PARTITION_COLUMN_MONTH, PARTITION_COLUMN_MONTH + "=" + date.getMonthOfYear()); partition.put(PARTITION_COLUMN_DAY, PARTITION_COLUMN_DAY + "=" + date.getDayOfMonth()); } else { partition.put(PARTITION_COLUMN_YEAR, date.getYear()); partition.put(PARTITION_COLUMN_MONTH, date.getMonthOfYear()); partition.put(PARTITION_COLUMN_DAY, date.getDayOfMonth()); } return partition; }
From source file:gobblin.util.TimeRangeChecker.java
License:Apache License
/** * Checks if a specified time is on a day that is specified the a given {@link List} of acceptable days, and that the * hours + minutes of the specified time fall into a range defined by startTimeStr and endTimeStr. * * @param days is a {@link List} of days, if the specified {@link DateTime} does not have a day that falls is in this * {@link List} then this method will return false. * @param startTimeStr defines the start range that the currentTime can fall into. This {@link String} should be of * the pattern defined by {@link #HOUR_MINUTE_FORMAT}. * @param endTimeStr defines the start range that the currentTime can fall into. This {@link String} should be of * the pattern defined by {@link #HOUR_MINUTE_FORMAT}. * @param currentTime is a {@link DateTime} for which this method will check if it is in the given {@link List} of * days and falls into the time range defined by startTimeStr and endTimeStr. * * @return true if the given time is in the defined range, false otherwise. *//* w w w . ja v a 2 s .c om*/ public static boolean isTimeInRange(List<String> days, String startTimeStr, String endTimeStr, DateTime currentTime) { if (!Iterables.any(days, new AreDaysEqual(DAYS_OF_WEEK.get(currentTime.getDayOfWeek())))) { return false; } DateTime startTime = null; DateTime endTime = null; try { startTime = HOUR_MINUTE_FORMATTER.withZone(DATE_TIME_ZONE).parseDateTime(startTimeStr); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "startTimeStr format is invalid, must be of format " + HOUR_MINUTE_FORMAT, e); } try { endTime = HOUR_MINUTE_FORMATTER.withZone(DATE_TIME_ZONE).parseDateTime(endTimeStr); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "endTimeStr format is invalid, must be of format " + HOUR_MINUTE_FORMAT, e); } startTime = startTime.withDate(currentTime.getYear(), currentTime.getMonthOfYear(), currentTime.getDayOfMonth()); endTime = endTime.withDate(currentTime.getYear(), currentTime.getMonthOfYear(), currentTime.getDayOfMonth()); Interval interval = new Interval(startTime.getMillis(), endTime.getMillis(), DATE_TIME_ZONE); return interval.contains(currentTime.getMillis()); }
From source file:google.registry.model.common.TimeOfYear.java
License:Open Source License
/** * Constructs a {@link TimeOfYear} from a {@link DateTime}. * * <p>This handles leap years in an intentionally peculiar way by always treating February 29 as * February 28. It is impossible to construct a {@link TimeOfYear} for February 29th. *//*w ww. j a v a2 s . c o m*/ public static TimeOfYear fromDateTime(DateTime dateTime) { DateTime nextYear = dateTime.plusYears(1); // This turns February 29 into February 28. TimeOfYear instance = new TimeOfYear(); instance.timeString = String.format("%02d %02d %08d", nextYear.getMonthOfYear(), nextYear.getDayOfMonth(), nextYear.getMillisOfDay()); return instance; }
From source file:Implement.Service.CommonServiceImpl.java
@Override public String getToDateInMillisecond() { DateTime toDateObj = new DateTime(); Date result = new Date(toDateObj.getYear() - 1900, toDateObj.getMonthOfYear() - 1, toDateObj.getDayOfMonth());//from w ww .j a va2s. co m return String.valueOf(result.getTime() + Long.valueOf("86400000")); }
From source file:Implement.Service.ProviderServiceImpl.java
@Override public String getProviderTrippDash(int providerID) { DateTime toDateObj = new DateTime(); Date result = new Date(toDateObj.getYear() - 1900, toDateObj.getMonthOfYear() - 1, toDateObj.getDayOfMonth());/*from w ww . j a va 2 s.c o m*/ long currentTime = Long.valueOf(result.getTime() + Long.valueOf("86400000")); long last30Day = currentTime - Long.valueOf("2592000000"); return gson.toJson(providerDAO.getProviderTrippDash(providerID, currentTime, last30Day)); }