List of usage examples for java.util TreeMap keySet
public Set<K> keySet()
From source file:trendanalisis.main.tools.weka.CoreWekaTFIDF.java
/** * Converts the instance w/o normalization. * //from www .j av a 2s.c om * @oaram instance the instance to convert * @param v * @return the conerted instance */ private int convertInstancewoDocNorm(Instance instance, ArrayList<Instance> v, int indexInstance) { // Convert the instance into a sorted set of indexes TreeMap<Integer, Double> contained = new TreeMap<Integer, Double>(); // Copy all non-converted attributes from input to output int firstCopy = 0; for (int i = 0; i < getInputFormat().numAttributes(); i++) { if (!m_SelectedRange.isInRange(i)) { if (getInputFormat().attribute(i).type() != Attribute.STRING && getInputFormat().attribute(i).type() != Attribute.RELATIONAL) { // Add simple nominal and numeric attributes directly if (instance.value(i) != 0.0) { contained.put(new Integer(firstCopy), new Double(instance.value(i))); } } else { if (instance.isMissing(i)) { contained.put(new Integer(firstCopy), new Double(Utils.missingValue())); } else if (getInputFormat().attribute(i).type() == Attribute.STRING) { // If this is a string attribute, we have to first add // this value to the range of possible values, then add // its new internal index. if (outputFormatPeek().attribute(firstCopy).numValues() == 0) { // Note that the first string value in a // SparseInstance doesn't get printed. outputFormatPeek().attribute(firstCopy) .addStringValue("Hack to defeat SparseInstance bug"); } int newIndex = outputFormatPeek().attribute(firstCopy) .addStringValue(instance.stringValue(i)); contained.put(new Integer(firstCopy), new Double(newIndex)); } else { // relational if (outputFormatPeek().attribute(firstCopy).numValues() == 0) { Instances relationalHeader = outputFormatPeek().attribute(firstCopy).relation(); // hack to defeat sparse instances bug outputFormatPeek().attribute(firstCopy).addRelation(relationalHeader); } int newIndex = outputFormatPeek().attribute(firstCopy) .addRelation(instance.relationalValue(i)); contained.put(new Integer(firstCopy), new Double(newIndex)); } } firstCopy++; } } Map<Integer, Integer> posMap = new HashMap<>(); Bag<String> contents = new HashBag(); for (int j = 0; j < instance.numAttributes(); j++) { // if ((getInputFormat().attribute(j).type() == Attribute.STRING) if (m_SelectedRange.isInRange(j) && (instance.isMissing(j) == false)) { m_Tokenizer.tokenize(instance.stringValue(j)); int posWord = 1; while (m_Tokenizer.hasMoreElements()) { String word = m_Tokenizer.nextElement(); if (this.m_lowerCaseTokens == true) { word = word.toLowerCase(); } word = m_Stemmer.stem(word); // System.out.println(posWord +":"+ word); Integer index = m_Dictionary.get(word); Words.put(index, word); contents.add(word); if (index != null) { if (m_OutputCounts) { // Separate if here rather than two lines down // to avoid hashtable lookup Double count = contained.get(index); if (count != null) { contained.put(index, new Double(count.doubleValue() + 1.0)); } else { contained.put(index, new Double(1)); } } else { contained.put(index, new Double(1)); } if (!posMap.containsKey(index)) { posMap.put(index, posWord); // posWord++; } } posWord++; } } } // Doing TFTransform // ArrayList<Integer> posList= new ArrayList<>(posMap.values()); // System.out.println(posList); /* * Fitur Subtittle * instance attribut ke 0 adalah judul * 1 adalah lokasi * 3 adalah tanggal */ String subtittle = ""; ArrayList<String> subtittles = null; if (ins_fitur_subtitle != null) { subtittle = ins_fitur_subtitle.get(indexInstance).stringValue(0); subtittles = new ArrayList<>(Arrays.asList(subtittle.split(" "))); // subtittles.retainAll(contents); } else { fitur_subtitle = false; } if (m_TFTransform == true) { Iterator<Integer> it = contained.keySet().iterator(); int set = 0; for (; it.hasNext();) { Integer index = it.next(); if (index.intValue() >= firstCopy) { double val = contained.get(index).doubleValue(); if (isBinary_transform()) { val = 1; } // val = (1 + Math.log(val)); contained.put(index, new Double(val)); set++; } } } // Doing IDFTransform double sum = 0; if (m_IDFTransform == true) { Iterator<Integer> it = contained.keySet().iterator(); int i = 0; for (; it.hasNext();) { Integer index = it.next(); if (index.intValue() >= firstCopy) { double val = contained.get(index).doubleValue(); double valIG = (FeatureSelection.InformationGain(m_DocsCounts[index.intValue()], m_NumInstances));// Math.abs(valIG); global_tf[index.intValue()] += val; df_prob[index.intValue()] = FeatureSelection.IdfProbability((double) m_NumInstances, m_DocsCounts[index.intValue()]); IG[index.intValue()] = valIG; if (isBinary_transform()) { val = 1; val = (Math.log(val)); } val = val * (1 + Math.log((double) m_NumInstances / (double) m_DocsCounts[index.intValue()])); if (isStat_pos_word()) { val = val + (1 / Math.sqrt(posMap.get(index))); } contained.put(index, new Double(val)); // global_tf[index.intValue()]= (1+ Math.log(m_NumInstances / (double) m_DocsCounts[index.intValue()])); i++; } } } // System.out.println("-------------------"); // Convert the set to structures needed to create a sparse instance. double[] values = new double[contained.size()]; int[] indices = new int[contained.size()]; Iterator<Integer> it = contained.keySet().iterator(); for (int i = 0; it.hasNext(); i++) { Integer index = it.next(); Double value = contained.get(index); values[i] = value.doubleValue(); indices[i] = index.intValue(); //df_prob[index.intValue()] = df_prob[index.intValue()]/m_DocsCounts[index.intValue()]; } Instance inst = new SparseInstance(instance.weight(), values, indices, outputFormatPeek().numAttributes()); inst.setDataset(outputFormatPeek()); v.add(inst); return firstCopy; }
From source file:com.dell.asm.asmcore.asmmanager.app.rest.ServiceTemplateService.java
/** * We will be parsing the network interfaces, most likely extracted from a device xml, and generating a json string to set the value of the service template setting with it * @param serverSettingNetwork/* w ww . ja v a 2 s . c om*/ * @param networkInterfaces */ protected void applyNetworkCustomization(ServiceTemplateSetting serverSettingNetwork, final TreeMap<String, Component> networkInterfaces, boolean is2x10gby2x1gNicType) { if (serverSettingNetwork == null || networkInterfaces == null) return; LOGGER.debug("Beginning to construct network from config xml"); //Setup the little helpers we will be using later //Create the top level of networkconfiguration com.dell.asm.asmcore.asmmanager.client.networkconfiguration.NetworkConfiguration networkConfigurationResult = new com.dell.asm.asmcore.asmmanager.client.networkconfiguration.NetworkConfiguration(); networkConfigurationResult.setId(UUID.randomUUID().toString()); networkConfigurationResult.setInterfaces(new ArrayList<Fabric>()); Fabric lastCard = new Fabric(); Interface lastSubInterface = new Interface(); // String lastSlot = "1"; //Fabric lastFabric = new Fabric(); //Interface lastFabricInterface = new Interface(); //We use this comparator to ensure the fabrics show up in the right order in the UI //If we don't sort, the fabrics will show up in the order they show up in the config.xml ArrayList<String> sortedInterfaces = new ArrayList<String>(); sortedInterfaces.addAll(networkInterfaces.keySet()); Collections.sort(sortedInterfaces, new FabricComparator()); //Loop through sortedInterfaces to map out which nics are in which fabric/slot. HashMap<String, String> fabricMap = new HashMap<>(); int fabricIndex = -1; String lastFabricLocation = "0"; String lastNicType = ""; // For RACK Servers, 1 Integrated and 7 PCI slots String[] fabricIds = { "1", "2", "3", "4", "5", "6", "7", "8" }; for (String nic : sortedInterfaces) { String thisLocation = getFabricLocation(nic); String thisNicType = nic.split("\\.\\d\\w*")[0]; if (!thisLocation.equals(lastFabricLocation) || !lastNicType.equals(thisNicType)) { fabricIndex++; lastFabricLocation = thisLocation; lastNicType = thisNicType; } String thisFabricId = fabricIds[fabricIndex]; fabricMap.put(nic, thisFabricId); } //Loop through sortedInterfaces to map out which nics are in which fabric/slot. //Iterate over all of the nic configurations that were passed in sorted off of their keys int firstInterfaceCount = 0; // is2x10gby2x1gNicType can only be set for ONE interface, must make sure we do not set it for ALL Network Interfaces (Network Cards / Nics) for (String key : sortedInterfaces) { String regex = "^\\w+\\.\\w+"; String min = "0"; String max = "100"; //Parse nics that are of the expected naming convention if (key.matches(regex + "\\.\\d\\w?-\\d(-\\d)?")) { LOGGER.debug("Found correctly formatted key: " + key); Component nic = networkInterfaces.get(key); //Get the values from the passed in nic configuration for (Attribute a : nic.getAttribute()) { if ("minbandwidth".equalsIgnoreCase(a.getName())) min = a.getValue(); else if ("maxbandwidth".equalsIgnoreCase(a.getName())) max = a.getValue(); } Pattern pattern = Pattern.compile(regex); Matcher m = pattern.matcher(key); m.find(); String nicType = m.group(); boolean isFcFabric = nicType.toLowerCase().startsWith("fc."); String numeric = key.split(regex + "\\.")[1]; String[] numericSplit = numeric.split("-"); //Now parse the numeric portion and construct a network configuation hierarchy from it //Top level under the network configuration String fIndex = fabricMap.get(nic.getFQDD()); String topName = "Interface " + fIndex; if (!topName.equals(lastCard.getName())) { LOGGER.debug("Creating top level for: " + topName); lastCard = new Fabric(); lastCard.setId(UUID.randomUUID().toString()); lastCard.setName(topName); lastCard.setEnabled(true); if (is2x10gby2x1gNicType && firstInterfaceCount < 4) { lastCard.setNictype(Interface.NIC_2_X_10GB_2_X_1GB); } else lastCard.setNictype(Interface.NIC_2_X_10GB); lastCard.setInterfaces(new ArrayList<Interface>()); if (isFcFabric) { lastCard.setFabrictype(Fabric.FC_TYPE); } else { lastCard.setFabrictype(Fabric.ETHERNET_TYPE); } //Only add the interfaces here if it is rack server //If not we will be constucting them anyway but just discarding them networkConfigurationResult.getInterfaces().add(lastCard); } //FC fabrics should have no port/partition configuration. if (!isFcFabric) { //Middle level String thisSlot = numericSplit[0]; String portNumber = numericSplit[1]; // Embedded/Integrated nics are weird, in that the nics could be labelled 1-1-1 and 2-1-1, but those are single port cards. // So we want to show double ports, in the same fabric. if ((key.contains("Embedded") || key.contains("Integrated")) && !thisSlot.equals("1")) { portNumber = thisSlot; } String middleName = "Port " + portNumber; if (!middleName.equals(lastSubInterface.getName())) { if (Integer.parseInt(numericSplit[1]) > 2) { if (is2x10gby2x1gNicType && firstInterfaceCount < 4) { lastCard.setNictype(Interface.NIC_2_X_10GB_2_X_1GB); } else { lastCard.setNictype(Interface.NIC_4_X_10GB); } } LOGGER.debug("Creating middle level for: " + middleName); lastSubInterface = new Interface(); lastSubInterface.setId(UUID.randomUUID().toString()); lastCard.getInterfaces().add(lastSubInterface); lastSubInterface.setPartitions(new ArrayList<Partition>()); lastSubInterface.setName(middleName); lastSubInterface.setPartitioned(true); } //Last level. Can be missed in FQDD. if (numericSplit.length > 2) { Partition partition = new Partition(); partition.setId(UUID.randomUUID().toString()); partition.setName(numericSplit[2]); partition.setMinimum(Integer.parseInt(min)); partition.setMaximum(Integer.parseInt(max)); partition.setNetworks(new ArrayList<String>()); lastSubInterface.getPartitions().add(partition); } } } firstInterfaceCount++; } fillMaxPortsAndPartitions(networkConfigurationResult.getInterfaces()); serverSettingNetwork.setValue(ServiceTemplateUtil.serializeNetwork(networkConfigurationResult)); }
From source file:org.opendatakit.services.database.utilities.ODKDatabaseImplUtils.java
/** * If the caller specified a complex json value for a structured type, flush * the value through to the individual columns. * * @param orderedColumns// w ww . ja v a2 s . c o m * @param values */ private void cleanUpValuesMap(OrderedColumns orderedColumns, Map<String, Object> values) { TreeMap<String, String> toBeResolved = new TreeMap<String, String>(); for (String key : values.keySet()) { if (DataTableColumns.CONFLICT_TYPE.equals(key)) { continue; } else if (DataTableColumns.DEFAULT_ACCESS.equals(key)) { continue; } else if (DataTableColumns.ROW_OWNER.equals(key)) { continue; } else if (DataTableColumns.GROUP_READ_ONLY.equals(key)) { continue; } else if (DataTableColumns.GROUP_MODIFY.equals(key)) { continue; } else if (DataTableColumns.GROUP_PRIVILEGED.equals(key)) { continue; } else if (DataTableColumns.FORM_ID.equals(key)) { continue; } else if (DataTableColumns.ID.equals(key)) { continue; } else if (DataTableColumns.LOCALE.equals(key)) { continue; } else if (DataTableColumns.ROW_ETAG.equals(key)) { continue; } else if (DataTableColumns.SAVEPOINT_CREATOR.equals(key)) { continue; } else if (DataTableColumns.SAVEPOINT_TIMESTAMP.equals(key)) { continue; } else if (DataTableColumns.SAVEPOINT_TYPE.equals(key)) { continue; } else if (DataTableColumns.SYNC_STATE.equals(key)) { continue; } else if (DataTableColumns._ID.equals(key)) { continue; } // OK it is one of the data columns ColumnDefinition cp = orderedColumns.find(key); if (!cp.isUnitOfRetention()) { toBeResolved.put(key, (String) values.get(key)); } } // remove these non-retained values from the values set... for (String key : toBeResolved.keySet()) { values.remove(key); } while (!toBeResolved.isEmpty()) { TreeMap<String, String> moreToResolve = new TreeMap<String, String>(); for (Map.Entry<String, String> entry : toBeResolved.entrySet()) { String key = entry.getKey(); String json = entry.getValue(); if (json == null) { // don't need to do anything // since the value is null continue; } ColumnDefinition cp = orderedColumns.find(key); try { TypeReference<Map<String, Object>> reference = new TypeReference<Map<String, Object>>() { }; Map<String, Object> struct = ODKFileUtils.mapper.readValue(json, reference); for (ColumnDefinition child : cp.getChildren()) { String subkey = child.getElementKey(); ColumnDefinition subcp = orderedColumns.find(subkey); if (subcp.isUnitOfRetention()) { ElementType subtype = subcp.getType(); ElementDataType type = subtype.getDataType(); if (type == ElementDataType.integer) { values.put(subkey, (Integer) struct.get(subcp.getElementName())); } else if (type == ElementDataType.number) { values.put(subkey, (Double) struct.get(subcp.getElementName())); } else if (type == ElementDataType.bool) { values.put(subkey, ((Boolean) struct.get(subcp.getElementName())) ? 1 : 0); } else { values.put(subkey, (String) struct.get(subcp.getElementName())); } } else { // this must be a javascript structure... re-JSON it and save (for // next round). moreToResolve.put(subkey, ODKFileUtils.mapper.writeValueAsString(struct.get(subcp.getElementName()))); } } } catch (JsonParseException e) { e.printStackTrace(); throw new IllegalStateException("should not be happening"); } catch (JsonMappingException e) { e.printStackTrace(); throw new IllegalStateException("should not be happening"); } catch (IOException e) { e.printStackTrace(); throw new IllegalStateException("should not be happening"); } } toBeResolved = moreToResolve; } }
From source file:org.xframium.spi.RunDetails.java
public synchronized void writeHTMLIndex(File rootFolder, boolean complete) { Collections.sort(detailsList, new RunComparator()); int runTime = (int) System.currentTimeMillis() - (int) startTime; TreeMap<String, int[]> caseMap = new TreeMap<String, int[]>(); TreeMap<String, int[]> deviceMap = new TreeMap<String, int[]>(); TreeMap<String, int[]> osMap = new TreeMap<String, int[]>(); TreeMap<String, int[]> envMap = new TreeMap<String, int[]>(); int[] stepBreakdown = new int[3]; int[] failureBreakdown = new int[5]; int successCount = 0; for (int i = 0; i < detailsList.size(); i++) { String runKey = (String) detailsList.get(i)[0]; Device device = (Device) detailsList.get(i)[1]; int success = (int) detailsList.get(i)[2]; stepBreakdown[0] += (int) detailsList.get(i)[3]; stepBreakdown[1] += (int) detailsList.get(i)[4]; stepBreakdown[2] += (int) detailsList.get(i)[5]; long startTime = (long) detailsList.get(i)[6]; long stopTime = (long) detailsList.get(i)[7]; failureBreakdown[0] += (int) detailsList.get(i)[8]; failureBreakdown[1] += (int) detailsList.get(i)[9]; failureBreakdown[2] += (int) detailsList.get(i)[10]; failureBreakdown[3] += (int) detailsList.get(i)[11]; failureBreakdown[4] += (int) detailsList.get(i)[12]; String deviceKey = device.getEnvironment(); int[] caseValue = caseMap.get(runKey); if (caseValue == null) { caseValue = new int[] { 0, 0, 0, 0, 0 }; caseMap.put(runKey, caseValue); }//from w w w .j a v a 2 s. c o m if (success == 1) caseValue[0]++; else if (success == 2) caseValue[1]++; else caseValue[4]++; caseValue[2]++; caseValue[3] += (stopTime - startTime); caseValue = envMap.get(device.getEnvironment()); if (caseValue == null) { caseValue = new int[] { 0, 0, 0 }; envMap.put(device.getEnvironment(), caseValue); } if (success == 1) caseValue[0]++; else if (success == 2) caseValue[1]++; else caseValue[2]++; caseValue = deviceMap.get(deviceKey); if (caseValue == null) { caseValue = new int[] { 0, 0, 0 }; deviceMap.put(deviceKey, caseValue); } if (success == 1) caseValue[0]++; else if (success == 2) caseValue[1]++; else caseValue[2]++; String osName = device.getOs(); if (osName == null) osName = "Unknown"; caseValue = osMap.get(osName); if (caseValue == null) { caseValue = new int[] { 0, 0, 0 }; osMap.put(osName, caseValue); } if (success == 1) caseValue[0]++; else if (success == 2) caseValue[1]++; else caseValue[2]++; if ((int) detailsList.get(i)[2] == 1) successCount++; } StringBuilder stringBuilder = new StringBuilder(); File useFile = getIndex(rootFolder); writePageHeader(stringBuilder, 1); String runLength = String.format("%dh %dm %ds", TimeUnit.MILLISECONDS.toHours(runTime), TimeUnit.MILLISECONDS.toMinutes(runTime) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(runTime)), TimeUnit.MILLISECONDS.toSeconds(runTime) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(runTime))); stringBuilder.append( "<div class=\"row\"><div class=\"pull-right text-muted\"><a hRef=\"../index.html\" style=\"margin-right: 18px;\">Return to Test Execution History</a></div></div>"); stringBuilder.append( "<div class=\"panel panel-primary\"><div class=panel-heading><div class=panel-title>Execution Detail (" + runLength + ")</div></div><div class=panel-body><table class=\"table table-hover table-condensed\">"); stringBuilder.append( "<tr><th width=\"40%\">Test</th><th width=\"40%\">Environment</th><th width=\"20%\">Duration</th><th>Status</th></tr><tbody>"); int[] localBreakdown = new int[5]; for (int i = 0; i < detailsList.size(); i++) { String runKey = (String) detailsList.get(i)[0]; Device device = (Device) detailsList.get(i)[1]; String location = runKey + "/" + device.getKey() + "/"; int success = (int) detailsList.get(i)[2]; long startTime = (long) detailsList.get(i)[6]; long stopTime = (long) detailsList.get(i)[7]; localBreakdown[0] = (int) detailsList.get(i)[8]; localBreakdown[1] = (int) detailsList.get(i)[9]; localBreakdown[2] = (int) detailsList.get(i)[10]; localBreakdown[3] = (int) detailsList.get(i)[11]; localBreakdown[4] = (int) detailsList.get(i)[12]; long testRunTime = stopTime - startTime; String testRunLength = String.format("%2dh %2dm %2ds", TimeUnit.MILLISECONDS.toHours(testRunTime), TimeUnit.MILLISECONDS.toMinutes(testRunTime) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(testRunTime)), TimeUnit.MILLISECONDS.toSeconds(testRunTime) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(testRunTime))); stringBuilder.append("<tr><td><a href='").append(location + runKey + ".html'>").append(runKey) .append("</a></td><td>"); stringBuilder.append(device.getEnvironment()).append("</td>"); stringBuilder.append("<td>").append(testRunLength) .append("</td><td style=\"padding-top: 10px; \" align=\"center\">"); if (success == 1) stringBuilder.append("<span class=\"label label-success\">Pass</span>"); else { if (localBreakdown[0] > 0) stringBuilder.append("<span class=\"label label-danger\">Script</span>"); else if (localBreakdown[1] > 0) stringBuilder.append("<span class=\"label label-danger\">Configuration</span>"); else if (localBreakdown[2] > 0) stringBuilder.append("<span class=\"label label-danger\">Application</span>"); else if (localBreakdown[3] > 0) stringBuilder.append("<span class=\"label label-danger\">Cloud</span>"); else if (localBreakdown[4] > 0) stringBuilder.append("<span class=\"label label-warning\">Skipped</span>"); else stringBuilder.append("<span class=\"label label-danger\">Fail</span>"); } stringBuilder.append("</td></tr>"); } stringBuilder.append("<tr><td colSpan='6' align='center'><h6>") .append(new File(rootFolder, getRootFolder() + System.getProperty("file.separator") + "executionMap.properties") .getAbsolutePath()) .append("</h6></td></tr></tbody></table></div></div>"); stringBuilder.append( "<div class=\"panel panel-primary\"><div class=panel-heading><div class=panel-title>Environment Summary</div></div><div class=panel-body><table class=\"table table-hover table-condensed\">"); stringBuilder .append("<thead><tr><th width=60%>Environment</th><th nowrap>Pass Rate</th></thead></tr><tbody>"); for (String deviceName : envMap.keySet()) { int[] currentRecord = deviceMap.get(deviceName); int totalValue = currentRecord[0] + currentRecord[1]; double successValue = 0; if (totalValue > 0) successValue = ((double) currentRecord[0] / (double) totalValue) * 100; stringBuilder.append("<tr><td width=60%>").append(deviceName).append("</td><td>") .append(percentFormat.format(successValue)).append("%</td></tr>"); } stringBuilder.append("</tbody></table></div></div>"); stringBuilder.append( "<div class=\"panel panel-primary\"><div class=panel-heading><div class=panel-title>Test Summary</div></div><div class=panel-body><table class=\"table table-hover table-condensed\">"); stringBuilder.append( "<thead><tr><th width=60%>Test</th><th nowrap>Pass Rate</th><th nowrap>Average Duration</th></thead></tr><tbody>"); for (String deviceName : caseMap.keySet()) { int[] currentRecord = caseMap.get(deviceName); int totalValue = currentRecord[0] + currentRecord[1]; double successValue = 0; if (totalValue > 0) successValue = ((double) currentRecord[0] / (double) totalValue) * 100; int runTimex = (int) ((double) currentRecord[3] / (double) currentRecord[2]); String runLengthx = String.format("%2dh %2dm %2ds", TimeUnit.MILLISECONDS.toHours(runTimex), TimeUnit.MILLISECONDS.toMinutes(runTimex) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(runTimex)), TimeUnit.MILLISECONDS.toSeconds(runTimex) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(runTimex))); stringBuilder.append("<tr><td width=60%>").append(deviceName).append("</td><td>") .append(percentFormat.format(successValue)).append("%</td><td>").append(runLengthx) .append("</td></tr>"); } stringBuilder.append("</tbody></table></div></div>"); stringBuilder.append( "<div class=\"panel panel-primary\"><div class=panel-heading><div class=panel-title>Failure Breakdown</div></div><div class=panel-body><table class=\"table table-hover table-condensed\">"); stringBuilder.append( "<thead><tr><th width=90%>Failure Type</th><th nowrap>Failure Count</th></tr></thead><tbody>"); stringBuilder.append( "<tbody><tr><td width=90%>Scripting Issues</td><td nowrap>" + failureBreakdown[0] + "</td></tr>"); stringBuilder.append( "<tr><td width=90%>Configuration Issues</td><td nowrap>" + failureBreakdown[1] + "</td></tr>"); stringBuilder.append( "<tr><td width=90%>Application Issues</td><td nowrap>" + failureBreakdown[2] + "</td></tr>"); stringBuilder.append("<tr><td width=90%>Cloud Issues</td><td nowrap>" + failureBreakdown[3] + "</td></tr>"); stringBuilder .append("<tr><td width=90%>Skipped Tests</td><td nowrap>" + failureBreakdown[4] + "</td></tr>"); stringBuilder.append("</tbody></table></div></div></div>"); stringBuilder.append("</div></div></div></div>"); writePageFooter(stringBuilder); try { useFile.getParentFile().mkdirs(); FileWriter fileWriter = new FileWriter(useFile); fileWriter.write(stringBuilder.toString()); fileWriter.close(); if (complete) { if (historyWriter == null) historyWriter = new HistoryWriter(DataManager.instance().getReportFolder()); historyWriter.writeData(getRootFolder() + System.getProperty("file.separator") + "index.html", startTime, System.currentTimeMillis(), envMap.size(), osMap.size(), successCount, detailsList.size() - successCount, envMap, failureBreakdown[0], failureBreakdown[1], failureBreakdown[2], failureBreakdown[3], failureBreakdown[4]); } } catch (Exception e) { e.printStackTrace(); } try { HttpClient httpclient = HttpClients.createDefault(); int CONNECTION_TIMEOUT_MS = 3000; // Timeout in millis. Builder requestBuilder = RequestConfig.custom().setConnectionRequestTimeout(CONNECTION_TIMEOUT_MS) .setConnectTimeout(CONNECTION_TIMEOUT_MS).setSocketTimeout(CONNECTION_TIMEOUT_MS); /*if ( CloudRegistry.instance().getCloud().getProxyHost() != null && !CloudRegistry.instance().getCloud().getProxyHost().isEmpty() ) { requestBuilder.setProxy( new HttpHost( CloudRegistry.instance().getCloud().getProxyHost(), Integer.parseInt( CloudRegistry.instance().getCloud().getProxyPort() ) ) ); }*/ if (ProxyRegistry.instance().getProxyHost() != null && !ProxyRegistry.instance().getProxyHost().isEmpty()) { requestBuilder.setProxy(new HttpHost(ProxyRegistry.instance().getProxyHost(), Integer.parseInt(ProxyRegistry.instance().getProxyPort()))); } RequestConfig requestConfig = requestBuilder.build(); HttpPost httppost = new HttpPost("http://www.google-analytics.com/collect"); httppost.setConfig(requestConfig); List<NameValuePair> params = new ArrayList<NameValuePair>(2); params.add(new BasicNameValuePair("v", "1")); params.add(new BasicNameValuePair("tid", "UA-80178289-1")); params.add(new BasicNameValuePair("cid", "555")); params.add(new BasicNameValuePair("t", "pageview")); params.add(new BasicNameValuePair("dt", "/testExecution")); params.add(new BasicNameValuePair("dp", ApplicationRegistry.instance().getAUT().getName())); params.add(new BasicNameValuePair("an", "xFramium")); params.add(new BasicNameValuePair("av", Initializable.VERSION)); params.add(new BasicNameValuePair("dh", CloudRegistry.instance().getCloud().getHostName())); params.add(new BasicNameValuePair("cm1", detailsList.size() + "")); params.add(new BasicNameValuePair("cm2", successCount + "")); params.add(new BasicNameValuePair("cm3", (detailsList.size() - successCount) + "")); params.add( new BasicNameValuePair("cm4", (stepBreakdown[0] + stepBreakdown[1] + stepBreakdown[2]) + "")); params.add(new BasicNameValuePair("cm5", stepBreakdown[0] + "")); params.add(new BasicNameValuePair("cm6", stepBreakdown[1] + "")); params.add(new BasicNameValuePair("cm7", stepBreakdown[2] + "")); params.add(new BasicNameValuePair("cm8", envMap.size() + "")); params.add(new BasicNameValuePair("cm9", (runTime / 1000) + "")); params.add(new BasicNameValuePair("cd2", System.getProperty("os.name"))); params.add(new BasicNameValuePair("cd3", System.getProperty("java.version"))); params.add(new BasicNameValuePair("cd4", "X" + Base64.encodeBase64String(CloudRegistry.instance().getCloud().getUserName().getBytes()) + "=")); httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); // Execute and get the response. HttpResponse response = httpclient.execute(httppost); } catch (Exception e) { } }
From source file:gov.vha.isaac.ochre.impl.sememe.DynamicSememeUsageDescription.java
/** * Read the RefexUsageDescription data from the database for a given nid. * /*from ww w. j ava2 s . co m*/ * Note that most users should call {@link #read(int)} instead, as that utilizes a cache. * This always reads directly from the DB. * * @param refexUsageDescriptorSequence * @throws IOException * @throws ContradictionException */ @SuppressWarnings("unchecked") public DynamicSememeUsageDescription(int refexUsageDescriptorSequence) { refexUsageDescriptorSequence_ = refexUsageDescriptorSequence; TreeMap<Integer, DynamicSememeColumnInfo> allowedColumnInfo = new TreeMap<>(); ConceptChronology<?> assemblageConcept = Get.conceptService().getConcept(refexUsageDescriptorSequence_); for (SememeChronology<? extends DescriptionSememe<?>> descriptionSememe : assemblageConcept .getConceptDescriptionList()) { @SuppressWarnings("rawtypes") Optional<LatestVersion<DescriptionSememe<?>>> descriptionVersion = ((SememeChronology) descriptionSememe) .getLatestVersion(DescriptionSememe.class, StampCoordinates.getDevelopmentLatestActiveOnly()); if (descriptionVersion.isPresent()) { @SuppressWarnings("rawtypes") DescriptionSememe ds = descriptionVersion.get().value(); if (ds.getDescriptionTypeConceptSequence() == IsaacMetadataAuxiliaryBinding.DEFINITION_DESCRIPTION_TYPE .getConceptSequence()) { Optional<SememeChronology<? extends SememeVersion<?>>> nestesdSememe = Get.sememeService() .getSememesForComponentFromAssemblage(ds.getNid(), IsaacMetadataConstants.DYNAMIC_SEMEME_DEFINITION_DESCRIPTION.getSequence()) .findAny(); if (nestesdSememe.isPresent()) { sememeUsageDescription_ = ds.getText(); } ; } if (ds.getDescriptionTypeConceptSequence() == IsaacMetadataAuxiliaryBinding.FULLY_SPECIFIED_NAME .getConceptSequence()) { name_ = ds.getText(); } if (sememeUsageDescription_ != null && name_ != null) { break; } } } if (StringUtils.isEmpty(sememeUsageDescription_)) { throw new RuntimeException("The Assemblage concept: " + assemblageConcept + " is not correctly assembled for use as an Assemblage for " + "a DynamicSememeData Refex Type. It must contain a description of type Definition with an annotation of type " + "DynamicSememe.DYNAMIC_SEMEME_DEFINITION_DESCRIPTION"); } Get.sememeService().getSememesForComponent(assemblageConcept.getNid()).forEach(sememe -> { if (sememe.getSememeType() == SememeType.DYNAMIC) { @SuppressWarnings("rawtypes") Optional<LatestVersion<? extends DynamicSememe>> sememeVersion = ((SememeChronology) sememe) .getLatestVersion(DynamicSememe.class, StampCoordinates.getDevelopmentLatestActiveOnly()); if (sememeVersion.isPresent()) { @SuppressWarnings("rawtypes") DynamicSememe ds = sememeVersion.get().value(); DynamicSememeDataBI[] refexDefinitionData = ds.getData(); if (sememe.getAssemblageSequence() == IsaacMetadataConstants.DYNAMIC_SEMEME_EXTENSION_DEFINITION .getSequence()) { if (refexDefinitionData == null || refexDefinitionData.length < 3 || refexDefinitionData.length > 7) { throw new RuntimeException("The Assemblage concept: " + assemblageConcept + " is not correctly assembled for use as an Assemblage for " + "a DynamicSememeData Refex Type. It must contain at least 3 columns in the DynamicSememeDataBI attachment, and no more than 7."); } //col 0 is the column number, //col 1 is the concept with col name //col 2 is the column data type, stored as a string. //col 3 (if present) is the default column data, stored as a subtype of DynamicSememeDataBI //col 4 (if present) is a boolean field noting whether the column is required (true) or optional (false or null) //col 5 (if present) is the validator {@link DynamicSememeValidatorType}, stored as a string array. //col 6 (if present) is the validatorData for the validator in column 5, stored as a subtype of DynamicSememeDataBI try { int column = (Integer) refexDefinitionData[0].getDataObject(); UUID descriptionUUID = (UUID) refexDefinitionData[1].getDataObject(); DynamicSememeDataType type = DynamicSememeDataType .valueOf((String) refexDefinitionData[2].getDataObject()); DynamicSememeDataBI defaultData = null; if (refexDefinitionData.length > 3) { defaultData = (refexDefinitionData[3] == null ? null : refexDefinitionData[3]); } if (defaultData != null && type.getDynamicSememeMemberClass() != refexDefinitionData[3] .getDynamicSememeDataType().getDynamicSememeMemberClass()) { throw new IOException("The Assemblage concept: " + assemblageConcept + " is not correctly assembled for use as an Assemblage for " + "a DynamicSememeData Refex Type. The type of the column (column 3) must match the type of the defaultData (column 4)"); } Boolean columnRequired = null; if (refexDefinitionData.length > 4) { columnRequired = (refexDefinitionData[4] == null ? null : (Boolean) refexDefinitionData[4].getDataObject()); } DynamicSememeValidatorType[] validators = null; DynamicSememeDataBI[] validatorsData = null; if (refexDefinitionData.length > 5) { if (refexDefinitionData[5] != null && ((DynamicSememeArrayBI<DynamicSememeStringBI>) refexDefinitionData[5]) .getDataArray().length > 0) { DynamicSememeArrayBI<DynamicSememeStringBI> readValidators = (DynamicSememeArrayBI<DynamicSememeStringBI>) refexDefinitionData[5]; validators = new DynamicSememeValidatorType[readValidators .getDataArray().length]; for (int i = 0; i < validators.length; i++) { validators[i] = DynamicSememeValidatorType .valueOf((String) readValidators.getDataArray()[i].getDataObject()); } } if (refexDefinitionData.length > 6) { if (refexDefinitionData[6] != null && ((DynamicSememeArrayBI<? extends DynamicSememeDataBI>) refexDefinitionData[6]) .getDataArray().length > 0) { DynamicSememeArrayBI<? extends DynamicSememeDataBI> readValidatorsData = (DynamicSememeArrayBI<? extends DynamicSememeDataBI>) refexDefinitionData[6]; validatorsData = new DynamicSememeDataBI[readValidatorsData .getDataArray().length]; for (int i = 0; i < validators.length; i++) { if (readValidatorsData.getDataArray()[i] != null) { validatorsData[i] = readValidatorsData.getDataArray()[i]; } else { validatorsData[i] = null; } } } } } allowedColumnInfo.put(column, new DynamicSememeColumnInfo(assemblageConcept.getPrimordialUuid(), column, descriptionUUID, type, defaultData, columnRequired, validators, validatorsData)); } catch (Exception e) { throw new RuntimeException("The Assemblage concept: " + assemblageConcept + " is not correctly assembled for use as an Assemblage for " + "a DynamicSememeData Refex Type. The first column must have a data type of integer, and the third column must be a string " + "that is parseable as a DynamicSememeDataType"); } } else if (sememe .getAssemblageSequence() == IsaacMetadataConstants.DYNAMIC_SEMEME_REFERENCED_COMPONENT_RESTRICTION .getSequence()) { if (refexDefinitionData == null || refexDefinitionData.length < 1) { throw new RuntimeException("The Assemblage concept: " + assemblageConcept + " is not correctly assembled for use as an Assemblage for " + "a DynamicSememeData Refex Type. If it contains a " + IsaacMetadataConstants.DYNAMIC_SEMEME_REFERENCED_COMPONENT_RESTRICTION .getFSN() + " then it must contain a single column of data, of type string, parseable as a " + ObjectChronologyType.class.getName()); } //col 0 is Referenced component restriction information - as a string. try { ObjectChronologyType type = ObjectChronologyType .parse(refexDefinitionData[0].getDataObject().toString()); if (type == ObjectChronologyType.UNKNOWN_NID) { //just ignore - it shouldn't have been saved that way anyway. } else { referencedComponentTypeRestriction_ = type; } } catch (Exception e) { throw new RuntimeException("The Assemblage concept: " + assemblageConcept + " is not correctly assembled for use as an Assemblage for " + "a DynamicSememeData Refex Type. The component type restriction annotation has an invalid value"); } //col 1 is an optional Referenced component sub-restriction information - as a string. if (refexDefinitionData.length > 1 && refexDefinitionData[1] != null) { try { SememeType type = SememeType .parse(refexDefinitionData[1].getDataObject().toString()); if (type == SememeType.UNKNOWN) { //just ignore - it shouldn't have been saved that way anyway. } else { referencedComponentTypeSubRestriction_ = type; } } catch (Exception e) { throw new RuntimeException("The Assemblage concept: " + assemblageConcept + " is not correctly assembled for use as an Assemblage for " + "a DynamicSememeData Refex Type. The component type restriction annotation has an invalid value"); } } else { referencedComponentTypeSubRestriction_ = null; } } } } }); refexColumnInfo_ = new DynamicSememeColumnInfo[allowedColumnInfo.size()]; int i = 0; for (int key : allowedColumnInfo.keySet()) { if (key != i) { throw new RuntimeException("The Assemblage concept: " + assemblageConcept + " is not correctly assembled for use as an Assemblage for " + "a DynamicSememeData Refex Type. It must contain sequential column numbers, with no gaps, which start at 0."); } refexColumnInfo_[i++] = allowedColumnInfo.get(key); } }
From source file:sh.isaac.model.semantic.DynamicUsageDescriptionImpl.java
/** * Read the RefexUsageDescription data from the database for a given sequence or nid. * * Note that most users should call {@link #read(int)} instead, as that * utilizes a cache. This always reads directly from the DB. * * @param refexUsageDescriptorId sequence or NID of refexUsageDescriptor *//*w w w .j a v a2 s . c o m*/ @SuppressWarnings("unchecked") public DynamicUsageDescriptionImpl(int refexUsageDescriptorId) { final ConceptChronology assemblageConcept = Get.conceptService() .getConceptChronology(refexUsageDescriptorId); this.refexUsageDescriptorNid = assemblageConcept.getNid(); final TreeMap<Integer, DynamicColumnInfo> allowedColumnInfo = new TreeMap<>(); for (final SemanticChronology descriptionSememe : assemblageConcept.getConceptDescriptionList()) { @SuppressWarnings("rawtypes") final LatestVersion descriptionVersion = ((SemanticChronology) descriptionSememe) .getLatestVersion(StampCoordinates.getDevelopmentLatestActiveOnly()); if (descriptionVersion.isPresent()) { @SuppressWarnings("rawtypes") final DescriptionVersion ds = (DescriptionVersion) descriptionVersion.get(); if (ds.getDescriptionTypeConceptNid() == TermAux.DEFINITION_DESCRIPTION_TYPE.getNid()) { final Optional<SemanticChronology> nestesdSememe = Get.assemblageService() .getSemanticChronologyStreamForComponentFromAssemblage(ds.getNid(), DynamicConstants.get().DYNAMIC_DEFINITION_DESCRIPTION.getNid()) .findAny(); if (nestesdSememe.isPresent()) { this.sememeUsageDescription = ds.getText(); } ; } if (ds.getDescriptionTypeConceptNid() == TermAux.FULLY_QUALIFIED_NAME_DESCRIPTION_TYPE.getNid()) { this.name = ds.getText(); } if ((this.sememeUsageDescription != null) && (this.name != null)) { break; } } } if (StringUtils.isEmpty(this.sememeUsageDescription)) { throw new RuntimeException("The Assemblage concept: " + assemblageConcept + " is not correctly assembled for use as an Assemblage for " + "a DynamicSememeData Refex Type. It must contain a description of type Definition with an annotation of type " + "DynamicSememe.DYNAMIC_SEMEME_DEFINITION_DESCRIPTION"); } Get.assemblageService().getSemanticChronologyStreamForComponent(assemblageConcept.getNid()) .forEach(sememe -> { if (sememe.getVersionType() == VersionType.DYNAMIC) { @SuppressWarnings("rawtypes") final LatestVersion<? extends DynamicVersion> sememeVersion = ((SemanticChronology) sememe) .getLatestVersion(StampCoordinates.getDevelopmentLatestActiveOnly()); if (sememeVersion.isPresent()) { @SuppressWarnings("rawtypes") final DynamicVersion ds = sememeVersion.get(); final DynamicData[] refexDefinitionData = ds.getData(); if (sememe.getAssemblageNid() == DynamicConstants.get().DYNAMIC_EXTENSION_DEFINITION .getNid()) { if ((refexDefinitionData == null) || (refexDefinitionData.length < 3) || (refexDefinitionData.length > 7)) { throw new RuntimeException("The Assemblage concept: " + assemblageConcept + " is not correctly assembled for use as an Assemblage for " + "a DynamicSememeData Refex Type. It must contain at least 3 columns in the DynamicSememeDataBI attachment, and no more than 7."); } // col 0 is the column number, // col 1 is the concept with col name // col 2 is the column data type, stored as a string. // col 3 (if present) is the default column data, stored as a subtype of DynamicData // col 4 (if present) is a boolean field noting whether the column is required (true) or optional (false or null) // col 5 (if present) is the validator {@link DynamicValidatorType}, stored as a string array. // col 6 (if present) is the validatorData for the validator in column 5, stored as a subtype of DynamicData try { final int column = (Integer) refexDefinitionData[0].getDataObject(); final UUID descriptionUUID = (UUID) refexDefinitionData[1].getDataObject(); final DynamicDataType type = DynamicDataType .valueOf((String) refexDefinitionData[2].getDataObject()); DynamicData defaultData = null; if (refexDefinitionData.length > 3) { defaultData = ((refexDefinitionData[3] == null) ? null : refexDefinitionData[3]); } if ((defaultData != null) && (type.getDynamicMemberClass() != refexDefinitionData[3] .getDynamicDataType().getDynamicMemberClass())) { throw new IOException("The Assemblage concept: " + assemblageConcept + " is not correctly assembled for use as an Assemblage for " + "a DynamicSememeData Refex Type. The type of the column (column 3) must match the type of the defaultData (column 4)"); } Boolean columnRequired = null; if (refexDefinitionData.length > 4) { columnRequired = ((refexDefinitionData[4] == null) ? null : (Boolean) refexDefinitionData[4].getDataObject()); } DynamicValidatorType[] validators = null; DynamicData[] validatorsData = null; if (refexDefinitionData.length > 5) { if ((refexDefinitionData[5] != null) && ((DynamicArray<DynamicString>) refexDefinitionData[5]) .getDataArray().length > 0) { final DynamicArray<DynamicString> readValidators = (DynamicArray<DynamicString>) refexDefinitionData[5]; validators = new DynamicValidatorType[readValidators .getDataArray().length]; for (int i = 0; i < validators.length; i++) { validators[i] = DynamicValidatorType.valueOf( (String) readValidators.getDataArray()[i].getDataObject()); } } if (refexDefinitionData.length > 6) { if ((refexDefinitionData[6] != null) && ((DynamicArray<? extends DynamicData>) refexDefinitionData[6]) .getDataArray().length > 0) { final DynamicArray<? extends DynamicData> readValidatorsData = (DynamicArray<? extends DynamicData>) refexDefinitionData[6]; validatorsData = new DynamicData[readValidatorsData .getDataArray().length]; if (validators != null) { for (int i = 0; i < validators.length; i++) { if (readValidatorsData.getDataArray()[i] != null) { validatorsData[i] = readValidatorsData .getDataArray()[i]; } else { validatorsData[i] = null; } } } } } } allowedColumnInfo.put(column, new DynamicColumnInfo(assemblageConcept.getPrimordialUuid(), column, descriptionUUID, type, defaultData, columnRequired, validators, validatorsData, null)); } catch (final Exception e) { throw new RuntimeException("The Assemblage concept: " + assemblageConcept + " is not correctly assembled for use as an Assemblage for " + "a DynamicSememeData Refex Type. The first column must have a data type of integer, and the third column must be a string " + "that is parseable as a DynamicSememeDataType"); } } else if (sememe.getAssemblageNid() == DynamicConstants .get().DYNAMIC_SEMEME_REFERENCED_COMPONENT_RESTRICTION.getNid()) { if ((refexDefinitionData == null) || (refexDefinitionData.length < 1)) { throw new RuntimeException("The Assemblage concept: " + assemblageConcept + " is not correctly assembled for use as an Assemblage for " + "a DynamicSememeData Refex Type. If it contains a " + DynamicConstants.get().DYNAMIC_SEMEME_REFERENCED_COMPONENT_RESTRICTION .getPrimaryName() + " then it must contain a single column of data, of type string, parseable as a " + ObjectChronologyType.class.getName()); } // col 0 is Referenced component restriction information - as a string. try { final ObjectChronologyType type = ObjectChronologyType .parse(refexDefinitionData[0].getDataObject().toString(), false); if (type == ObjectChronologyType.UNKNOWN_NID) { // just ignore - it shouldn't have been saved that way anyway. } else { this.referencedComponentTypeRestriction = type; } } catch (final Exception e) { throw new RuntimeException("The Assemblage concept: " + assemblageConcept + " is not correctly assembled for use as an Assemblage for " + "a DynamicSememeData Refex Type. The component type restriction annotation has an invalid value"); } // col 1 is an optional Referenced component sub-restriction information - as a string. if ((refexDefinitionData.length > 1) && (refexDefinitionData[1] != null)) { try { final VersionType type = VersionType .parse(refexDefinitionData[1].getDataObject().toString(), false); if (type == VersionType.UNKNOWN) { // just ignore - it shouldn't have been saved that way anyway. } else { this.referencedComponentTypeSubRestriction = type; } } catch (final Exception e) { throw new RuntimeException("The Assemblage concept: " + assemblageConcept + " is not correctly assembled for use as an Assemblage for " + "a DynamicSememeData Refex Type. The component type restriction annotation has an invalid value"); } } else { this.referencedComponentTypeSubRestriction = null; } } } } }); this.refexColumnInfo = new DynamicColumnInfo[allowedColumnInfo.size()]; int i = 0; for (final int key : allowedColumnInfo.keySet()) { if (key != i) { throw new RuntimeException("The Assemblage concept: " + assemblageConcept + " is not correctly assembled for use as an Assemblage for " + "a DynamicSememeData Refex Type. It must contain sequential column numbers, with no gaps, which start at 0."); } this.refexColumnInfo[i++] = allowedColumnInfo.get(key); } }
From source file:org.sakaiproject.tool.assessment.facade.AssessmentGradingFacadeQueries.java
public List getExportResponsesData(String publishedAssessmentId, boolean anonymous, String audioMessage, String fileUploadMessage, String noSubmissionMessage, boolean showPartAndTotalScoreSpreadsheetColumns, String poolString, String partString, String questionString, String textString, String rationaleString, String itemGradingCommentsString, Map useridMap, String responseCommentString) { ArrayList dataList = new ArrayList(); ArrayList headerList = new ArrayList(); ArrayList finalList = new ArrayList(2); PublishedAssessmentService pubService = new PublishedAssessmentService(); HashSet publishedAssessmentSections = pubService .getSectionSetForAssessment(Long.valueOf(publishedAssessmentId)); Double zeroDouble = new Double(0.0); HashMap publishedAnswerHash = pubService .preparePublishedAnswerHash(pubService.getPublishedAssessment(publishedAssessmentId)); HashMap publishedItemTextHash = pubService .preparePublishedItemTextHash(pubService.getPublishedAssessment(publishedAssessmentId)); HashMap publishedItemHash = pubService .preparePublishedItemHash(pubService.getPublishedAssessment(publishedAssessmentId)); //Get this sorted to add the blank gradings for the questions not answered later. Set publishItemSet = new TreeSet(new ItemComparator()); publishItemSet.addAll(publishedItemHash.values()); int numSubmission = 1; String numSubmissionText = noSubmissionMessage; String lastAgentId = ""; String agentEid = ""; String firstName = ""; String lastName = ""; Set useridSet = new HashSet(useridMap.keySet()); ArrayList responseList = null; boolean canBeExported = false; boolean fistItemGradingData = true; List list = getAllOrderedSubmissions(publishedAssessmentId); Iterator assessmentGradingIter = list.iterator(); while (assessmentGradingIter.hasNext()) { // create new section-item-scores structure for this assessmentGrading Iterator sectionsIter = publishedAssessmentSections.iterator(); HashMap sectionItems = new HashMap(); TreeMap sectionScores = new TreeMap(); while (sectionsIter.hasNext()) { PublishedSectionData publishedSection = (PublishedSectionData) sectionsIter.next(); ArrayList itemsArray = publishedSection.getItemArraySortedForGrading(); Iterator itemsIter = itemsArray.iterator(); // Iterate through the assessment questions (items) HashMap itemsForSection = new HashMap(); while (itemsIter.hasNext()) { ItemDataIfc item = (ItemDataIfc) itemsIter.next(); itemsForSection.put(item.getItemId(), item.getItemId()); }// w w w .j a va 2 s. com sectionItems.put(publishedSection.getSequence(), itemsForSection); sectionScores.put(publishedSection.getSequence(), zeroDouble); } AssessmentGradingData assessmentGradingData = (AssessmentGradingData) assessmentGradingIter.next(); String agentId = assessmentGradingData.getAgentId(); responseList = new ArrayList(); canBeExported = false; if (anonymous) { canBeExported = true; responseList.add(assessmentGradingData.getAssessmentGradingId()); } else { if (useridMap.containsKey(assessmentGradingData.getAgentId())) { useridSet.remove(assessmentGradingData.getAgentId()); canBeExported = true; try { agentEid = userDirectoryService.getUser(assessmentGradingData.getAgentId()).getEid(); firstName = userDirectoryService.getUser(assessmentGradingData.getAgentId()).getFirstName(); lastName = userDirectoryService.getUser(assessmentGradingData.getAgentId()).getLastName(); } catch (Exception e) { log.error("Cannot get user"); } responseList.add(lastName); responseList.add(firstName); responseList.add(agentEid); if (assessmentGradingData.getForGrade()) { if (lastAgentId.equals(agentId)) { numSubmission++; } else { numSubmission = 1; lastAgentId = agentId; } } else { numSubmission = 0; lastAgentId = agentId; } if (numSubmission == 0) { numSubmissionText = noSubmissionMessage; } else { numSubmissionText = String.valueOf(numSubmission); } responseList.add(numSubmissionText); } } if (canBeExported) { int sectionScoreColumnStart = responseList.size(); if (showPartAndTotalScoreSpreadsheetColumns) { Double finalScore = assessmentGradingData.getFinalScore(); if (finalScore != null) { responseList.add((Double) finalScore.doubleValue()); // gopal - cast for spreadsheet numerics } else { log.debug("finalScore is NULL"); responseList.add(0d); } } String assessmentGradingComments = ""; if (assessmentGradingData.getComments() != null) { assessmentGradingComments = assessmentGradingData.getComments().replaceAll("<br\\s*/>", ""); } responseList.add(assessmentGradingComments); Long assessmentGradingId = assessmentGradingData.getAssessmentGradingId(); HashMap studentGradingMap = getStudentGradingData( assessmentGradingData.getAssessmentGradingId().toString(), false); ArrayList grades = new ArrayList(); grades.addAll(studentGradingMap.values()); Collections.sort(grades, new QuestionComparator(publishedItemHash)); //Add the blank gradings for the questions not answered in random pools. if (grades.size() < publishItemSet.size()) { int index = -1; for (Object pido : publishItemSet) { index++; PublishedItemData pid = (PublishedItemData) pido; if (index == grades.size() || ((ItemGradingData) ((List) grades.get(index)).get(0)) .getPublishedItemId().longValue() != pid.getItemId().longValue()) { //have to add the placeholder List newList = new ArrayList(); newList.add(new EmptyItemGrading(pid.getSection().getSequence(), pid.getItemId(), pid.getSequence())); grades.add(index, newList); } } } int questionNumber = 0; for (Object oo : grades) { // There can be more than one answer to a question, e.g. for // FIB with more than one blank or matching questions. So sort // by sequence number of answer. (don't bother to sort if just 1) List l = (List) oo; if (l.size() > 1) Collections.sort(l, new AnswerComparator(publishedAnswerHash)); String maintext = ""; String rationale = ""; String responseComment = ""; boolean addRationale = false; boolean addResponseComment = false; boolean matrixChoices = false; TreeMap responsesMap = new TreeMap(); // loop over answers per question int count = 0; ItemGradingData grade = null; //boolean isAudioFileUpload = false; boolean isFinFib = false; double itemScore = 0.0d; //Add the missing sequences! //To manage emi answers, could help with others too Map<Long, String> emiAnswerText = new TreeMap<Long, String>(); for (Object ooo : l) { grade = (ItemGradingData) ooo; if (grade == null || EmptyItemGrading.class.isInstance(grade)) { continue; } if (grade != null && grade.getAutoScore() != null) { itemScore += grade.getAutoScore().doubleValue(); } // now print answer data log.debug("<br> " + grade.getPublishedItemId() + " " + grade.getRationale() + " " + grade.getAnswerText() + " " + grade.getComments() + " " + grade.getReview()); Long publishedItemId = grade.getPublishedItemId(); ItemDataIfc publishedItemData = (ItemDataIfc) publishedItemHash.get(publishedItemId); Long typeId = publishedItemData.getTypeId(); questionNumber = publishedItemData.getSequence(); if (typeId.equals(TypeIfc.FILL_IN_BLANK) || typeId.equals(TypeIfc.FILL_IN_NUMERIC) || typeId.equals(TypeIfc.CALCULATED_QUESTION)) { log.debug("FILL_IN_BLANK, FILL_IN_NUMERIC"); isFinFib = true; String thistext = ""; Long answerid = grade.getPublishedAnswerId(); Long sequence = null; if (answerid != null) { AnswerIfc answer = (AnswerIfc) publishedAnswerHash.get(answerid); if (answer != null) { sequence = answer.getSequence(); } } String temptext = grade.getAnswerText(); if (temptext == null) { temptext = "No Answer"; } thistext = sequence + ": " + temptext; if (count == 0) maintext = thistext; else maintext = maintext + "|" + thistext; count++; } else if (typeId.equals(TypeIfc.MATCHING)) { log.debug("MATCHING"); String thistext = ""; // for some question types we have another text field Long answerid = grade.getPublishedAnswerId(); String temptext = "No Answer"; Long sequence = null; if (answerid != null) { AnswerIfc answer = (AnswerIfc) publishedAnswerHash.get(answerid); if (answer != null) { temptext = answer.getText(); if (temptext == null) { temptext = "No Answer"; } sequence = answer.getItemText().getSequence(); } else if (answerid == -1) { temptext = "None of the Above"; ItemTextIfc itemTextIfc = (ItemTextIfc) publishedItemTextHash .get(grade.getPublishedItemTextId()); sequence = itemTextIfc.getSequence(); } } else { ItemTextIfc itemTextIfc = (ItemTextIfc) publishedItemTextHash .get(grade.getPublishedItemTextId()); sequence = itemTextIfc.getSequence(); } thistext = sequence + ": " + temptext; if (count == 0) maintext = thistext; else maintext = maintext + "|" + thistext; count++; } else if (typeId.equals(TypeIfc.IMAGEMAP_QUESTION)) { log.debug("MATCHING"); ItemTextIfc itemTextIfc = (ItemTextIfc) publishedItemTextHash .get(grade.getPublishedItemTextId()); Long sequence = itemTextIfc.getSequence(); String temptext = (grade.getIsCorrect()) ? "OK" : "No OK"; String thistext = sequence + ": " + temptext; if (count == 0) maintext = thistext; else maintext = maintext + "|" + thistext; count++; } else if (typeId.equals(TypeIfc.IMAGEMAP_QUESTION)) { log.debug("MATCHING"); ItemTextIfc itemTextIfc = (ItemTextIfc) publishedItemTextHash .get(grade.getPublishedItemTextId()); Long sequence = itemTextIfc.getSequence(); String temptext = (grade.getIsCorrect()) ? "OK" : "No OK"; String thistext = sequence + ": " + temptext; if (count == 0) maintext = thistext; else maintext = maintext + "|" + thistext; count++; } else if (typeId.equals(TypeIfc.IMAGEMAP_QUESTION)) { log.debug("MATCHING"); ItemTextIfc itemTextIfc = (ItemTextIfc) publishedItemTextHash .get(grade.getPublishedItemTextId()); Long sequence = itemTextIfc.getSequence(); String temptext = (grade.getIsCorrect()) ? "OK" : "No OK"; String thistext = sequence + ": " + temptext; if (count == 0) maintext = thistext; else maintext = maintext + "|" + thistext; count++; } else if (typeId.equals(TypeIfc.EXTENDED_MATCHING_ITEMS)) { log.debug("EXTENDED_MATCHING_ITEMS"); String thistext = ""; // for some question types we have another text field Long answerid = grade.getPublishedAnswerId(); String temptext = "No Answer"; Long sequence = null; if (answerid != null) { AnswerIfc answer = (AnswerIfc) publishedAnswerHash.get(answerid); if (answer != null) { temptext = answer.getLabel(); if (temptext == null) { temptext = "No Answer"; } sequence = answer.getItemText().getSequence(); } } if (sequence == null) { ItemTextIfc itemTextIfc = (ItemTextIfc) publishedItemTextHash .get(grade.getPublishedItemTextId()); if (itemTextIfc != null) { sequence = itemTextIfc.getSequence(); } } if (sequence != null) { thistext = emiAnswerText.get(sequence); if (thistext == null) { thistext = temptext; } else { thistext = thistext + temptext; } emiAnswerText.put(sequence, thistext); } else { // Orphaned answer: the answer item to which it refers was removed after the assessment was taken, // as a result of editing the published assessment. This behaviour should be fixed, i.e. it should // not be possible to get orphaned answer item references in the database. sequence = new Long(99); emiAnswerText.put(sequence, "Item Removed"); } } else if (typeId.equals(TypeIfc.MATRIX_CHOICES_SURVEY)) { log.debug("MATRIX_CHOICES_SURVEY"); // for this kind of question a responsesMap is generated matrixChoices = true; Long answerid = grade.getPublishedAnswerId(); String temptext = "No Answer"; Long sequence = null; if (answerid != null) { AnswerIfc answer = (AnswerIfc) publishedAnswerHash.get(answerid); temptext = answer.getText(); if (temptext == null) { temptext = "No Answer"; } sequence = answer.getItemText().getSequence(); } else { ItemTextIfc itemTextIfc = (ItemTextIfc) publishedItemTextHash .get(grade.getPublishedItemTextId()); sequence = itemTextIfc.getSequence(); log.debug( "Answerid null for " + grade.getPublishedItemId() + ". Adding " + sequence); temptext = "No Answer"; } responsesMap.put(sequence, temptext); } else if (typeId.equals(TypeIfc.AUDIO_RECORDING)) { log.debug("AUDIO_RECORDING"); maintext = audioMessage; //isAudioFileUpload = true; } else if (typeId.equals(TypeIfc.FILE_UPLOAD)) { log.debug("FILE_UPLOAD"); maintext = fileUploadMessage; //isAudioFileUpload = true; } else if (typeId.equals(TypeIfc.ESSAY_QUESTION)) { log.debug("ESSAY_QUESTION"); if (grade.getAnswerText() != null) { maintext = grade.getAnswerText(); } } else { log.debug("other type"); String thistext = ""; // for some question types we have another text field Long answerid = grade.getPublishedAnswerId(); if (answerid != null) { AnswerIfc answer = (AnswerIfc) publishedAnswerHash.get(answerid); if (answer != null) { String temptext = answer.getText(); if (temptext != null) thistext = temptext; } else { log.warn("Published answer for " + answerid + " is null"); } } if (count == 0) maintext = thistext; else maintext = maintext + "|" + thistext; count++; } // taking care of rationale if (!addRationale && (typeId.equals(TypeIfc.MULTIPLE_CHOICE) || typeId.equals(TypeIfc.MULTIPLE_CORRECT) || typeId.equals(TypeIfc.MULTIPLE_CORRECT_SINGLE_SELECTION) || typeId.equals(TypeIfc.TRUE_FALSE))) { log.debug( "MULTIPLE_CHOICE or MULTIPLE_CORRECT or MULTIPLE_CORRECT_SINGLE_SELECTION or TRUE_FALSE"); if (publishedItemData.getHasRationale() != null && publishedItemData.getHasRationale()) { addRationale = true; rationale = grade.getRationale(); if (rationale == null) { rationale = ""; } } } //Survey - Matrix of Choices - Add Comment Field if (typeId.equals(TypeIfc.MATRIX_CHOICES_SURVEY)) { PublishedItemData pid = (PublishedItemData) publishedItemData; if (pid.getAddCommentFlag()) { addResponseComment = true; if (responseComment.equals("") && grade.getAnswerText() != null) { responseComment = grade.getAnswerText(); } } } } // inner for - answers if (!emiAnswerText.isEmpty()) { if (maintext == null) { maintext = ""; } for (Entry<Long, String> entry : emiAnswerText.entrySet()) { maintext = maintext + "|" + entry.getKey().toString() + ":" + entry.getValue(); } if (maintext.startsWith("|")) { maintext = maintext.substring(1); } } Integer sectionSequenceNumber = null; if (grade == null || EmptyItemGrading.class.isInstance(grade)) { sectionSequenceNumber = EmptyItemGrading.class.cast(grade).getSectionSequence(); questionNumber = EmptyItemGrading.class.cast(grade).getItemSequence(); // indicate that the student was not presented with this question maintext = "-"; } else { sectionSequenceNumber = updateSectionScore(sectionItems, sectionScores, grade.getPublishedItemId(), itemScore); } if (isFinFib && maintext.indexOf("No Answer") >= 0 && count == 1) { maintext = "No Answer"; } else if ("".equals(maintext)) { maintext = "No Answer"; } String itemGradingComments = ""; // if question type is not matrix choices apply the original code if (!matrixChoices) { responseList.add(maintext); if (grade.getComments() != null) { itemGradingComments = grade.getComments().replaceAll("<br\\s*/>", ""); } responseList.add(itemGradingComments); } else { // if there are questions not answered, a no answer response is added to the map ItemDataIfc correspondingPublishedItemData = (ItemDataIfc) publishedItemHash .get(grade.getPublishedItemId()); List correspondingItemTextArray = correspondingPublishedItemData.getItemTextArray(); log.debug("publishedItem is " + correspondingPublishedItemData.getText() + " and number of rows " + correspondingItemTextArray.size()); if (responsesMap.size() < correspondingItemTextArray.size()) { Iterator itItemTextHash = correspondingItemTextArray.iterator(); while (itItemTextHash.hasNext()) { ItemTextIfc itemTextIfc = (ItemTextIfc) itItemTextHash.next(); if (!responsesMap.containsKey(itemTextIfc.getSequence())) { log.debug("responsesMap does not contain answer to " + itemTextIfc.getText()); responsesMap.put(itemTextIfc.getSequence(), "No Answer"); } } } Iterator it = responsesMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry e = (Map.Entry) it.next(); log.debug("Adding to response list " + e.getKey() + " and " + e.getValue()); responseList.add(e.getValue()); if (grade.getComments() != null) { itemGradingComments = grade.getComments().replaceAll("<br\\s*/>", ""); } responseList.add(itemGradingComments); itemGradingComments = ""; } } if (addRationale) { responseList.add(rationale); } if (addResponseComment) { responseList.add(responseComment); } // Only set header based on the first item grading data if (fistItemGradingData) { //get the pool name String poolName = null; for (Iterator i = publishedAssessmentSections.iterator(); i.hasNext();) { PublishedSectionData psd = (PublishedSectionData) i.next(); if (psd.getSequence().intValue() == sectionSequenceNumber) { poolName = psd.getSectionMetaDataByLabel(SectionDataIfc.POOLNAME_FOR_RANDOM_DRAW); } } if (!matrixChoices) { headerList.add(makeHeader(partString, sectionSequenceNumber, questionString, textString, questionNumber, poolString, poolName)); if (addRationale) { headerList.add(makeHeader(partString, sectionSequenceNumber, questionString, rationaleString, questionNumber, poolString, poolName)); } if (addResponseComment) { headerList.add(makeHeader(partString, sectionSequenceNumber, questionString, responseCommentString, questionNumber, poolString, poolName)); } headerList.add(makeHeader(partString, sectionSequenceNumber, questionString, itemGradingCommentsString, questionNumber, poolString, poolName)); } else { int numberRows = responsesMap.size(); for (int i = 0; i < numberRows; i = i + 1) { headerList.add(makeHeaderMatrix(partString, sectionSequenceNumber, questionString, textString, questionNumber, i + 1, poolString, poolName)); if (addRationale) { headerList .add(makeHeaderMatrix(partString, sectionSequenceNumber, questionString, rationaleString, questionNumber, i + 1, poolString, poolName)); } if (addResponseComment) { headerList.add(makeHeaderMatrix(partString, sectionSequenceNumber, questionString, responseCommentString, questionNumber, i + 1, poolString, poolName)); } headerList.add(makeHeaderMatrix(partString, sectionSequenceNumber, questionString, itemGradingCommentsString, questionNumber, i + 1, poolString, poolName)); } } } } // outer for - questions if (showPartAndTotalScoreSpreadsheetColumns) { if (sectionScores.size() > 1) { Iterator keys = sectionScores.keySet().iterator(); while (keys.hasNext()) { Double partScore = (Double) ((Double) sectionScores.get(keys.next())).doubleValue(); responseList.add(sectionScoreColumnStart++, partScore); } } } dataList.add(responseList); if (fistItemGradingData) { fistItemGradingData = false; } } } // while if (!anonymous && useridSet.size() != 0) { Iterator iter = useridSet.iterator(); while (iter.hasNext()) { String id = (String) iter.next(); try { agentEid = userDirectoryService.getUser(id).getEid(); firstName = userDirectoryService.getUser(id).getFirstName(); lastName = userDirectoryService.getUser(id).getLastName(); } catch (Exception e) { log.error("Cannot get user"); } responseList = new ArrayList(); responseList.add(lastName); responseList.add(firstName); responseList.add(agentEid); responseList.add(noSubmissionMessage); dataList.add(responseList); } } Collections.sort(dataList, new ResponsesComparator(anonymous)); finalList.add(dataList); finalList.add(headerList); return finalList; }