List of usage examples for java.util TreeMap keySet
public Set<K> keySet()
From source file:com.itemanalysis.jmetrik.graph.density.DensityAnalysis.java
public XYSeriesCollection summarize() throws SQLException, IllegalArgumentException { Statement stmt = null;//from ww w . jav a 2 s.com ResultSet rs = null; TreeMap<String, ResizableDoubleArray> data = new TreeMap<String, ResizableDoubleArray>(); //set progress bar information int nrow = 0; JmetrikPreferencesManager pref = new JmetrikPreferencesManager(); String dbType = pref.getDatabaseType(); if (DatabaseType.APACHE_DERBY.toString().equals(dbType)) { JmetrikDatabaseFactory dbFactory = new JmetrikDatabaseFactory(DatabaseType.APACHE_DERBY); nrow = dao.getRowCount(conn, tableName); } else { //add other databases here when functionality is added } maxProgress = (double) nrow; Table sqlTable = new Table(tableName.getNameForDatabase()); SelectQuery select = new SelectQuery(); select.addColumn(sqlTable, variable.getName().nameForDatabase()); if (hasGroupingVariable) select.addColumn(sqlTable, groupVar.getName().nameForDatabase()); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = stmt.executeQuery(select.toString()); String conditionalName = ""; ResizableDoubleArray cData = null; double value = Double.NaN; while (rs.next()) { if (groupVar != null) { String groupName = rs.getString(groupVar.getName().nameForDatabase()); if (rs.wasNull()) { groupName = ""; } conditionalName = groupName; } else { conditionalName = "Series 1"; } cData = data.get(conditionalName); if (cData == null) { cData = new ResizableDoubleArray((int) maxProgress); data.put(conditionalName, cData); } value = rs.getDouble(variable.getName().nameForDatabase()); if (!rs.wasNull()) { cData.addElement(value); } updateProgress(); } rs.close(); stmt.close(); String kType = command.getSelectOneOption("kernel").getSelectedArgument(); double adjustment = command.getFreeOption("adjust").getDouble(); KernelFactory kernelFactory = new KernelFactory(kType); KernelFunction kernelFunction = kernelFactory.getKernelFunction(); Bandwidth bandwidth = null; KernelDensity density = null; UniformDistributionApproximation uniform = null; Min min = new Min(); Max max = new Max(); double[] x = null; this.firePropertyChange("progress-ind-on", null, null); XYSeriesCollection seriesCollection = new XYSeriesCollection(); XYSeries series = null; for (String s : data.keySet()) { series = new XYSeries(s); x = data.get(s).getElements(); bandwidth = new ScottsBandwidth(x, adjustment); uniform = new UniformDistributionApproximation(min.evaluate(x), max.evaluate(x), KERNEL_POINTS); density = new KernelDensity(kernelFunction, bandwidth, uniform); double[] dens = density.evaluate(x); double[] points = density.getPoints(); for (int i = 0; i < dens.length; i++) { series.add(points[i], dens[i]); } seriesCollection.addSeries(series); } return seriesCollection; }
From source file:net.spfbl.core.Analise.java
public TreeSet<String> getResultFullSet() throws InterruptedException { TreeMap<String, String> map = new TreeMap<String, String>(); whiteFullSet(map);//w w w .ja v a 2 s. c o m File resultFile = getResultFile(); if (resultFile.exists()) { try { FileReader fileReader = new FileReader(resultFile); BufferedReader bufferedReader = new BufferedReader(fileReader); try { String line; while ((line = bufferedReader.readLine()) != null) { int index = line.indexOf(' '); if (index > 0) { String ip = line.substring(0, index); try { if (containsResultSet(ip)) { String result = line.substring(index + 1); map.put(ip, result); } } catch (InterruptedException ex) { Server.logError(ex); } } } } finally { bufferedReader.close(); } } catch (Exception ex) { Server.logError(ex); } } TreeSet<String> set = new TreeSet<String>(); for (String ip : map.keySet()) { String result = map.get(ip); set.add(ip + " " + result); } return set; }
From source file:com.mfizz.observer.core.ServiceObserver.java
private void doSnapshotAll(SnapshotAllResult result) throws Exception { ///*from w w w . j a va2s . c om*/ // create list of snapshots that will be executed // ArrayList<SnapshotTask> snapshotTasks = new ArrayList<SnapshotTask>(); for (Observer<D> observer : observers.values()) { snapshotTasks.add(new SnapshotTask(observer, result.beginTimestamp)); } result.snapshotsAttempted = snapshotTasks.size(); // this will run all the update tasks and wait for them all to finish executor.invokeAll(snapshotTasks); // create an aggregate for each group TreeMap<String, ObserveAggregateSnapshot<A>> aggs = new TreeMap<String, ObserveAggregateSnapshot<A>>(); // process deltas from each observer for (Observer<D> observer : observers.values()) { // determine if last snapshot completed or failed if (observer.getConsecutiveSnapshotCompletedCount() > 0) { result.snapshotsCompleted++; } else { result.snapshotsFailed++; } // was this the first snapshot attempt for this observer? long snapshotAttempts = observer.getSnapshotAttemptCounter(); // each group will aggregate the same delta snapshot from each observer ObserveDeltaSnapshot<D> ods = observer.getDeltaSnapshot(); if (ods == null) { //logger.debug("delta snapshot for observer {} was null", observer.getName()); SnapshotException e = observer.getException(); if (e == null) { if (snapshotAttempts <= 1) { // first runs we don't expect any deltas } else { logger.error( "observer [{}] for service [{}] had null delta AND exception values (previous snapshot maybe failed?)", observer.getName(), getServiceName()); } } else { // this is now logged in SnapshotTask below //logger.warn("exception during snapshot for observer " + observer.getName(), e); } } else { // period should be the same across all deltas TimePeriod period = ods.getPeriod(); // TODO: verify periods match each other as safety check? // create or get aggregate for each group this observer belongs to for (String group : observer.configuration.getGroups()) { ObserveAggregateSnapshot<A> oas = aggs.get(group); if (oas == null) { oas = new ObserveAggregateSnapshot<A>(period, aggregateClass.newInstance()); aggs.put(group, oas); } oas.add(observer.getName(), ods.getData()); } } } if (snapshotAllAttemptedCounter.get() > 1 && aggs.isEmpty()) { logger.warn("snapshotAll() for service [{}] generated no aggregated snapshots!", this.getServiceName()); } // at this point, the new snapshots from each observer have generated // new aggregates for this point-in-time -- add this to our rolling time series for (String group : aggs.keySet()) { // last aggregate snapshot ObserveAggregateSnapshot<A> oas = aggs.get(group); // get or create new series of aggregate snapshots for each group TimeSeries<ObserveAggregateSnapshot<A>> aggseries = snapshots.get(group); if (aggseries == null) { // figure out capacity of time series (retentionTime / step + fudgeFactor) long retentionMillis = getRetentionMillis(); int initialCapacity = (int) (retentionMillis / this.serviceConfig.getStepMillis()) + 2; logger.info( "Creating new TimeSeries for service [{}] group [{}] with retentionMillis=" + retentionMillis + "; initialCapacity=" + initialCapacity, getServiceName(), group); aggseries = new TimeSeries<ObserveAggregateSnapshot<A>>(retentionMillis, initialCapacity); snapshots.put(group, aggseries); } // add aggregate snapshot to the time series for each group // this will also prune old snapshots that are older than the retention period // the timestamp of the aggregate becomes the relative "now" timestamp for calculating retentions // this is how we'll always at least keep "current" times aggseries.add(oas, oas.getTimestamp()); // create an updated summary for each interval for this group SummaryGroupFactory<S, A> sfg = new SummaryGroupFactory<S, A>(oas.getTimestamp(), this.summaryClass, this.serviceConfig.getPeriods()); sfg.beginAll(); Iterator<ObserveAggregateSnapshot<A>> it = aggseries.getSeries().iterator(); while (it.hasNext()) { ObserveAggregateSnapshot<A> tempoas = it.next(); sfg.summarize(tempoas.getPeriod(), tempoas.getAggregate()); } sfg.completeAll(); SummaryGroup<S> sg = sfg.createSummaryGroup(); summary.put(group, sg); } }
From source file:jp.zippyzip.impl.GeneratorServiceImpl.java
public void updateZips() { Date timestamp = getLzhDao().getZipInfo().getTimestamp(); LinkedList<Pref> prefs = getPrefs(); TreeMap<String, TreeSet<String>> zips = new TreeMap<String, TreeSet<String>>(); int cnt = 0;/*from w w w. j a v a 2 s . c o m*/ try { for (Pref pref : prefs) { ParentChild data = getParentChildDao().get("pre" + pref.getCode()); if (data != null) { for (String json : data.getChildren()) { JSONArray ja = new JSONArray(json); for (int i = 0; i < ja.length(); ++i) { JSONObject jo = ja.getJSONObject(i); String zip = jo.optString("zip", ""); String key = jo.optString("key", ""); if (!zips.containsKey(zip)) { zips.put(zip, new TreeSet<String>()); } zips.get(zip).add(key); } } } } ParentChild data = null; LinkedList<String> zip1s = new LinkedList<String>(); String prev = null; for (String code : zips.keySet()) { String zip1 = code.substring(0, 3); String zip2 = code.substring(3); if (!zip1.equals(prev)) { if (data != null) { getParentChildDao().store(data); } LinkedList<String> parents = new LinkedList<String>(); parents.add(zip1); data = new ParentChild(zip1, timestamp, parents); zip1s.add(new JSONStringer().object().key("zip1").value(zip1).endObject().toString()); prev = zip1; } for (String key : zips.get(code)) { data.getChildren().add(new JSONStringer().object().key("zip2").value(zip2).key("key").value(key) .endObject().toString()); ++cnt; } } if (data != null) { getParentChildDao().store(data); } getParentChildDao().store(new ParentChild("zip1s", timestamp, new LinkedList<String>(), zip1s)); log.info("count:" + cnt); } catch (JSONException e) { log.log(Level.WARNING, "", e); } return; }
From source file:org.sakaiproject.tool.assessment.ui.bean.author.AssessmentSettingsBean.java
/** * Popluate the select item list of extended time targets * //from www. j a v a 2s.co m * @return */ public SelectItem[] initExtendedTimeTargets() { SelectItem[] extTimeSelectItems = null; Site site = null; try { site = SiteService.getSite(ToolManager.getCurrentPlacement().getContext()); Collection groups = site.getGroups(); SectionAwareness sectionAwareness = PersistenceService.getInstance().getSectionAwareness(); // List sections = sectionAwareness.getSections(site.getId()); List enrollments = sectionAwareness.getSiteMembersInRole(site.getId(), Role.STUDENT); // Treemaps are used here because they auto-sort TreeMap SectionTargets = new TreeMap<String, String>(); TreeMap groupTargets = new TreeMap<String, String>(); TreeMap studentTargets = new TreeMap<String, String>(); // Add groups to target set if (groups != null && groups.size() > 0) { Iterator groupIter = groups.iterator(); while (groupIter.hasNext()) { Group group = (Group) groupIter.next(); if (!group.getTitle().startsWith("Access: ")) // do not // include // Lessons // groups groupTargets.put("Group: " + group.getTitle(), group.getId()); } } // Add students to target set if (enrollments != null && enrollments.size() > 0) { for (Iterator iter = enrollments.iterator(); iter.hasNext();) { EnrollmentRecord enrollmentRecord = (EnrollmentRecord) iter.next(); String userId = enrollmentRecord.getUser().getUserUid(); String userDisplayName = enrollmentRecord.getUser().getSortName(); studentTargets.put(userDisplayName, userId); } } // Add targets to selectItem array. We put the alpha name in as the // key so it would // be alphabetized. Now we pull it out and build the select item // list. int listSize = 1 + groupTargets.size() + studentTargets.size(); extTimeSelectItems = new SelectItem[listSize]; extTimeSelectItems[0] = new SelectItem("1", "Select User/Group"); int selectCount = 1; // Add in groups to select item list Set keySet = groupTargets.keySet(); Iterator iter = keySet.iterator(); while (iter.hasNext()) { String alphaName = (String) iter.next(); String sakaiId = (String) groupTargets.get(alphaName); extTimeSelectItems[selectCount++] = new SelectItem(sakaiId, alphaName); } // Add in students to select item list keySet = studentTargets.keySet(); iter = keySet.iterator(); while (iter.hasNext()) { String alphaName = (String) iter.next(); String sakaiId = (String) studentTargets.get(alphaName); extTimeSelectItems[selectCount++] = new SelectItem(sakaiId, alphaName); } } catch (IdUnusedException ex) { // No site available } return extTimeSelectItems; }
From source file:net.triptech.metahive.messaging.JmsMetahiveContributionListener.java
private int processSubmission(final Submission submission) { int processCount = 0; // Build the validated data grid ValidatedDataGrid dataGrid = new ValidatedDataGrid(submission.getRawDataGrid()); MetahivePreferences prefs = MetahivePreferences.load(); TreeMap<Integer, Definition> definitions = new TreeMap<Integer, Definition>(); int columnIndex = 0; int primaryIndex = 0; int secondaryIndex = 0; int tertiaryIndex = 0; for (ValidatedField field : dataGrid.getHeaderFields()) { logger.info("Field valid: " + field.isValid()); logger.info("Id field: " + field.isIdField()); logger.info("Field value: " + field.getValue()); logger.info("Column index: " + columnIndex); if (field.isValid()) { if (field.isIdField()) { if (StringUtils.equalsIgnoreCase(prefs.getPrimaryRecordName(), field.getValue())) { primaryIndex = columnIndex; }//from ww w. j ava 2s . co m if (StringUtils.equalsIgnoreCase(prefs.getSecondaryRecordName(), field.getValue())) { secondaryIndex = columnIndex; } if (StringUtils.equalsIgnoreCase(prefs.getTertiaryRecordName(), field.getValue())) { tertiaryIndex = columnIndex; } } else { Definition definition = Definition.findDefinitionByNameEquals(field.getValue()); definitions.put(columnIndex, definition); } } columnIndex++; } for (ValidatedRow row : dataGrid.getRows()) { if (row.isValid()) { // Load the record String primaryRecord = ""; String secondaryRecord = ""; String tertiaryRecord = ""; primaryRecord = row.getFields().get(primaryIndex).getValue(); if (secondaryIndex > 0) { secondaryRecord = row.getFields().get(secondaryIndex).getValue(); } if (tertiaryIndex > 0) { tertiaryRecord = row.getFields().get(tertiaryIndex).getValue(); } if (StringUtils.isBlank(secondaryRecord) && StringUtils.isNotBlank(prefs.getSecondaryRecordDefault())) { secondaryRecord = prefs.getSecondaryRecordDefault(); } if (StringUtils.isBlank(tertiaryRecord) && StringUtils.isNotBlank(prefs.getTertiaryRecordDefault())) { tertiaryRecord = prefs.getTertiaryRecordDefault(); } if (StringUtils.isNotBlank(secondaryRecord)) { secondaryRecord = KeyValueCalculator.parseRecordId(secondaryRecord); } if (StringUtils.isNotBlank(tertiaryRecord)) { tertiaryRecord = KeyValueCalculator.parseRecordId(tertiaryRecord); } logger.info("Primary record: " + primaryRecord); logger.info("Secondary record: " + secondaryRecord); logger.info("Tertiary record: " + tertiaryRecord); Record record = Record.findRecordByRecordIdEquals(primaryRecord); logger.info("Record id: " + record.getId()); if (record != null) { for (int index : definitions.keySet()) { Definition definition = definitions.get(index); ValidatedField cell = row.getFields().get(index); if (cell.isValid() && StringUtils.isNotBlank(cell.getValue())) { SubmittedField field = new SubmittedField(); field.setDefinition(definition); field.setRecord(record); field.setSubmission(submission); field.setPrimaryRecordId(primaryRecord); field.setSecondaryRecordId(secondaryRecord); field.setTertiaryRecordId(tertiaryRecord); field.setValue(cell.getValue().trim()); field.persist(); field.flush(); processCount++; logger.info("Submitted field id: " + field.getId()); JmsRecalculateRequest req = new JmsRecalculateRequest(field); keyValueGenerationTemplate.convertAndSend(req); } } } } } return processCount; }
From source file:com.jtstand.swing.StatsPanel.java
private XYIntervalSeriesCollection createIntervalXYDatasetDistribution(boolean inverted) { //create the population map TreeMap<String, int[]> map = new TreeMap<String, int[]>(); Iterator<TestStepInstance> it = getFilteringIterator(); while (it.hasNext()) { TestStepInstance step = it.next(); String groupName = getGroupName(step); int[] population = map.get(groupName); if (population == null) { population = new int[numberOfCategories]; for (int i = 0; i < numberOfCategories; i++) { population[i] = 0;//w w w .j a v a 2 s. c om } map.put(groupName, population); } //Stat stat=catstats.get(groupName); Stat stat = allstat; if (stat != null) { Number num = getNumber(step); if (num != null) { double val = num.doubleValue(); int category; if (stat.getStandardDeviation() != 0) { category = (int) (numberOfCategories / 2.0 + numberOfCategories * (val - stat.getAverage()) / (getNumberOfSigmas(stat) * stat.getStandardDeviation())); } else { category = numberOfCategories / 2; } if (category >= 0 && category < numberOfCategories) { population[category]++; } // else { // System.out.println("Value: " + val + " Category: " + category); // } } } else { log.error("There is no stat for:" + groupName); } } XYIntervalSeriesCollection dataset = new XYIntervalSeriesCollection(); int cat = 0; int[] prev = new int[numberOfCategories]; for (int i = 0; i < prev.length; i++) { prev[i] = 0; } for (Iterator<String> it2 = map.keySet().iterator(); it2.hasNext(); cat++) { String groupName = it2.next(); int[] population = map.get(groupName); XYIntervalSeries pop = new XYIntervalSeries(groupName); if (inverted) { for (int i = numberOfCategories - 1; i >= 0; i--) { if (population[i] != 0) { // pop.add(midValue(i), leftValue(i, cat, map.size()), rightValue(i, cat, map.size()), population[i], prev[i], prev[i] + population[i]); pop.add(midValue(i), leftValue(i), rightValue(i), population[i], prev[i], prev[i] + population[i]); prev[i] = prev[i] + population[i]; } } } else { for (int i = 0; i < numberOfCategories; i++) { if (population[i] != 0) { // pop.add(midValue(i), leftValue(i, cat, map.size()), rightValue(i, cat, map.size()), population[i], prev[i], prev[i] + population[i]); pop.add(midValue(i), leftValue(i), rightValue(i), population[i], prev[i], prev[i] + population[i]); prev[i] = prev[i] + population[i]; } } } dataset.addSeries(pop); } return dataset; }
From source file:jp.zippyzip.impl.GeneratorServiceImpl.java
public void preZips() { Date timestamp = getLzhDao().getZipInfo().getTimestamp(); LinkedList<Pref> prefs = getPrefs(); LinkedList<City> cities = getCities(); try {// w ww . ja va 2 s .c o m for (Pref pref : prefs) { TreeMap<String, TreeSet<String>> zips = new TreeMap<String, TreeSet<String>>(); for (City city : cities) { if (!city.getCode().startsWith(pref.getCode())) { continue; } ParentChild data = getParentChildDao().get(city.getCode()); if (data != null) { for (String json : data.getChildren()) { String zip = new JSONObject(json).optString("code", ""); if (!zips.containsKey(zip)) { zips.put(zip, new TreeSet<String>()); } zips.get(zip).add(city.getCode()); } } data = getParentChildDao().get(city.getCode() + "c"); if (data != null) { for (String json : data.getChildren()) { String zip = new JSONObject(json).optString("code", ""); if (!zips.containsKey(zip)) { zips.put(zip, new TreeSet<String>()); } zips.get(zip).add(city.getCode() + "c"); } } } StringBuilder rec = new StringBuilder("["); LinkedList<String> list = new LinkedList<String>(); for (String zip : zips.keySet()) { for (String key : zips.get(zip)) { rec.append(new JSONStringer().object().key("zip").value(zip).key("key").value(key) .endObject().toString()); if (rec.length() > 400) { rec.append("]"); list.add(rec.toString()); rec = new StringBuilder("["); } else { rec.append(","); } } } if (rec.length() > 1) { rec.append("]"); list.add(rec.toString()); } getParentChildDao() .store(new ParentChild("pre" + pref.getCode(), timestamp, new LinkedList<String>(), list)); log.info(pref.getCode() + ":" + list.size()); } } catch (JSONException e) { log.log(Level.WARNING, "", e); } return; }
From source file:edu.hawaii.soest.hioos.isus.ISUSSource.java
/** * A method that processes the data object passed and flushes the * data to the DataTurbine given the sensor properties in the XMLConfiguration * passed in.// w w w . j a v a 2s . co m * * @param xmlConfig - the XMLConfiguration object containing the list of * sensor properties * @param frameMap - the parsed data as a HierarchicalMap object */ public boolean process(XMLConfiguration xmlConfig, HierarchicalMap frameMap) { logger.debug("ISUSSource.process() called."); // do not execute the stream if there is no connection if (!isConnected()) return false; boolean success = false; try { // add channels of data that will be pushed to the server. // Each sample will be sent to the Data Turbine as an rbnb frame. Information // on each channel is found in the XMLConfiguration file (email.account.properties.xml) // and the StorXParser object (to get the data string) ChannelMap rbnbChannelMap = new ChannelMap(); // used to flush channels ChannelMap registerChannelMap = new ChannelMap(); // used to register channels int channelIndex = 0; String sensorName = null; String sensorSerialNumber = null; String sensorDescription = null; boolean isImmersed = false; String[] calibrationURLs = null; String calibrationURL = null; String type = null; List sensorList = xmlConfig.configurationsAt("account.logger.sensor"); for (Iterator sIterator = sensorList.iterator(); sIterator.hasNext();) { // HierarchicalConfiguration sensorConfig = (HierarchicalConfiguration) sIterator.next(); sensorSerialNumber = sensorConfig.getString("serialNumber"); // find the correct sensor configuration properties if (sensorSerialNumber.equals(frameMap.get("serialNumber"))) { sensorName = sensorConfig.getString("name"); sensorDescription = sensorConfig.getString("description"); isImmersed = new Boolean(sensorConfig.getString("isImmersed")).booleanValue(); calibrationURLs = sensorConfig.getStringArray("calibrationURL"); type = (String) frameMap.get("type"); // find the correct calibrationURL from the list given the type for (String url : calibrationURLs) { if (url.indexOf(type) > 0) { calibrationURL = url; break; } else { logger.debug("There was no match for " + type); } } // get a Calibration instance to interpret raw sensor values Calibration calibration = new Calibration(); if (calibration.parse(calibrationURL)) { // Build the RBNB channel map // get the sample date and convert it to seconds since the epoch Date frameDate = (Date) frameMap.get("date"); Calendar frameDateTime = Calendar.getInstance(); frameDateTime.setTime(frameDate); double sampleTimeAsSecondsSinceEpoch = (double) (frameDateTime.getTimeInMillis() / 1000); // and create a string formatted date for the given time zone DATE_FORMAT.setTimeZone(TZ); String frameDateAsString = DATE_FORMAT.format(frameDate).toString(); // get the sample data from the frame map ByteBuffer rawFrame = (ByteBuffer) frameMap.get("rawFrame"); ISUSFrame isusFrame = (ISUSFrame) frameMap.get("parsedFrameObject"); String serialNumber = isusFrame.getSerialNumber(); String sampleDate = isusFrame.getSampleDate(); String sampleTime = isusFrame.getSampleTime(); SimpleDateFormat dtFormat = new SimpleDateFormat(); Date sampleDateTime = isusFrame.getSampleDateTime(); dtFormat.setTimeZone(TimeZone.getTimeZone("UTC")); dtFormat.applyPattern("MM/dd/yy"); String sampleDateUTC = dtFormat.format(sampleDateTime); dtFormat.applyPattern("HH:mm:ss"); String sampleTimeUTC = dtFormat.format(sampleDateTime); dtFormat.setTimeZone(TimeZone.getTimeZone("HST")); dtFormat.applyPattern("MM/dd/yy"); String sampleDateHST = dtFormat.format(sampleDateTime); dtFormat.applyPattern("HH:mm:ss"); String sampleTimeHST = dtFormat.format(sampleDateTime); dtFormat.applyPattern("dd-MMM-yy HH:mm"); String sampleDateTimeHST = dtFormat.format(sampleDateTime); double rawNitrogenConcentration = isusFrame.getNitrogenConcentration(); double rawAuxConcentration1 = isusFrame.getAuxConcentration1(); double rawAuxConcentration2 = isusFrame.getAuxConcentration2(); double rawAuxConcentration3 = isusFrame.getAuxConcentration3(); double rawRmsError = isusFrame.getRmsError(); double rawInsideTemperature = isusFrame.getInsideTemperature(); double rawSpectrometerTemperature = isusFrame.getSpectrometerTemperature(); double rawLampTemperature = isusFrame.getLampTemperature(); int rawLampTime = isusFrame.getLampTime(); double rawHumidity = isusFrame.getHumidity(); double rawLampVoltage12 = isusFrame.getLampVoltage12(); double rawInternalPowerVoltage5 = isusFrame.getInternalPowerVoltage5(); double rawMainPowerVoltage = isusFrame.getMainPowerVoltage(); double rawReferenceAverage = isusFrame.getReferenceAverage(); double rawReferenceVariance = isusFrame.getReferenceVariance(); double rawSeaWaterDarkCounts = isusFrame.getSeaWaterDarkCounts(); double rawSpectrometerAverage = isusFrame.getSpectrometerAverage(); int checksum = isusFrame.getChecksum(); //// apply calibrations to the observed data double nitrogenConcentration = calibration.apply(rawNitrogenConcentration, isImmersed, "NITRATE"); double auxConcentration1 = calibration.apply(rawAuxConcentration1, isImmersed, "AUX1"); double auxConcentration2 = calibration.apply(rawAuxConcentration2, isImmersed, "AUX2"); double auxConcentration3 = calibration.apply(rawAuxConcentration3, isImmersed, "AUX3"); double rmsError = calibration.apply(rawRmsError, isImmersed, "RMSe"); double insideTemperature = calibration.apply(rawInsideTemperature, isImmersed, "T_INT"); double spectrometerTemperature = calibration.apply(rawSpectrometerTemperature, isImmersed, "T_SPEC"); double lampTemperature = calibration.apply(rawLampTemperature, isImmersed, "T_LAMP"); int lampTime = rawLampTime; double humidity = calibration.apply(rawHumidity, isImmersed, "HUMIDITY"); double lampVoltage12 = calibration.apply(rawLampVoltage12, isImmersed, "VOLT_12"); double internalPowerVoltage5 = calibration.apply(rawInternalPowerVoltage5, isImmersed, "VOLT_5"); double mainPowerVoltage = calibration.apply(rawMainPowerVoltage, isImmersed, "VOLT_MAIN"); double referenceAverage = calibration.apply(rawReferenceAverage, isImmersed, "REF_AVG"); double referenceVariance = calibration.apply(rawReferenceVariance, isImmersed, "REF_STD"); double seaWaterDarkCounts = calibration.apply(rawSeaWaterDarkCounts, isImmersed, "SW_DARK"); double spectrometerAverage = calibration.apply(rawSpectrometerAverage, isImmersed, "SPEC_AVG"); // iterate through the individual wavelengths List<String> variableNames = calibration.getVariableNames(); TreeMap<String, Double> wavelengthsMap = new TreeMap<String, Double>(); Collections.sort(variableNames); int rawWavelengthCounts = 0; int count = 1; for (String name : variableNames) { // just handle the wavelength channels if (name.startsWith("UV_")) { rawWavelengthCounts = isusFrame.getChannelWavelengthCounts(count); double value = calibration.apply(rawWavelengthCounts, isImmersed, name); count++; wavelengthsMap.put(name, new Double(value)); } } String sampleString = ""; sampleString += sampleDate + "\t"; sampleString += sampleDateUTC + "\t"; sampleString += sampleTime + "\t"; sampleString += sampleTimeUTC + "\t"; sampleString += sampleDateHST + "\t"; sampleString += sampleTimeHST + "\t"; sampleString += sampleDateTimeHST + "\t"; sampleString += String.format("%-15.11f", nitrogenConcentration) + "\t"; //sampleString += String.format("%15.11f", auxConcentration1) + "\t"; //sampleString += String.format("%15.11f", auxConcentration2) + "\t"; //sampleString += String.format("%15.11f", auxConcentration3) + "\t"; sampleString += String.format("%15.11f", rmsError) + "\t"; sampleString += String.format("%15.11f", insideTemperature) + "\t"; sampleString += String.format("%15.11f", spectrometerTemperature) + "\t"; sampleString += String.format("%15.11f", lampTemperature) + "\t"; sampleString += String.format("%6d", lampTime) + "\t"; sampleString += String.format("%15.11f", humidity) + "\t"; sampleString += String.format("%15.11f", lampVoltage12) + "\t"; sampleString += String.format("%15.11f", internalPowerVoltage5) + "\t"; sampleString += String.format("%15.11f", mainPowerVoltage) + "\t"; sampleString += String.format("%15.11f", referenceAverage) + "\t"; sampleString += String.format("%15.11f", referenceVariance) + "\t"; sampleString += String.format("%15.11f", seaWaterDarkCounts) + "\t"; sampleString += String.format("%15.11f", spectrometerAverage) + "\t"; Set<String> wavelengths = wavelengthsMap.keySet(); Iterator wIterator = wavelengths.iterator(); while (wIterator.hasNext()) { String name = (String) wIterator.next(); Double wavelengthValue = (Double) wavelengthsMap.get(name); sampleString += String.format("%6d", wavelengthValue.intValue()) + "\t"; channelIndex = registerChannelMap.Add(name); registerChannelMap.PutUserInfo(channelIndex, "units=counts"); channelIndex = rbnbChannelMap.Add(name); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { wavelengthValue.doubleValue() }); } sampleString += String.format("%03d", checksum); sampleString += "\n"; // add the sample timestamp to the rbnb channel map //registerChannelMap.PutTime(sampleTimeAsSecondsSinceEpoch, 0d); rbnbChannelMap.PutTime(sampleTimeAsSecondsSinceEpoch, 0d); // add the BinaryRawSatlanticFrameData channel to the channelMap channelIndex = registerChannelMap.Add("BinaryRawSatlanticFrameData"); registerChannelMap.PutUserInfo(channelIndex, "units=none"); channelIndex = rbnbChannelMap.Add("BinaryRawSatlanticFrameData"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsByteArray(channelIndex, rawFrame.array()); // add the DecimalASCIISampleData channel to the channelMap channelIndex = registerChannelMap.Add(getRBNBChannelName()); registerChannelMap.PutUserInfo(channelIndex, "units=none"); channelIndex = rbnbChannelMap.Add(getRBNBChannelName()); rbnbChannelMap.PutMime(channelIndex, "text/plain"); rbnbChannelMap.PutDataAsString(channelIndex, sampleString); // add the serialNumber channel to the channelMap channelIndex = registerChannelMap.Add("serialNumber"); registerChannelMap.PutUserInfo(channelIndex, "units=none"); channelIndex = rbnbChannelMap.Add("serialNumber"); rbnbChannelMap.PutMime(channelIndex, "text/plain"); rbnbChannelMap.PutDataAsString(channelIndex, serialNumber); // add the sampleDateUTC channel to the channelMap channelIndex = registerChannelMap.Add("sampleDateUTC"); registerChannelMap.PutUserInfo(channelIndex, "units=YYYYDDD"); channelIndex = rbnbChannelMap.Add("sampleDateUTC"); rbnbChannelMap.PutMime(channelIndex, "text/plain"); rbnbChannelMap.PutDataAsString(channelIndex, sampleDate); // add the sampleTimeUTC channel to the channelMap channelIndex = registerChannelMap.Add("sampleTimeUTC"); registerChannelMap.PutUserInfo(channelIndex, "units=hh.hhhhhh"); channelIndex = rbnbChannelMap.Add("sampleTimeUTC"); rbnbChannelMap.PutMime(channelIndex, "text/plain"); rbnbChannelMap.PutDataAsString(channelIndex, sampleTimeUTC); // add the nitrogenConcentration channel to the channelMap channelIndex = registerChannelMap.Add("nitrogenConcentration"); registerChannelMap.PutUserInfo(channelIndex, "units=uM"); channelIndex = rbnbChannelMap.Add("nitrogenConcentration"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { nitrogenConcentration }); // add the auxConcentration1 channel to the channelMap channelIndex = registerChannelMap.Add("auxConcentration1"); registerChannelMap.PutUserInfo(channelIndex, "units=none"); channelIndex = rbnbChannelMap.Add("auxConcentration1"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { auxConcentration1 }); // add the auxConcentration3 channel to the channelMap channelIndex = registerChannelMap.Add("auxConcentration2"); registerChannelMap.PutUserInfo(channelIndex, "units=none"); channelIndex = rbnbChannelMap.Add("auxConcentration2"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { auxConcentration2 }); // add the serialNumber channel to the channelMap channelIndex = registerChannelMap.Add("auxConcentration3"); registerChannelMap.PutUserInfo(channelIndex, "units=none"); channelIndex = rbnbChannelMap.Add("auxConcentration3"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { auxConcentration3 }); // add the rmsError channel to the channelMap channelIndex = registerChannelMap.Add("rmsError"); registerChannelMap.PutUserInfo(channelIndex, "units=none"); channelIndex = rbnbChannelMap.Add("rmsError"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { rmsError }); // add the insideTemperature channel to the channelMap channelIndex = registerChannelMap.Add("insideTemperature"); registerChannelMap.PutUserInfo(channelIndex, "units=Celsius"); channelIndex = rbnbChannelMap.Add("insideTemperature"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { insideTemperature }); // add the spectrometerTemperature channel to the channelMap channelIndex = registerChannelMap.Add("spectrometerTemperature"); registerChannelMap.PutUserInfo(channelIndex, "units=Celsius"); channelIndex = rbnbChannelMap.Add("spectrometerTemperature"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { spectrometerTemperature }); // add the lampTemperature channel to the channelMap channelIndex = registerChannelMap.Add("lampTemperature"); registerChannelMap.PutUserInfo(channelIndex, "units=Celsius"); channelIndex = rbnbChannelMap.Add("lampTemperature"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { lampTemperature }); // add the lampTime channel to the channelMap channelIndex = registerChannelMap.Add("lampTime"); registerChannelMap.PutUserInfo(channelIndex, "units=seconds"); channelIndex = rbnbChannelMap.Add("lampTime"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsInt32(channelIndex, new int[] { lampTime }); // add the humidity channel to the channelMap channelIndex = registerChannelMap.Add("humidity"); registerChannelMap.PutUserInfo(channelIndex, "units=%"); channelIndex = rbnbChannelMap.Add("humidity"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { humidity }); // add the lampVoltage12 channel to the channelMap channelIndex = registerChannelMap.Add("lampVoltage12"); registerChannelMap.PutUserInfo(channelIndex, "units=V"); channelIndex = rbnbChannelMap.Add("lampVoltage12"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { lampVoltage12 }); // add the internalPowerVoltage5 channel to the channelMap channelIndex = registerChannelMap.Add("internalPowerVoltage5"); registerChannelMap.PutUserInfo(channelIndex, "units=V"); channelIndex = rbnbChannelMap.Add("internalPowerVoltage5"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { internalPowerVoltage5 }); // add the mainPowerVoltage channel to the channelMap channelIndex = registerChannelMap.Add("mainPowerVoltage"); registerChannelMap.PutUserInfo(channelIndex, "units=V"); channelIndex = rbnbChannelMap.Add("mainPowerVoltage"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { mainPowerVoltage }); // add the referenceAverage channel to the channelMap channelIndex = registerChannelMap.Add("referenceAverage"); registerChannelMap.PutUserInfo(channelIndex, "units=count"); channelIndex = rbnbChannelMap.Add("referenceAverage"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { referenceAverage }); // add the referenceVariance channel to the channelMap channelIndex = registerChannelMap.Add("referenceVariance"); registerChannelMap.PutUserInfo(channelIndex, "units=count"); channelIndex = rbnbChannelMap.Add("referenceVariance"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { referenceVariance }); // add the seaWaterDarkCounts channel to the channelMap channelIndex = registerChannelMap.Add("seaWaterDarkCounts"); registerChannelMap.PutUserInfo(channelIndex, "units=count"); channelIndex = rbnbChannelMap.Add("seaWaterDarkCounts"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { seaWaterDarkCounts }); // add the spectrometerAverage channel to the channelMap channelIndex = registerChannelMap.Add("spectrometerAverage"); registerChannelMap.PutUserInfo(channelIndex, "units=count"); channelIndex = rbnbChannelMap.Add("averageWavelength"); rbnbChannelMap.PutMime(channelIndex, "application/octet-stream"); rbnbChannelMap.PutDataAsFloat64(channelIndex, new double[] { spectrometerAverage }); // Now register the RBNB channels, and flush the rbnbChannelMap to the // DataTurbine getSource().Register(registerChannelMap); getSource().Flush(rbnbChannelMap); logger.info(frameDateAsString + " " + "Sample sent to the DataTurbine: (" + serialNumber + ") " + sampleString); registerChannelMap.Clear(); rbnbChannelMap.Clear(); } else { logger.info("Couldn't apply the calibration coefficients. " + "Skipping this sample."); } // end if() } // end if() } // end for() //getSource.Detach(); success = true; } catch (ParseException pe) { // parsing of the calibration file failed. Log the exception, return false success = false; logger.debug("There was a problem parsing the calibration file. The " + "error message was: " + pe.getMessage()); return success; } catch (SAPIException sapie) { // In the event of an RBNB communication exception, log the exception, // and allow execute() to return false, which will prompt a retry. success = false; sapie.printStackTrace(); return success; } return success; }
From source file:subsets.GenerateGFKMatrix.java
void query2() { graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); registerShutdownHook(graphDb);/*from w w w. ja v a2 s. c om*/ ExecutionEngine engine = new ExecutionEngine(graphDb); ExecutionResult result; TreeMap<String, HashSet> SmartCube_SC_Attribut = new TreeMap(); TreeMap<String, HashSet> MetaCube_SmartCube = new TreeMap(); TreeMap<String, JSONObject> name_json1 = new TreeMap(); TreeMap<String, JSONObject> name_json2 = new TreeMap(); try (Transaction ignored = graphDb.beginTx()) { result = (ExecutionResult) engine .execute("MATCH (sc:SmartCube)<-[:MEMBER_OF]-(sca:SCAttribut) RETURN sc,sca"); //TreeMap<String,HashSet> SCAttribut_SCAlgo = new TreeMap(); //TreeMap<String,HashSet> SCAlgo_BCAttribut = new TreeMap(); //ArrayList<TreeMap<String,HashSet>> treemaps = new ArrayList(); for (Map<String, Object> row : result) { String SmartCube = null; String SC_Attribut = null; String SC_Algorithumus = null; String BC_Attribut = null; String MetaCube = null; for (Entry<String, Object> column : row.entrySet()) { Node x = (Node) column.getValue(); if (column.getKey().equals("sca")) SC_Attribut = (String) x.getProperty("name"); //if (column.getKey().equals("c")) SC_Algorithumus = (String) x.getProperty("name"); if (column.getKey().equals("sc")) SmartCube = (String) x.getProperty("name"); //for (String y :x.getPropertyKeys()) System.out.println(y); if (column.getKey().equals("sc")) MetaCube = (String) x.getProperty("MetaCube"); } System.out.println("------------------------"); addAttribute_to_Treemap(MetaCube, SmartCube, MetaCube_SmartCube); addAttribute_to_Treemap(SmartCube, SC_Attribut, SmartCube_SC_Attribut); } //ende query } graphDb.shutdown(); ArrayList<String[]> hirarchy = new ArrayList<String[]>(); hirarchy.add(sc); hirarchy.add(sca); hirarchy.add(bca); TreeMap<String, JSONObject> SCAttribut_SCAlgo_BCAttribut = getDepTree_old( "MATCH (sc:SCAttribut) -[:DERIVED_BY]->(sca:SCAlgorithmen)-[:USES] ->(bca:BCAttribut) RETURN sc,sca,bca", hirarchy); hirarchy.clear(); hirarchy.add(sc); hirarchy.add(bca); TreeMap<String, JSONObject> SCAttribut_BCAttribut = getDepTree( "MATCH (sc:SCAttribut) -[:TRANSITION]->(bca:BCAttribut) RETURN sc,bca", hirarchy); SCAttribut_SCAlgo_BCAttribut.putAll(SCAttribut_BCAttribut); part_tree(SmartCube_SC_Attribut, SCAttribut_SCAlgo_BCAttribut, name_json1, false); part_tree(MetaCube_SmartCube, name_json1, name_json2, false); //old and working // part_tree(SmartCube_SC_Attribut, null,name_json1, true); // part_tree(MetaCube_SmartCube, name_json1,name_json2, false); //part_tree(SmartCube_SCAttribut, name_json1, name_json2, false); JSONObject MetaCube = new JSONObject(); try { MetaCube.append("name", "MetaCube"); for (String key : name_json2.keySet()) { JSONObject cube = name_json2.get(key); MetaCube.append("children", cube); } } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String content = MetaCube.toString(); try { //String content = json_smartcube.toString(); File file = new File("C://Users//frisch//Desktop//d3//flare.json"); // if file doesnt exists, then create it if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); bw.write(content); bw.close(); System.out.println("Done"); } catch (IOException e) { e.printStackTrace(); } }