List of usage examples for java.lang Float Float
@Deprecated(since = "9") public Float(String s) throws NumberFormatException
From source file:org.openmrs.module.pmtct.web.view.chart.MaternityPieChartView.java
/** * @see org.openmrs.module.pmtct.web.view.chart.AbstractChartView#createChart(java.util.Map, * javax.servlet.http.HttpServletRequest) *//*w w w . j a va2 s . com*/ @Override protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) { UserContext userContext = Context.getUserContext(); ApplicationContext appContext = ContextProvider.getApplicationContext(); PMTCTModuleTag tag = new PMTCTModuleTag(); List<Object> res = new ArrayList<Object>(); PmtctService pmtct; pmtct = Context.getService(PmtctService.class); String startDate = ""; String endDate = ""; DefaultPieDataset pieDataset = new DefaultPieDataset(); String title = "", descriptionTitle = "", dateInterval = ""; Concept concept = null; Encounter enc = null; SimpleDateFormat df = MohTracUtil.getMySQLDateFormat();//new SimpleDateFormat("dd/MM/yyyy"); if (request.getParameter("type").compareTo("1") == 0) { try { // Date myDate = new Date("1/1/" + ((new Date()).getYear() + 1900)); // startDate = df.format(myDate); Date today = new Date(); Date oneYearFromNow = new Date(new Date().getTime() - PMTCTConstants.YEAR_IN_MILLISECONDS); endDate = df.format(today); startDate = df.format(oneYearFromNow); dateInterval = "(" + new SimpleDateFormat("dd-MMM-yyyy").format(oneYearFromNow) + " - " + new SimpleDateFormat("dd-MMM-yyyy").format(today) + ")"; res = pmtct.getGeneralStatsForPatientsInMaternity(startDate, endDate); List<String> childBornOptions = new ArrayList<String>(); List<Integer> childBornStatusValues = new ArrayList<Integer>(); Collection<ConceptAnswer> answers = Context.getConceptService() .getConcept(PMTCTConfigurationUtils.getBornStatusConceptId()).getAnswers(); for (ConceptAnswer str : answers) { childBornOptions.add(str.getAnswerConcept().getName().getName()); childBornStatusValues.add(0); } childBornOptions.add("Others"); childBornStatusValues.add(0); for (Object ob : res) { int patientId = (Integer) ((Object[]) ob)[0]; Encounter matEnc = tag.getMaternityEncounterInfo(patientId); String childResult = tag.observationValueByConcept(matEnc, PMTCTConfigurationUtils.getBornStatusConceptId()); int i = 0; boolean found = false; for (String s : childBornOptions) { if ((s.compareToIgnoreCase(childResult)) == 0) { childBornStatusValues.set(i, childBornStatusValues.get(i) + 1); found = true; } i++; } if (!found) { childBornStatusValues.set(childBornStatusValues.size() - 1, childBornStatusValues.get(childBornStatusValues.size() - 1) + 1); } } int i = 0; for (String s : childBornOptions) { if (childBornStatusValues.get(i) > 0) { Float percentage = new Float(100 * childBornStatusValues.get(i) / res.size()); pieDataset.setValue(s + " (" + childBornStatusValues.get(i) + " , " + percentage + "%)", percentage); } i++; } concept = Context.getConceptService().getConcept(PMTCTConfigurationUtils.getBornStatusConceptId()); } catch (Exception ex) { ex.printStackTrace(); } title = MohTracUtil.getMessage("pmtct.menu.maternity", null); } else if (request.getParameter("type").compareTo("2") == 0) { try { res = pmtct.getExpectedPatientsInMaternity(); String patientHivStatus = "", partnerHivStatus = ""; int allPositive = 0, allNegative = 0, negPos = 0, posNeg = 0, other = 0; for (Object ob : res) { int patientId = (Integer) ((Object[]) ob)[0]; enc = tag.getCPNEncounterInfo(patientId); patientHivStatus = tag.observationValueByConcept(enc, PMTCTConstants.RESULT_OF_HIV_TEST); partnerHivStatus = tag.observationValueByConcept(enc, PMTCTConstants.TESTING_STATUS_OF_PARTNER); if (patientHivStatus.compareTo(partnerHivStatus) == 0 && patientHivStatus.compareTo(Context .getConceptService().getConcept(PMTCTConstants.POSITIVE).getName().getName()) == 0) allPositive += 1; else if (patientHivStatus.compareTo(partnerHivStatus) == 0 && patientHivStatus.compareTo(Context .getConceptService().getConcept(PMTCTConstants.NEGATIVE).getName().getName()) == 0) allNegative += 1; else if (patientHivStatus .compareTo(Context.getConceptService().getConcept(PMTCTConstants.NEGATIVE).getName() .getName()) == 0 && partnerHivStatus.compareTo(Context.getConceptService() .getConcept(PMTCTConstants.POSITIVE).getName().getName()) == 0) negPos += 1; else if (patientHivStatus .compareTo(Context.getConceptService().getConcept(PMTCTConstants.POSITIVE).getName() .getName()) == 0 && partnerHivStatus.compareTo(Context.getConceptService() .getConcept(PMTCTConstants.NEGATIVE).getName().getName()) == 0) posNeg += 1; else other += 1; } Float percentage = 0f; if (allPositive > 0) { percentage = new Float(100 * allPositive / res.size()); title = MohTracUtil.getMessage("pmtct.menu.allPositive", null); pieDataset.setValue(title + " (" + allPositive + " , " + percentage + "%)", percentage); } if (allNegative > 0) { percentage = new Float(100 * allNegative / res.size()); title = MohTracUtil.getMessage("pmtct.menu.allNegative", null); pieDataset.setValue(title + " (" + allNegative + " , " + percentage + "%)", percentage); } if (posNeg > 0) { percentage = new Float(100 * posNeg / res.size()); title = MohTracUtil.getMessage("pmtct.menu.posNeg", null); pieDataset.setValue(title + " (" + posNeg + " , " + percentage + "%)", percentage); } if (negPos > 0) { percentage = new Float(100 * negPos / res.size()); title = MohTracUtil.getMessage("pmtct.menu.negPos", null); pieDataset.setValue(title + " (" + negPos + " , " + percentage + "%)", percentage); } if (other > 0) { percentage = new Float(100 * other / res.size()); title = MohTracUtil.getMessage("pmtct.menu.otherStatus", null); pieDataset.setValue(title + " (" + other + " , " + percentage + "%)", percentage); } title = MohTracUtil.getMessage("pmtct.menu.expectedMaternityPatient", null); descriptionTitle = MohTracUtil.getMessage("pmtct.menu.partnerStatus", null); concept = null; } catch (Exception e) { e.printStackTrace(); } } else if (request.getParameter("type").compareTo("3") == 0) { log.info(">>>>>>>>>>>>>>GRAPHICS>>patientsTestedInDeliveryRoom>>>Starting..."); try { // Date myDate = new Date("1/1/" + ((new Date()).getYear() + 1900)); // startDate = df.format(myDate); Date today = new Date(); Date oneYearFromNow = new Date(new Date().getTime() - PMTCTConstants.YEAR_IN_MILLISECONDS); endDate = df.format(today); startDate = df.format(oneYearFromNow); log.info(">>>>>>>>>>>>>>GRAPHICS>>patientsTestedInDeliveryRoom>>>startdate=" + startDate + " - endDate" + endDate); dateInterval = "(" + new SimpleDateFormat("dd-MMM-yyyy").format(oneYearFromNow) + " - " + new SimpleDateFormat("dd-MMM-yyyy").format(today) + ")"; res = pmtct.getpatientsTestedInDeliveryRoom(startDate, endDate); log.info(">>>>>>>>>>>>>>GRAPHICS>>patientsTestedInDeliveryRoom>>>Result=" + res.size()); // log.info(">>>>>>>>>>>>>>MaternityPieChartView>> startdate=" + startDate + "----- enddate=" + endDate // + "<<=====>>" + res.size()); List<String> resultOfHIVTestOptions = new ArrayList<String>(); List<Integer> resultOfHIVTestValues = new ArrayList<Integer>(); Collection<ConceptAnswer> answers = Context.getConceptService() .getConcept(PMTCTConstants.RESULT_HIV_TEST_IN_DELIVERY_ROOM).getAnswers(); for (ConceptAnswer str : answers) { resultOfHIVTestOptions.add(str.getAnswerConcept().getName().getName()); resultOfHIVTestValues.add(0); } resultOfHIVTestOptions.add("Others"); resultOfHIVTestValues.add(0); for (Object ob : res) { int patientId = (Integer) ((Object[]) ob)[0]; Encounter matEnc = tag.getMaternityEncounterInfo(patientId); String hivTestResult = tag.observationValueByConcept(matEnc, PMTCTConstants.RESULT_HIV_TEST_IN_DELIVERY_ROOM); int i = 0; boolean found = false; for (String s : resultOfHIVTestOptions) { if ((s.compareToIgnoreCase(hivTestResult)) == 0) { resultOfHIVTestValues.set(i, resultOfHIVTestValues.get(i) + 1); found = true; } i++; } if (!found) { resultOfHIVTestValues.set(resultOfHIVTestValues.size() - 1, resultOfHIVTestValues.get(resultOfHIVTestValues.size() - 1) + 1); } } int i = 0; for (String s : resultOfHIVTestOptions) { if (resultOfHIVTestValues.get(i) > 0) { Float percentage = new Float(100 * resultOfHIVTestValues.get(i) / res.size()); pieDataset.setValue(s + " (" + resultOfHIVTestValues.get(i) + " , " + percentage + "%)", percentage); } i++; } concept = Context.getConceptService() .getConcept(PMTCTConfigurationUtils.getHivTestInDeliveryRoomConceptId()); log.info(">>>>>>>>>>>>>>GRAPHICS>>patientsTestedInDeliveryRoom>>>End"); } catch (Exception ex) { log.error(">>>>>>>>>An error occured when trying to create piechart..."); ex.printStackTrace(); } title = appContext.getMessage("pmtct.menu.maternity", null, userContext.getLocale()); } JFreeChart chart = ChartFactory.createPieChart(title + " : " + ((null != concept) ? concept.getPreferredName(userContext.getLocale()) + dateInterval : descriptionTitle), pieDataset, true, true, false); return chart; }
From source file:dsd.dao.RawDataDAO.java
private static Object[][] PrepareMultipleValuesForInsert(List<RawData> listOfData) { Object[][] valueArray = new Object[listOfData.size()][6]; for (int i = 0; i < listOfData.size(); i++) { valueArray[i][0] = new Float(listOfData.get(i).getWindSpeed()); valueArray[i][1] = new Float(listOfData.get(i).getWindDirection()); valueArray[i][2] = new Float(listOfData.get(i).getHydrometer()); valueArray[i][3] = new Float(listOfData.get(i).getSonar()); valueArray[i][4] = new Integer( listOfData.get(i).getSonarType() == null ? 0 : listOfData.get(i).getSonarType().getCode()); valueArray[i][5] = new Timestamp(listOfData.get(i).getTimestamp()); }/*from ww w. j a va2 s . c om*/ return valueArray; }
From source file:com.springsource.greenhouse.events.JdbcEventRepositoryTest.java
private void assertMobile(EventSession session, boolean favorite) { assertEquals("Choices in Mobile Application Development", session.getTitle()); // assertEquals(new DateTime(2010, 10, 21, 16, 45, 0, 0, DateTimeZone.UTC), session.getStartTime()); // assertEquals(new DateTime(2010, 10, 21, 18, 15, 0, 0, DateTimeZone.UTC), session.getEndTime()); assertEquals(2, session.getLeaders().size()); assertEquals("Roy Clarkson", session.getLeaders().get(0).getName()); assertEquals("Keith Donald", session.getLeaders().get(1).getName()); assertEquals(new Float(0), session.getRating()); assertEquals(favorite, session.isFavorite()); assertEquals("Junior Ballroom B", session.getRoom().getLabel()); }
From source file:junit.googlecode.genericdao.search.TrickyIssueTest.java
/** * If a property value is supposed to be of type Long but an Integer is * passed in, an error would be thrown. This was a major issue when passing * values in from Adobe Flex where we had no way to control whether a number * is passed as an Integer or Long. The latest version should be able to * deal with this issue.//ww w .jav a2s. c o m */ @SuppressWarnings("unchecked") @Test public void testNumberClassCastError() { initDB(); Search s = new Search(Person.class); s.addFilterGreaterThan("id", new Integer(0)); // id should be Long assertListEqual( new Person[] { sallyA, joeA, joeB, margaretB, mamaB, papaA, mamaA, papaB, grandpaA, grandmaA }, target.search(s)); s.clear(); s.addFilterEqual("age", new Long(40L)); assertListEqual(new Person[] { mamaA }, target.search(s)); s.clear(); s.addFilterEqual("age", new Double(10.0)); assertListEqual(new Person[] { joeA, joeB }, target.search(s)); s.clear(); s.addFilterEqual("mother.age", new Double(40.0)); assertListEqual(new Person[] { joeA, sallyA }, target.search(s)); s.clear(); s.addFilterEqual("mother.home.address", mamaA.getHome().getAddress()); assertListEqual(new Person[] { joeA, sallyA }, target.search(s)); s.clear(); s.addFilterEqual("mother.home.address.id", new Float(mamaA.getHome().getAddress().getId().floatValue())); assertListEqual(new Person[] { joeA, sallyA }, target.search(s)); s.clear(); s.addFilterIn("id", new Object[] { new Integer(joeA.getId().intValue()), new Integer(joeB.getId().intValue()) }); assertListEqual(new Person[] { joeA, joeB }, target.search(s)); s.clear(); s.addFilterIn("id", (Object[]) new Integer[] { new Integer(joeA.getId().intValue()), new Integer(joeB.getId().intValue()) }); assertListEqual(new Person[] { joeA, joeB }, target.search(s)); }
From source file:ctblocktest.CTblocktest.java
static int crossCheck(String modeName, boolean packMode, boolean zipMode, boolean numMode) { int errCount = 0; try {/*w ww . ja v a 2s.c o m*/ CTreader ctr = new CTreader(sourceFolder); // new CTreader at root folder CTinfo.setDebug(false); int j = 0; for (String chan : ctr.listChans(modeName)) { // System.err.println("Chan: "+chan+", out of: "+ctr.listChans(modeName).size()); CTdata data = ctr.getData(modeName, chan, 0., nsamp * dt, "oldest"); double[] t = data.getTime(); float[] dd; if (numMode) dd = data.getDataAsNumericF32(); else dd = data.getDataAsFloat32(); double iTime = 1460000000.; // sec for (int i = 0; i < dd.length; i++, iTime += dt) { // System.err.println("i: "+i+", j: "+j); if (dd[i] != new Float(i + j)) { if (debug) System.err.println(modeName + ": readCheck error, chan: " + chan + ": dd[" + i + "]: " + dd[i] + " vs " + new Float(i + j) + ", j: " + j); errCount++; } if (t[i] != iTime) { if (debug) System.err.println(modeName + ": readCheck error, chan: " + chan + ": t[" + i + "]: " + t[i] + " vs " + iTime + ", j: " + j); errCount++; } } j++; } } catch (Exception e) { System.err.println("Exception: " + e); } if (errCount == 0) System.err.println("readTest done: " + modeName); else System.err.println("readTest done: " + modeName + ", Errors: " + errCount); return errCount; }
From source file:com.climate.oada.dao.impl.DynamodbDAO.java
/** * Maps AWS SDK AttributeValue map to LandUnit value object. * * @param items - Map of scan result./* www.j av a 2 s . co m*/ * @return List of LandUnits. */ private List<LandUnit> mapItemsToLandUnit(List<Map<String, AttributeValue>> items) { List<LandUnit> retval = new ArrayList<LandUnit>(); for (Map<String, AttributeValue> item : items) { LandUnit lu = new LandUnit(); lu.setUnitId(new Long(item.get(LandUnit.ID_ATTR_NAME).getS())); lu.setUserId(new Long(item.get(LandUnit.USER_ID_ATTR_NAME).getS())); lu.setName(item.get(LandUnit.NAME_ATTR_NAME).getS()); lu.setFarmName(item.get(LandUnit.FARM_NAME_ATTR_NAME).getS()); lu.setClientName(item.get(LandUnit.CLIENT_NAME_ATTR_NAME).getS()); lu.setAcres(new Float(item.get(LandUnit.ID_ATTR_NAME).getS())); lu.setSource(item.get(LandUnit.SOURCE_ATTR_NAME).getS()); lu.setOtherProps(item.get(LandUnit.OTHER_PROPS_ATTR_NAME).getS()); lu.setWktBoundary(item.get(LandUnit.GEOM_ATTR_NAME).getS()); retval.add(lu); } return retval; }
From source file:com.ushahidi.swiftriver.core.api.dao.impl.JpaRiverDaoTest.java
@Test public void getDrops() { Account account = accountDao.findById(1L); DropFilter filter = new DropFilter(); List<Drop> drops = riverDao.getDrops(1L, filter, 1, 10, account); assertEquals(5, drops.size());/*from w w w .j a v a 2 s . co m*/ Drop drop = drops.get(0); assertEquals(5, drop.getId()); assertEquals(false, drop.getRead()); assertEquals("rss", drop.getChannel()); assertEquals("droplet 5 title", drop.getTitle()); assertEquals("droplet 5 content", drop.getContent()); assertEquals("5", drop.getOriginalId()); assertEquals(30, drop.getCommentCount()); assertEquals(1, drop.getIdentity().getId()); assertEquals("identity1_name", drop.getIdentity().getName()); assertEquals("identity1_avatar", drop.getIdentity().getAvatar()); assertNotNull(drop.getOriginalUrl()); assertEquals(3, drop.getOriginalUrl().getId()); assertEquals("http://www.bbc.co.uk/nature/20273855", drop.getOriginalUrl().getUrl()); assertEquals(2, drop.getTags().size()); Tag tag = drop.getTags().get(0); assertEquals(1, tag.getId()); assertEquals("Jeremy Hunt", tag.getTag()); assertEquals("person", tag.getType()); assertEquals(2, drop.getLinks().size()); Link link = drop.getLinks().get(0); assertEquals(2, link.getId()); assertEquals( "http://news.bbc.co.uk/democracylive/hi/house_of_commons/newsid_9769000/9769109.stm#sa-ns_mchannel=rss&ns_source=PublicRSS20-sa"", link.getUrl()); assertEquals(2, drop.getMedia().size()); Media media = drop.getMedia().get(0); assertEquals(1, media.getId()); assertEquals("http://gigaom2.files.wordpress.com/2012/10/datacapspercentage.jpeg", media.getUrl()); assertEquals("image", media.getType()); assertEquals(2, media.getThumbnails().size()); MediaThumbnail thumbnail = media.getThumbnails().get(0); assertEquals( "https://2bcbd22fbb0a02d76141-1680e9dfed1be27cdc47787ec5d4ef89.ssl.cf1.rackcdn.com/625dd7cb656d258b4effb325253e880631699d80345016e9e755b4a04341cda1.peg", thumbnail.getUrl()); assertEquals(80, thumbnail.getSize()); assertEquals(2, drop.getPlaces().size()); Place place = drop.getPlaces().get(0); assertEquals(1, place.getId()); assertEquals("Wales", place.getPlaceName()); assertEquals(new Float(146.11), place.getLongitude()); assertEquals(new Float(-33), place.getLatitude()); drop = drops.get(3); assertEquals(2, drop.getId()); assertEquals(2, drop.getForms().size()); RiverDropForm form = (RiverDropForm) drop.getForms().get(0); assertEquals(1, (long) form.getId()); List<RiverDropFormField> values = form.getValues(); assertEquals(3, values.size()); assertEquals(1, (long) values.get(0).getField().getId()); assertEquals("[\"English\"]", values.get(0).getValue()); assertEquals(2, (long) values.get(1).getField().getId()); assertEquals("\"Journalist\"", values.get(1).getValue()); assertEquals(3, (long) values.get(2).getField().getId()); assertEquals("\"Kenyans\"", values.get(2).getValue()); }
From source file:com.amazonaws.services.iot.demo.danbo.rpi.PiezoBuzzer.java
public String[] play(String songData) throws Exception { ArrayList<Integer> pitches = new ArrayList<Integer>(); ArrayList<Float> durations = new ArrayList<Float>(); int default_dur = 4; int default_oct = 6; int bpm = 63; int num;/*from w w w . j av a 2 s.co m*/ long wholenote; long duration; int note; int scale; int p = 0; while (songData.charAt(p) != ':') { p++; } p++; if (songData.charAt(p) == 'd') { p++; p++; num = 0; while (Character.isDigit(songData.charAt(p))) { num = (num * 10) + Integer.valueOf(songData.charAt(p++) - '0'); } if (num > 0) { default_dur = num; } p++; } if (songData.charAt(p) == 'o') { p++; p++; num = Integer.valueOf(songData.charAt(p++) - '0'); if (num >= 3 && num <= 7) { default_oct = num; } p++; } if (songData.charAt(p) == 'b') { p++; p++; num = 0; while (Character.isDigit(songData.charAt(p))) { num = (num * 10) + Integer.valueOf(songData.charAt(p++) - '0'); } bpm = num; p++; } wholenote = (60 * 1000L / bpm) * 4; while (p < songData.length()) { num = 0; while (Character.isDigit(songData.charAt(p))) { num = (num * 10) + Integer.valueOf(songData.charAt(p++) - '0'); } if (num != 0) { duration = wholenote / num; } else { duration = wholenote / default_dur; } note = 0; switch (songData.charAt(p)) { case 'c': note = 1; break; case 'd': note = 3; break; case 'e': note = 5; break; case 'f': note = 6; break; case 'g': note = 8; break; case 'a': note = 10; break; case 'b': note = 12; break; case 'p': note = 0; default: note = 0; } p++; if (songData.charAt(p) == '#') { note++; p++; } if (songData.charAt(p) == '.') { duration += duration / 2; p++; } if (Character.isDigit(songData.charAt(p))) { scale = Integer.valueOf(songData.charAt(p) - '0'); p++; } else { scale = default_oct; } scale += OCTAVE_OFFSET; if (songData.charAt(p) == ',') { p++; } if (note != 0) { int n = note_pitch[(scale - 4) * 12 + note]; pitches.add(new Integer(n)); durations.add(new Float(duration) / new Float(1000)); } else { pitches.add(new Integer(0)); durations.add(new Float(duration) / new Float(1000)); } } String[] returnVal = new String[2]; returnVal[0] = pitches.toString().substring(1, pitches.toString().length() - 1).replaceAll(" ", ""); returnVal[1] = durations.toString().substring(1, durations.toString().length() - 1).replaceAll(" ", ""); return returnVal; }
From source file:com.streamreduce.util.GoogleAnalyticsClient.java
public JSONObject getProfileMetrics(String profileId) throws IOException { String formattedToday = DATE_TIME_FORMATTER.print(new DateTime()); Analytics analytics = initializeAnalytics(); GaData data = analytics.data().ga()/*from w w w . j a v a 2s . c o m*/ .get("ga:" + profileId, formattedToday, formattedToday, "ga:visitors,ga:newVisits").execute(); if (CollectionUtils.isEmpty(data.getRows())) { return null; } JSONObjectBuilder builder = new JSONObjectBuilder(); builder.add("id", profileId); int columnIndex = 0; for (GaData.ColumnHeaders header : data.getColumnHeaders()) { JSONObjectBuilder metric = new JSONObjectBuilder(); String metricName = normalizeMetricName(header.getName()); metric.add("metric", metricName); metric.add("id", profileId); Set<String> hashtags = new HashSet<>(); hashtags.add(metricName.toLowerCase()); for (List<String> row : data.getRows()) { for (int rowIndex = 0; rowIndex < row.size(); rowIndex++) { if (rowIndex == columnIndex) { metric.add("data", new Float(row.get(rowIndex))); } } } hashtags.add("googleanalytics"); metric.add("hashtags", hashtags); builder.append("metrics", metric.build()); columnIndex++; } return builder.build(); }
From source file:de.iteratec.svg.SvgGraphicWriter.java
/** * Rasterizes the generated SVG Document to a JGEP and writes in onto the given output stream. * //from www . j ava2 s . co m * @param document * SVG-{@link Document} to write as JPEG * @param outputStream * The stream to write to. * @throws SvgExportException * Iff the write operation was unsuccessful. */ public static void writeToJPEG(org.w3c.dom.Document document, OutputStream outputStream) throws SvgExportException { JPEGTranscoder t = new JPEGTranscoder(); LOGGER.debug("Trying to write the document to the output stram as JPEG."); // Set the transcoding hints. t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1)); setScaledImageTranscoderDimensions(t, getWidthFromDom(document), getHeightFromDom(document)); write(document, outputStream, t); }