List of usage examples for java.lang Math ceil
public static double ceil(double a)
From source file:com.firesoft.member.Model.UserListModel.java
public void fetNextService(int serviceId, ENUM_SEARCH_ORDER search_order) { userlistRequest userrequest = new userlistRequest(); userrequest.service_type = serviceId; userrequest.sid = SESSION.getInstance().sid; userrequest.uid = SESSION.getInstance().uid; userrequest.sort_by = search_order.value(); userrequest.ver = MemberAppConst.VERSION_CODE; if (dataList.size() > 0) { userrequest.by_no = (int) Math.ceil(dataList.size() * 1.0 / NUMPERPAGE) + 1; ;/*from w w w .j av a 2 s . c om*/ } userrequest.count = NUMPERPAGE; userrequest.location = new LOCATION(); userrequest.location.lat = LocationManager.getLatitude(); userrequest.location.lon = LocationManager.getLongitude(); BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() { @Override public void callback(String url, JSONObject jo, AjaxStatus status) { try { UserListModel.this.callback(this, url, jo, status); if (null != jo) { userlistResponse response = new userlistResponse(); response.fromJson(jo); if (response.succeed == 1) { dataList.addAll(response.users); UserListModel.this.OnMessageResponse(url, jo, status); } else { UserListModel.this.callback(url, response.error_code, response.error_desc); } } else { UserListModel.this.OnMessageResponse(url, jo, status); } } catch (JSONException e) { } } }; Map<String, Object> params = new HashMap<String, Object>(); try { JSONObject requestJson = userrequest.toJson(); requestJson.remove("by_id"); params.put("json", requestJson.toString()); } catch (JSONException e) { } if (isSendingMessage(ApiInterface.USER_LIST)) { return; } cb.url(ApiInterface.USER_LIST).type(JSONObject.class).params(params); ajax(cb); }
From source file:web.InteractionsController.java
/** * * @param pageid//ww w .j a va 2 s . c o m * @param request * @return */ @RequestMapping("/interactions/viewinteraction/{pageid}") public ModelAndView viewinteractions(@PathVariable int pageid, HttpServletRequest request) { int total = 10; int start = 1; if (pageid != 1) { start = (pageid - 1) * total + 1; } List<Interactions> list = dao.getInteractionsByPage(start, total); HashMap<String, Object> context = new HashMap<String, Object>(); context.put("list", list); int count = dao.getInteractionsCount(); context.put("pages", Math.ceil((float) count / (float) total)); context.put("page", pageid); Message msg = (Message) request.getSession().getAttribute("message"); if (msg != null) { context.put("message", msg); request.getSession().removeAttribute("message"); } return new ModelAndView("viewinteractions", context); }
From source file:com.insthub.O2OMobile.Model.UserListModel.java
public void fetNextService(int serviceId, ENUM_SEARCH_ORDER search_order) { userlistRequest userrequest = new userlistRequest(); userrequest.service_type = serviceId; userrequest.sid = SESSION.getInstance().sid; userrequest.uid = SESSION.getInstance().uid; userrequest.sort_by = search_order.value(); userrequest.ver = O2OMobileAppConst.VERSION_CODE; if (dataList.size() > 0) { userrequest.by_no = (int) Math.ceil(dataList.size() * 1.0 / NUMPERPAGE) + 1; ;// w w w. j a v a 2 s . c o m } userrequest.count = NUMPERPAGE; userrequest.location = new LOCATION(); userrequest.location.lat = LocationManager.getLatitude(); userrequest.location.lon = LocationManager.getLongitude(); BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() { @Override public void callback(String url, JSONObject jo, AjaxStatus status) { try { UserListModel.this.callback(this, url, jo, status); if (null != jo) { userlistResponse response = new userlistResponse(); response.fromJson(jo); if (response.succeed == 1) { dataList.addAll(response.users); UserListModel.this.OnMessageResponse(url, jo, status); } else { UserListModel.this.callback(url, response.error_code, response.error_desc); } } else { UserListModel.this.OnMessageResponse(url, jo, status); } } catch (JSONException e) { } } }; Map<String, Object> params = new HashMap<String, Object>(); try { JSONObject requestJson = userrequest.toJson(); requestJson.remove("by_id"); params.put("json", requestJson.toString()); } catch (JSONException e) { } if (isSendingMessage(ApiInterface.USER_LIST)) { return; } cb.url(ApiInterface.USER_LIST).type(JSONObject.class).params(params); ajax(cb); }
From source file:org.sakaiproject.gradebookng.tool.panels.AssignmentStatisticsPanel.java
@Override public void onInitialize() { super.onInitialize(); final Long assignmentId = ((Model<Long>) getDefaultModel()).getObject(); final Assignment assignment = this.businessService.getAssignment(assignmentId.longValue()); AssignmentStatisticsPanel.this.window.setTitle( (new StringResourceModel("label.statistics.title", null, new Object[] { assignment.getName() }) .getString()));/* w w w . ja v a2 s . c o m*/ final List<GbStudentGradeInfo> gradeInfo = this.businessService.buildGradeMatrix(Arrays.asList(assignment)); final List<Double> allGrades = new ArrayList<>(); for (int i = 0; i < gradeInfo.size(); i++) { final GbStudentGradeInfo studentGradeInfo = gradeInfo.get(i); final Map<Long, GbGradeInfo> studentGrades = studentGradeInfo.getGrades(); final GbGradeInfo grade = studentGrades.get(assignmentId); if (grade == null || grade.getGrade() == null) { // this is not the grade you are looking for } else { allGrades.add(Double.valueOf(grade.getGrade())); } } Collections.sort(allGrades); final DefaultCategoryDataset data = new DefaultCategoryDataset(); final Map<String, Integer> counts = new TreeMap<>(); Integer extraCredits = 0; // Start off with a 0-50% range counts.put(String.format("%d-%d", 0, 50), 0); final int range = 10; for (int start = 50; start < 100; start = start + range) { final String key = String.format("%d-%d", start, start + range); counts.put(key, 0); } for (final Double grade : allGrades) { if (isExtraCredit(grade, assignment)) { extraCredits = extraCredits + 1; continue; } final double percentage; if (GradingType.PERCENTAGE.equals(this.gradingType)) { percentage = grade; } else { percentage = grade / assignment.getPoints() * 100; } final int total = Double.valueOf(Math.ceil(percentage) / range).intValue(); int start = total * range; if (start == 100) { start = start - range; } String key = String.format("%d-%d", start, start + range); if (start < 50) { key = String.format("%d-%d", 0, 50); } counts.put(key, counts.get(key) + 1); } for (final String label : counts.keySet()) { data.addValue(counts.get(label), "count", label); } if (extraCredits > 0) { data.addValue(extraCredits, "count", getString("label.statistics.chart.extracredit")); } final JFreeChart chart = ChartFactory.createBarChart(null, // the chart title getString("label.statistics.chart.xaxis"), // the label for the category axis getString("label.statistics.chart.yaxis"), // the label for the value axis data, // the dataset for the chart PlotOrientation.VERTICAL, // the plot orientation false, // show legend true, // show tooltips false); // show urls chart.setBorderVisible(false); chart.setAntiAlias(false); final CategoryPlot categoryPlot = chart.getCategoryPlot(); final BarRenderer br = (BarRenderer) categoryPlot.getRenderer(); br.setItemMargin(0); br.setMinimumBarLength(0.05); br.setMaximumBarWidth(0.1); br.setSeriesPaint(0, new Color(51, 122, 183)); br.setBarPainter(new StandardBarPainter()); br.setShadowPaint(new Color(220, 220, 220)); BarRenderer.setDefaultShadowsVisible(true); br.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(getString("label.statistics.chart.tooltip"), NumberFormat.getInstance())); categoryPlot.setRenderer(br); // show only integers in the count axis categoryPlot.getRangeAxis().setStandardTickUnits(new NumberTickUnitSource(true)); categoryPlot.setBackgroundPaint(Color.white); add(new JFreeChartImageWithToolTip("chart", Model.of(chart), "tooltip", 540, 300)); add(new Label("graded", String.valueOf(allGrades.size()))); if (allGrades.size() > 0) { add(new Label("average", constructAverageLabel(allGrades, assignment))); add(new Label("median", constructMedianLabel(allGrades, assignment))); add(new Label("lowest", constructLowestLabel(allGrades, assignment))); add(new Label("highest", constructHighestLabel(allGrades, assignment))); add(new Label("deviation", constructStandardDeviationLabel(allGrades))); } else { add(new Label("average", "-")); add(new Label("median", "-")); add(new Label("lowest", "-")); add(new Label("highest", "-")); add(new Label("deviation", "-")); } add(new GbAjaxLink("done") { private static final long serialVersionUID = 1L; @Override public void onClick(final AjaxRequestTarget target) { AssignmentStatisticsPanel.this.window.close(target); } }); }
From source file:com.insthub.O2OMobile.Model.OrderListAroundModel.java
public void getListMore(int sort_by) { orderlistaroundRequest request = new orderlistaroundRequest(); request.sid = SESSION.getInstance().sid; request.uid = SESSION.getInstance().uid; request.ver = O2OMobileAppConst.VERSION_CODE; request.sort_by = sort_by;/*from w w w. j ava 2 s . c o m*/ request.by_no = (int) Math.ceil(publicOrderList.size() * 1.0 / NUMPERPAGE) + 1; request.count = NUMPERPAGE; LOCATION location = new LOCATION(); location.lat = LocationManager.getLatitude(); location.lon = LocationManager.getLongitude(); request.location = location; BeeCallback<JSONObject> cb = new BeeCallback<JSONObject>() { @Override public void callback(String url, JSONObject jo, AjaxStatus status) { try { OrderListAroundModel.this.callback(this, url, jo, status); if (null != jo) { orderlistaroundResponse response = new orderlistaroundResponse(); response.fromJson(jo); publicMore = response.more; if (response.succeed == 1) { publicOrderList.addAll(response.orders); OrderListAroundModel.this.OnMessageResponse(url, jo, status); } else { OrderListAroundModel.this.callback(url, response.error_code, response.error_desc); } } } catch (JSONException e) { } } }; Map<String, Object> params = new HashMap<String, Object>(); try { JSONObject requestJson = request.toJson(); requestJson.remove("by_id"); params.put("json", requestJson.toString()); } catch (JSONException e) { } if (isSendingMessage(ApiInterface.ORDERLIST_AROUND)) { return; } cb.url(ApiInterface.ORDERLIST_AROUND).type(JSONObject.class).params(params); ajax(cb); }
From source file:edu.asu.ca.kaushik.algorithms.randomized.lll.GroupLLL.java
/** * Size of the smaller array is (1 + ln (d * A)) / ln B * Where d = choose(k,t) - choose(k-t,t), and * A = v^t, B = A/(A-1) for the Trivial group, * A = v^{t-1}, B = A/(A-1) for the cyclic group, and * A = (v^{t-1}-1)/(v-1), B = v^{t-1}/(v^{t-1}-v+1). * @param t//from w ww . j av a 2 s . c om * @param k * @param v * @return */ private int arraySize(int t, int k, int v) { double d = CombinatoricsUtils.binomialCoefficientDouble(k, t) - CombinatoricsUtils.binomialCoefficientDouble(k - t, t); double A = 0.0d; double B = 0.0d; switch (this.gId) { case 0: // trivial group A = Math.pow(v, t); B = A / (A - 1); break; case 1: // cyclic group A = Math.pow(v, t - 1); B = A / (A - 1); break; case 2: // Frobenius group double vtm1 = Math.pow(v, t - 1); A = (vtm1 - 1) / (v - 1); B = vtm1 / (vtm1 - v + 1); break; default: System.err.println("Invalid group Id."); System.exit(1); } double nume = 1.0d + Math.log(d * A); double dnom = Math.log(B); return (int) Math.ceil(nume / dnom); }
From source file:com.eftech.wood.phone.iphone.IphoneJDBCTemplate.java
@Override public List<Iphone> listIphone(Select select, int page_nomber) { List<Iphone> listIphone = listIphone(select); // get int count = listIphone.size(); // nomber of products from question List<Iphone> listIphone2 = new ArrayList<Iphone>(); // add elements to list int finishProd = page_nomber * NOMBER_PRODUCTS_ON_PAGE; int startProd = page_nomber * NOMBER_PRODUCTS_ON_PAGE - NOMBER_PRODUCTS_ON_PAGE; for (int i = 0; i < listIphone.size(); i++) { if ((i >= startProd) && (i < finishProd)) listIphone2.add(listIphone.get(i)); }/*from w w w. j av a2 s .co m*/ setKol_vo_product(listIphone.size()); kol_vo_page_itogo = (int) Math.ceil((double) count / (double) NOMBER_PRODUCTS_ON_PAGE); // setKol_vo_page_itogo(); return listIphone2; }
From source file:handlers.actionshift.RewardListInfo.java
/** * Method ratedGroupedRewardList.// ww w . ja v a 2 s . c om * @param tmp StringBuilder * @param npc NpcInstance * @param list RewardList * @param player Player * @param mod double */ private static void ratedGroupedRewardList(StringBuilder tmp, NpcInstance npc, RewardList list, Player player, double mod) { tmp.append("<table width=270 border=0>"); tmp.append("<tr><td><table width=270 border=0><tr><td><font color=\"aaccff\">").append(list.getType()) .append("</font></td></tr></table></td></tr>"); tmp.append("<tr><td><img src=\"L2UI.SquareWhite\" width=270 height=1> </td></tr>"); tmp.append("<tr><td><img src=\"L2UI.SquareBlank\" width=270 height=10> </td></tr>"); for (RewardGroup g : list) { List<RewardData> items = g.getItems(); double gchance = g.getChance(); double gmod = mod; double grate; double gmult; double rateDrop = (npc instanceof RaidBossInstance ? Config.RATE_DROP_RAIDBOSS : npc.isSiegeGuard() ? (Config.RATE_DROP_SIEGE_GUARD + player.getVitalityBonus()) : Config.RATE_DROP_ITEMS * player.getRateItems()); double rateAdena = (Config.RATE_DROP_ADENA + player.getVitalityBonus()) * player.getRateAdena(); if (g.isAdena()) { if (rateAdena == 0) { continue; } grate = rateAdena; if (gmod > 10) { gmod *= g.getChance() / RewardList.MAX_CHANCE; gchance = RewardList.MAX_CHANCE; } grate *= gmod; } else { if (rateDrop == 0) { continue; } grate = rateDrop; if (g.notRate()) { grate = Math.min(gmod, 1.0); } else { grate *= gmod; } } gmult = Math.ceil(grate); tmp.append("<tr><td><img src=\"L2UI.SquareBlank\" width=270 height=10> </td></tr>"); tmp.append("<tr><td>"); tmp.append("<table width=270 border=0 bgcolor=333333>"); tmp.append("<tr><td width=170><font color=\"a2a0a2\">Group Chance: </font><font color=\"b09979\">") .append(pf.format(gchance / RewardList.MAX_CHANCE)).append("</font></td>"); tmp.append("<td width=100 align=right>"); tmp.append("</td></tr>"); tmp.append("</table>").append("</td></tr>"); tmp.append("<tr><td><table>"); for (RewardData d : items) { double imult = d.notRate() ? 1.0 : gmult; String icon = d.getItem().getIcon(); if ((icon == null) || icon.equals(StringUtils.EMPTY)) { icon = "icon.etc_question_mark_i00"; } tmp.append("<tr><td width=32><img src=").append(icon) .append(" width=32 height=32></td><td width=238>").append(HtmlUtils.htmlItemName(d.getId())) .append("<br1>"); tmp.append("<font color=\"b09979\">[") .append(Math.round(d.getMinDrop() * (g.isAdena() ? gmult : 1.0))).append("..") .append(Math.round(d.getMaxDrop() * imult)).append("] "); tmp.append(pf.format(d.getChance() / RewardList.MAX_CHANCE)).append("</font></td></tr>"); } tmp.append("</table></td></tr>"); } tmp.append("</table>"); }
From source file:edu.indiana.soic.ts.mapreduce.pwd.PairWiseDistance.java
public int execJob(Configuration conf, String sequenceFileFullPath, String sequenceFile, String distDir) throws Exception { /* input parameters */ LOG.info(sequenceFileFullPath);//from w ww .j a va2 s. c o m Job job = new Job(conf, "Pairwise-calc-" + sequenceFile); /* create the base dir for this job. Delete and recreates if it exists */ Path hdMainDir = new Path(distDir + "/" + sequenceFile); FileSystem fs = FileSystem.get(conf); fs.delete(hdMainDir, true); Path hdInputDir = new Path(hdMainDir, "data"); if (!fs.mkdirs(hdInputDir)) { throw new IOException("Mkdirs failed to create " + hdInputDir.toString()); } int noOfSequences = getNoOfSequences(sequenceFileFullPath, fs); int noOfDivisions = (int) Math.ceil(noOfSequences / (double) blockSize); int noOfBlocks = (noOfDivisions * (noOfDivisions + 1)) / 2; LOG.info("No of divisions :" + noOfDivisions + "\nNo of blocks :" + noOfBlocks + "\nBlock size :" + blockSize); // Retrieving the configuration form the job to set the properties // Setting properties to the original conf does not work (possible // Hadoop bug) Configuration jobConf = job.getConfiguration(); // Input dir in HDFS. Create this in newly created job base dir Path inputDir = new Path(hdMainDir, "input"); if (!fs.mkdirs(inputDir)) { throw new IOException("Mkdirs failed to create " + inputDir.toString()); } Long dataPartitionStartTime = System.nanoTime(); partitionData(sequenceFileFullPath, noOfSequences, blockSize, fs, noOfDivisions, jobConf, inputDir); distributeData(blockSize, conf, fs, hdInputDir, noOfDivisions); long dataPartTime = (System.nanoTime() - dataPartitionStartTime) / 1000000; LOG.info("Data Partition & Scatter Completed in (ms):" + dataPartTime); // Output dir in HDFS Path hdOutDir = new Path(hdMainDir, "out"); jobConf.setInt(Constants.BLOCK_SIZE, blockSize); jobConf.setInt(Constants.NO_OF_DIVISIONS, noOfDivisions); jobConf.setInt(Constants.NO_OF_SEQUENCES, noOfSequences); jobConf.set(Constants.DIST_FUNC, distFunc); job.setJarByClass(PairWiseDistance.class); job.setMapperClass(SWGMap.class); job.setReducerClass(SWGReduce.class); job.setOutputKeyClass(LongWritable.class); job.setOutputValueClass(SWGWritable.class); FileInputFormat.setInputPaths(job, hdInputDir); FileOutputFormat.setOutputPath(job, hdOutDir); job.setInputFormatClass(SequenceFileInputFormat.class); job.setOutputFormatClass(SequenceFileOutputFormat.class); job.setNumReduceTasks(noOfDivisions); long startTime = System.currentTimeMillis(); int exitStatus = job.waitForCompletion(true) ? 0 : 1; double executionTime = (System.currentTimeMillis() - startTime) / 1000.0; LOG.info("Job Finished in " + executionTime + " seconds"); LOG.info("# #seq\t#blockS\tTtime\tinput\tdataDistTime\toutput" + noOfSequences + "\t" + noOfBlocks + "\t" + executionTime + "\t" + sequenceFileFullPath + "\t" + dataPartTime + "\t" + hdMainDir); return exitStatus; }