List of usage examples for java.util Calendar SUNDAY
int SUNDAY
To view the source code for java.util Calendar SUNDAY.
Click Source Link
From source file:org.eevolution.form.VSCRP.java
public CategoryDataset createWeightDataset(Timestamp start, MResource r) { GregorianCalendar gc1 = new GregorianCalendar(); gc1.setTimeInMillis(start.getTime()); gc1.clear(Calendar.MILLISECOND); gc1.clear(Calendar.SECOND);//from ww w .ja v a2s . c om gc1.clear(Calendar.MINUTE); gc1.clear(Calendar.HOUR_OF_DAY); String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); String nameload = Msg.translate(Env.getCtx(), "Load"); String namesummary = Msg.translate(Env.getCtx(), "Summary"); String namepossiblecapacity = "Possible Capacity"; MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); double currentweight = DB.getSQLValue(null, "Select SUM( (mo.qtyordered-mo.qtydelivered)*(Select mp.weight From m_product mp Where mo.m_product_id=mp.m_product_id ) )From mpc_order mo Where ad_client_id=?", r.getAD_Client_ID()); // fjviejo e-evolution machineqty capacidad por el numero de maquinas // double dailyCapacity = DB.getSQLValue(null,"Select dailycapacity From s_resource Where s_resource_id=?",r.getS_Resource_ID()); double dailyCapacity = DB.getSQLValue(null, "Select dailycapacity*MachineQty From s_resource Where s_resource_id=?", r.getS_Resource_ID()); System.out.println("***** Capacidad diaria " + dailyCapacity); // e-evolution end double utilization = DB.getSQLValue(null, "Select percentutillization From s_resource Where s_resource_id=?", r.getS_Resource_ID()); double summary = 0; int day = 0; while (day < 32) { day++; switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: if (t.isOnSunday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.MONDAY: if (t.isOnMonday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.TUESDAY: if (t.isOnTuesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.WEDNESDAY: if (t.isOnWednesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.THURSDAY: if (t.isOnThursday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.FRIDAY: if (t.isOnFriday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.SATURDAY: if (t.isOnSaturday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; } dataset.addValue(currentweight, nameload, new Integer(day)); dataset.addValue(summary, namesummary, new Integer(day)); gc1.add(Calendar.DATE, 1); } return dataset; }
From source file:com.silverpeas.scheduler.simple.SchedulerJob.java
/** * This method sets the scheduling parameter. The time settings are given by vectors. Each vector * holds a list of Integer objects (currently ordered). Every Integer represents a element of a * timestamp (cron like)./*from ww w. ja va 2 s .c om*/ * @param startMinutes A list of minutes (0-59) * @param startHours A list of hours (0-23) * @param startDaysOfMonth A list of days of a month (1-31) * @param startMonths A list of months (1-12; starts with 1 for January) * @param startDaysOfWeek A list of day of a week (0-6; starts with 0 for Sunday) */ protected synchronized void setSchedulingParameter(List<Integer> startMinutes, List<Integer> startHours, List<Integer> startDaysOfMonth, List<Integer> startMonths, List<Integer> startDaysOfWeek) throws SchedulerException { Enumeration vectorEnumerator; List<Integer> workVector; int workInt; // Check minute values if (startMinutes == null) { startMinutes = new ArrayList<Integer>(); } for (Integer minute : startMinutes) { try { workInt = minute; if ((workInt < 0) || (workInt > 59)) { throw new SchedulerException("SchedulerMethodJob.setParameter: A minute value is out of range"); } } catch (ClassCastException aException) { throw new SchedulerException("SchedulerMethodJob.setParameter: Can't convert a minute value"); } } // Check hour values if (startHours == null) { startHours = new ArrayList<Integer>(); } for (Integer hours : startHours) { try { workInt = hours; if ((workInt < 0) || (workInt > 23)) { throw new SchedulerException("SchedulerMethodJob.setParameter: A hour value is out of range"); } } catch (ClassCastException aException) { throw new SchedulerException("SchedulerMethodJob.setParameter: Can't convert a hour value"); } } // Check day of month values if (startDaysOfMonth == null) { startDaysOfMonth = new ArrayList<Integer>(); } for (Integer days : startDaysOfMonth) { try { workInt = days; if ((workInt < 1) || (workInt > 31)) { throw new SchedulerException( "SchedulerMethodJob.setParameter: A day of month value is out of range"); } } catch (ClassCastException aException) { throw new SchedulerException("SchedulerMethodJob.setParameter: Can't convert a day of month value"); } } // Check month values and normalize them for internal usage if (startMonths == null) { startMonths = new ArrayList<Integer>(); } workVector = new ArrayList<Integer>(); for (Integer month : startMonths) { try { workInt = month; if ((workInt < 1) || (workInt > 12)) { throw new SchedulerException("SchedulerMethodJob.setParameter: A month value is out of range"); } workVector.add(workInt - 1); // Internal: zero based } catch (ClassCastException aException) { throw new SchedulerException("SchedulerMethodJob.setParameter: Can't convert a month value"); } } startMonths = workVector; // Check day of week values if (startDaysOfWeek == null) { startDaysOfWeek = new ArrayList<Integer>(); } workVector = new ArrayList<Integer>(); for (Integer daysOfWeek : startDaysOfWeek) { try { workInt = daysOfWeek; if ((workInt < 0) || (workInt > 6)) { throw new SchedulerException( "SchedulerMethodJob.setParameter: A day of week value is out of range"); } // Conversion not realy necessary, but what if SUN changes the // implementation .... :-)) switch (workInt) { case 0: workVector.add(Calendar.SUNDAY); break; case 1: workVector.add(Calendar.MONDAY); break; case 2: workVector.add(Calendar.TUESDAY); break; case 3: workVector.add(Calendar.WEDNESDAY); break; case 4: workVector.add(Calendar.THURSDAY); break; case 5: workVector.add(Calendar.FRIDAY); break; case 6: workVector.add(Calendar.SATURDAY); break; } } catch (ClassCastException aException) { throw new SchedulerException("SchedulerMethodJob.setParameter: Can't convert a day of week value"); } } startDaysOfWeek = workVector; // Assign the calculated values vMinutes = startMinutes; vHours = startHours; vDaysOfMonth = startDaysOfMonth; vMonths = startMonths; vDaysOfWeek = startDaysOfWeek; // Sort the calculated vectors sortCronVectors(); }
From source file:com.alkacon.opencms.calendar.CmsCalendarMonthBean.java
/** * Returns the days of a month to display in a matrix, depending on the start day of the week.<p> * /*from w w w.j a v a 2 s . c om*/ * The month matrix starts with index "1" and uses 7 columns per row to display one week in a row. * The value returns null if no date should be shown at the current index position.<p> * * @param year the year of the month to display * @param month the month to display * @param calendarLocale the Locale for the calendar to determine the start day of the week * @return the days of a month to display in a matrix, depending on the start day of the week */ public Map getMonthDaysMatrix(int year, int month, Locale calendarLocale) { Map monthDays = new TreeMap(); Calendar startDay = new GregorianCalendar(year, month, 1); Calendar runDay = startDay; int index = 1; // calculate the start day of the week Calendar calendar = new GregorianCalendar(calendarLocale); int weekStart = calendar.getFirstDayOfWeek(); // create empty indexes before the first day of the month while (runDay.get(Calendar.DAY_OF_WEEK) != weekStart) { monthDays.put(new Integer(index), null); index++; if (weekStart == Calendar.SATURDAY) { weekStart = Calendar.SUNDAY; } else { weekStart++; } } // create the indexes for the month dates while (true) { monthDays.put(new Integer(index), runDay.clone()); // increase day to next day runDay.roll(Calendar.DAY_OF_MONTH, true); index++; if (runDay.get(Calendar.DAY_OF_MONTH) == 1) { // runDay has switched to the next month, stop loop break; } } // create empty indexes after the last day of the month int rest = (index - 1) % 7; if (rest > 0) { rest = 7 - rest; } for (int i = 0; i < rest; i++) { monthDays.put(new Integer(index), null); index++; } return monthDays; }
From source file:UserInterface.TMAnalystRole.TMAnaylstWorkAreaJPanel.java
private void generateGraph(Train selectedTrain) { ArrayList<TrainOffered> selectedTrainOfferedListWEEKDAYS = new ArrayList<>(); ArrayList<TrainOffered> selectedTrainOfferedListWEEKENDS = new ArrayList<>(); int days = (int) spnrRecord.getValue(); Date today = new Date(); Date olderThanToday = new Date(); olderThanToday.setTime(today.getTime() + (long) (-days) * 1000 * 60 * 60 * 24); long todayDate = (today.getTime()) / (1000 * 60 * 60 * 24); long olderDate = (olderThanToday.getTime()) / (1000 * 60 * 60 * 24); for (TrainOffered selectedTrainOffered : enterprise.getTrainsOfferedHistory().getTrainsOffered()) { if (selectedTrainOffered.getTrain().equals(selectedTrain)) { long selectedDate = (selectedTrainOffered.getDayOffered().getTime()) / (1000 * 60 * 60 * 24); if (selectedDate >= olderDate && selectedDate <= todayDate) { Calendar date = Calendar.getInstance(); date.setTime(selectedTrainOffered.getDayOffered()); if ((date.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) || ((date.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY))) { if (!selectedTrainOfferedListWEEKENDS.contains(selectedTrainOffered)) { selectedTrainOfferedListWEEKENDS.add(selectedTrainOffered); }//from w w w . ja v a 2 s .c om } else { if (!selectedTrainOfferedListWEEKDAYS.contains(selectedTrainOffered)) { selectedTrainOfferedListWEEKDAYS.add(selectedTrainOffered); } } } } } Map<TimeSlot.TimeSlotRange, Integer> weekendData = new HashMap<TimeSlot.TimeSlotRange, Integer>(); for (TrainOffered selectedTrainOfferedOnWeekend : selectedTrainOfferedListWEEKENDS) { for (TrainStatus rt : selectedTrainOfferedOnWeekend.getRunningTrains()) { if (weekendData.containsKey(rt.getTrainSchedule().getTimeSlot())) { Integer previousValue = weekendData.get(rt.getTrainSchedule().getTimeSlot()); weekendData.put(rt.getTrainSchedule().getTimeSlot(), previousValue + rt.getRunningCapacity()); } else { weekendData.put(rt.getTrainSchedule().getTimeSlot(), rt.getRunningCapacity()); } } } ArrayList<Integer> sortedWeekendData = new ArrayList<>(); if (weekendData.size() > 0) { for (TimeSlot.TimeSlotRange tsr : TimeSlot.TimeSlotRange.values()) { sortedWeekendData.add(weekendData.get(tsr)); } } Map<TimeSlot.TimeSlotRange, Integer> weekdayData = new HashMap<>(); for (TrainOffered selectedTrainOfferedOnWeekDays : selectedTrainOfferedListWEEKDAYS) { for (TrainStatus rt : selectedTrainOfferedOnWeekDays.getRunningTrains()) { if (weekdayData.containsKey(rt.getTrainSchedule().getTimeSlot())) { Integer previousValue = weekdayData.get(rt.getTrainSchedule().getTimeSlot()); weekdayData.put(rt.getTrainSchedule().getTimeSlot(), previousValue + rt.getRunningCapacity()); } else { weekdayData.put(rt.getTrainSchedule().getTimeSlot(), rt.getRunningCapacity()); } } } ArrayList<Integer> sortedWeekDayDataList = new ArrayList<>(); if (weekdayData.size() > 0) { for (TimeSlot.TimeSlotRange tsr : TimeSlot.TimeSlotRange.values()) { sortedWeekDayDataList.add(weekdayData.get(tsr)); } } CategoryDataset dataset; String series1 = "Weekdays"; String series2 = "Weekends"; String series3 = "Maximum Capcity"; DefaultCategoryDataset dataset1 = new DefaultCategoryDataset(); for (int i = 0; i < sortedWeekendData.size(); i++) { dataset1.addValue(Math.round(sortedWeekendData.get(i) / selectedTrainOfferedListWEEKENDS.size()), series2, TimeSlot.TimeSlotRange.values()[i].getValue()); } for (int i = 0; i < sortedWeekDayDataList.size(); i++) { // System.out.println("Key = " + entry.getKey().getValue() + ", Value = " + Math.round(entry.getValue()/selectedTrainOfferedListWEEKENDS.size())); dataset1.addValue(Math.round(sortedWeekDayDataList.get(i) / selectedTrainOfferedListWEEKDAYS.size()), series1, TimeSlot.TimeSlotRange.values()[i].getValue()); } for (int i = 0; i < 15; i++) { // System.out.println("Key = " + entry.getKey().getValue() + ", Value = " + Math.round(entry.getValue()/selectedTrainOfferedListWEEKENDS.size())); dataset1.addValue(selectedTrain.getTrainCapacity(), series3, TimeSlot.TimeSlotRange.values()[i].getValue()); } dataset = dataset1; final JFreeChart chart = ChartFactory.createLineChart( "Average Congestion of Train : " + selectedTrain.getTrainName(), // chart title "Time Slot", // domain axis label "Congestion Level", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); ChartFrame chartPanel = new ChartFrame("Line Chart of Train", chart); chartPanel.setSize(this.getWidth(), this.getHeight() + 200); chartPanel.setVisible(true); }
From source file:org.eevolution.form.VCRP.java
public CategoryDataset createWeightDataset(Timestamp start, MResource r) { GregorianCalendar gc1 = new GregorianCalendar(); gc1.setTimeInMillis(start.getTime()); gc1.clear(Calendar.MILLISECOND); gc1.clear(Calendar.SECOND);//w ww. j a v a 2 s .co m gc1.clear(Calendar.MINUTE); gc1.clear(Calendar.HOUR_OF_DAY); String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); String nameload = Msg.translate(Env.getCtx(), "Load"); String namesummary = Msg.translate(Env.getCtx(), "Summary"); String namepossiblecapacity = "Possible Capacity"; MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); double currentweight = DB.getSQLValue(null, "Select SUM( (mo.qtyordered-mo.qtydelivered)*(Select mp.weight From m_product mp Where mo.m_product_id=mp.m_product_id ) )From mpc_order mo Where ad_client_id=?", r.getAD_Client_ID()); // fjviejo e-evolution machineqty capacidad por el numero de maquinas // double dailyCapacity = DB.getSQLValue(null,"Select dailycapacity From s_resource Where s_resource_id=?",r.getS_Resource_ID()); double dailyCapacity = DB.getSQLValue(null, "Select dailycapacity*MachineQty From s_resource Where s_resource_id=?", r.getS_Resource_ID()); System.out.println("***** Capacidad diaria " + dailyCapacity); // e-evolution end double utilization = DB.getSQLValue(null, "Select percentutillization From s_resource Where s_resource_id=?", r.getS_Resource_ID()); double summary = 0; int day = 0; /* * Vit4B Modificado para que tome 28 dias y * * */ while (day < 29) { day++; switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: if (t.isOnSunday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.MONDAY: if (t.isOnMonday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.TUESDAY: if (t.isOnTuesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.WEDNESDAY: if (t.isOnWednesday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.THURSDAY: if (t.isOnThursday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.FRIDAY: if (t.isOnFriday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; case Calendar.SATURDAY: if (t.isOnSaturday()) { currentweight -= (dailyCapacity * utilization) / 100; summary += ((dailyCapacity * utilization) / 100); dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day)); dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day)); } else { dataset.addValue(0, namepossiblecapacity, new Integer(day)); dataset.addValue(0, namecapacity, new Integer(day)); } break; } dataset.addValue(currentweight, nameload, new Integer(day)); dataset.addValue(summary, namesummary, new Integer(day)); gc1.add(Calendar.DATE, 1); } return dataset; }
From source file:org.activequant.util.charting.IntradayMarketTimeline.java
private long getStartTime(int day) { long startTime = 0; if (day == Calendar.SUNDAY) { startTime = this.sundayStart; } else if (day == Calendar.MONDAY) { startTime = this.mondayStart; } else if (day == Calendar.TUESDAY) { startTime = this.tuesdayStart; } else if (day == Calendar.WEDNESDAY) { startTime = this.wednesdayStart; } else if (day == Calendar.THURSDAY) { startTime = this.thursdayStart; } else if (day == Calendar.FRIDAY) { startTime = this.fridayStart; } else if (day == Calendar.SATURDAY) { startTime = this.saturdayStart; }/*from w w w .ja va2s.c o m*/ return startTime; }
From source file:com.castis.xylophone.adsmadapter.common.util.InventorySizePolicyGenerator.java
private List<String> getTimeExternalID(InventoryBoxDayCode dayCode, List<String> timeValueList) { List<String> externalIDList = new ArrayList<String>(); switch (dayCode) { case WEEKDAY: for (String timeValue : timeValueList) { timeValue = timeValue.length() < 2 ? "0" + timeValue : timeValue; externalIDList.add("W.*.W" + Calendar.MONDAY + ".H" + timeValue); externalIDList.add("W.*.W" + Calendar.TUESDAY + ".H" + timeValue); externalIDList.add("W.*.W" + Calendar.WEDNESDAY + ".H" + timeValue); externalIDList.add("W.*.W" + Calendar.THURSDAY + ".H" + timeValue); externalIDList.add("W.*.W" + Calendar.FRIDAY + ".H" + timeValue); }/*from www . j av a2s .c o m*/ break; case WEEKEND: for (String timeValue : timeValueList) { timeValue = timeValue.length() < 2 ? "0" + timeValue : timeValue; externalIDList.add("W.*.W" + Calendar.SUNDAY + ".H" + timeValue); externalIDList.add("W.*.W" + Calendar.SATURDAY + ".H" + timeValue); } break; } return externalIDList; }
From source file:com.frey.repo.DateUtil.java
/***************************************** * @return interger// w ww . j a v a 2 s. co m * @ ? ****************************************/ public static int getWeekNumOfYearDay(String strDate) throws ParseException { Calendar calendar = Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); Date curDate = format.parse(strDate); int iWeekNum; calendar.setTime(curDate); if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR) - 1; } else { iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR); } return iWeekNum; }
From source file:edu.stanford.epad.epadws.processing.pipeline.task.EpadStatisticsTask.java
@Override public void run() { try {/*from ww w .j av a 2s.c om*/ log.info("Getting epad statistics"); EpadStatistics es = new EpadStatistics(); int users = new User().getCount(""); int projects = new Project().getCount(""); int patients = new Subject().getCount(""); int studies = new Study().getCount(""); int files = new EpadFile().getCount(""); int templates = new EpadFile().getCount("filetype = '" + FileType.TEMPLATE.getName() + "'"); int plugins = new Plugin().getCount(""); int series = epadDatabaseOperations.getNumberOfSeries(); int npacs = RemotePACService.getInstance().getRemotePACs().size(); int aims = epadDatabaseOperations.getNumberOfAIMs("1 = 1"); int dsos = epadDatabaseOperations.getNumberOfAIMs("DSOSeriesUID is not null or DSOSeriesUID != ''"); int pacQueries = new RemotePACQuery().getCount(""); int wls = 0; try { wls = new WorkList().getCount(""); } catch (Exception x) { } String host = EPADConfig.xnatServer; if (host == null || host.equalsIgnoreCase("localhost") || host.equalsIgnoreCase("127.0.0.1") || host.equalsIgnoreCase("epad-vm")) host = System.getenv("DOCKER_HOST"); ; if (host == null || host.equalsIgnoreCase("localhost") || host.equalsIgnoreCase("127.0.0.1") || host.equalsIgnoreCase("epad-vm")) host = System.getenv("HOSTNAME"); ; if (host == null || host.equalsIgnoreCase("localhost") || host.equalsIgnoreCase("127.0.0.1") || host.equalsIgnoreCase("epad-vm")) host = InetAddress.getLocalHost().getHostName(); if (host == null || host.equalsIgnoreCase("localhost") || host.equalsIgnoreCase("127.0.0.1") || host.equalsIgnoreCase("epad-vm")) host = getIPAddress(); es.setHost(host); es.setNumOfUsers(users); es.setNumOfProjects(projects); es.setNumOfPatients(patients); es.setNumOfStudies(studies); es.setNumOfSeries(series); es.setNumOfAims(aims); es.setNumOfDSOs(dsos); es.setNumOfWorkLists(wls); es.setNumOfPacs(npacs); es.setNumOfAutoQueries(pacQueries); es.setNumOfFiles(files); es.setNumOfPlugins(plugins); es.setNumOfTemplates(templates); es.setCreator("admin"); es.save(); //get the template statistics List<EpadStatisticsTemplate> templateStats = epadDatabaseOperations.getTemplateStats(); Calendar now = Calendar.getInstance(); boolean daily = true; if ("Weekly".equalsIgnoreCase(EPADConfig.getParamValue("StatisticsPeriod", "Daily"))) daily = false; if (!"true".equalsIgnoreCase(EPADConfig.getParamValue("DISABLE_STATISTICS_TRANSMIT"))) { if (daily || now.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { long delay = new Random().nextInt(1800 + 1); if (EPADConfig.xnatServer.indexOf("stanford") == -1) Thread.sleep(1000 * delay); // So that all don't do this at the same time //send the number statistics String epadUrl = EPADConfig.getParamValue("EpadStatisticsURL", "https://epad-public.stanford.edu/epad/statistics/"); epadUrl = epadUrl + "?numOfUsers=" + users; epadUrl = epadUrl + "&numOfProjects=" + projects; epadUrl = epadUrl + "&numOfPatients=" + patients; epadUrl = epadUrl + "&numOfStudies=" + studies; epadUrl = epadUrl + "&numOfSeries=" + series; epadUrl = epadUrl + "&numOfAims=" + aims; epadUrl = epadUrl + "&numOfDSOs=" + dsos; epadUrl = epadUrl + "&numOfWorkLists=" + wls; epadUrl = epadUrl + "&numOfFiles=" + files; epadUrl = epadUrl + "&numOfPlugins=" + plugins; epadUrl = epadUrl + "&numOfTemplates=" + templates; epadUrl = epadUrl + "&host=" + host; HttpClient client = new HttpClient(); PutMethod putMethod = new PutMethod(epadUrl); try { log.info("Sending statistics to Central Epad, url:" + epadUrl); int status = client.executeMethod(putMethod); log.info("Done Sending, status:" + putMethod.getStatusLine()); } catch (IOException e) { log.warning("Error calling Central Epad with URL " + epadUrl, e); } finally { putMethod.releaseConnection(); } //send statistics for templates for (EpadStatisticsTemplate st : templateStats) { //get the xml first String filePath = st.getFilePath() + st.getFileId() + ".xml"; log.info("path " + filePath); File f = null; if (filePath != null && (f = new File(filePath)).exists()) { st.setTemplateText(EPADFileUtils.readFileAsString(f)); } st.setCreator("admin"); //persist to db st.save(); epadUrl = EPADConfig.getParamValue("EpadTemplateStatisticsURL", "https://epad-public.stanford.edu/epad/statistics/templates/"); epadUrl = epadUrl + "?templateCode=" + encode(st.getTemplateCode()); epadUrl = epadUrl + "&templateName=" + encode(st.getTemplateName()); epadUrl = epadUrl + "&authors=" + encode(st.getAuthors()); epadUrl = epadUrl + "&version=" + encode(st.getVersion()); epadUrl = epadUrl + "&templateLevelType=" + encode(st.getTemplateLevelType()); epadUrl = epadUrl + "&templateDescription=" + encode(st.getTemplateDescription()); epadUrl = epadUrl + "&numOfAims=" + st.getNumOfAims(); epadUrl = epadUrl + "&host=" + host; putMethod = new PutMethod(epadUrl); putMethod.setRequestEntity( new StringRequestEntity(st.getTemplateText(), "text/xml", "UTF-8")); try { log.info("Sending template statistics to Central Epad, url:" + epadUrl); int status = client.executeMethod(putMethod); log.info("Done Sending, status:" + putMethod.getStatusLine()); } catch (IOException e) { log.warning("Error calling Central Epad with URL " + epadUrl, e); } finally { putMethod.releaseConnection(); } } } } } catch (Exception e) { log.warning("Error is saving/sending statistics", e); } GetMethod getMethod = null; try { String epadUrl = EPADConfig.getParamValue("EpadStatusURL", "https://epad-public.stanford.edu/epad/status/"); HttpClient client = new HttpClient(); getMethod = new GetMethod(epadUrl); int status = client.executeMethod(getMethod); if (status == HttpServletResponse.SC_OK) { String response = getMethod.getResponseBodyAsString(); int versInd = response.indexOf("Version:"); if (versInd != -1) { String version = response.substring(versInd + "Version:".length() + 1); if (version.indexOf("\n") != -1) version = version.substring(0, version.indexOf("\n")); if (version.indexOf(" ") != -1) version = version.substring(0, version.indexOf(" ")); log.info("Current ePAD version:" + version + " Our Version:" + new EPadWebServerVersion().getVersion()); if (!version.equals(new EPadWebServerVersion().getVersion())) { newEPADVersion = version; newEPADVersionAvailable = true; String msg = "A new version of ePAD: " + version + " is available, please go to ftp://epad-distribution.stanford.edu/ to download"; log.info(msg); List<User> admins = new User().getObjects("admin = 1 and enabled = 1"); for (User admin : admins) { List<Map<String, String>> userEvents = epadDatabaseOperations .getEpadEventsForSessionID(admin.getUsername(), false); boolean skip = false; for (Map<String, String> event : userEvents) { if (event.get("aim_name").equals("Upgrade")) { skip = true; break; } } if (skip) continue; if (EPADConfig.xnatServer.indexOf("stanford") == -1) epadDatabaseOperations.insertEpadEvent(admin.getUsername(), msg, // Message "", "", // aimUID, aimName "", // patient ID "", // patient Name "", // templateID "", // templateName "Please update ePAD"); // PluginName } } } } else log.warning("Error is getting epad version"); } catch (Exception x) { log.warning("Error is getting epad version", x); } finally { getMethod.releaseConnection(); } //done with calculating and sending the statistics //calculate a monthly cumulative if it is there is no record for the month boolean isAlreadyCalced = false; Calendar now = Calendar.getInstance(); try { EPADUsageList monthly = epadOperations.getMonthlyUsageSummaryForMonth(now.get(Calendar.MONTH) + 1); if (monthly != null && monthly.ResultSet.totalRecords > 0) isAlreadyCalced = true; } catch (Exception e) { log.warning("Couldn't get if the monthly cumulative statistics already calculated, assuming no", e); } if (isAlreadyCalced == false) { epadDatabaseOperations.calcMonthlyCumulatives(); } }
From source file:org.activequant.util.charting.IntradayMarketTimeline.java
private long getEndTime(int day) { long endTime = 0; if (day == Calendar.SUNDAY) { endTime = this.sundayEnd; } else if (day == Calendar.MONDAY) { endTime = this.mondayEnd; } else if (day == Calendar.TUESDAY) { endTime = this.tuesdayEnd; } else if (day == Calendar.WEDNESDAY) { endTime = this.wednesdayEnd; } else if (day == Calendar.THURSDAY) { endTime = this.thursdayEnd; } else if (day == Calendar.FRIDAY) { endTime = this.fridayEnd; } else if (day == Calendar.SATURDAY) { endTime = this.saturdayEnd; }// w w w. j a v a 2s. c o m return endTime; }