List of usage examples for java.util Vector get
public synchronized E get(int index)
From source file:gskproject.Analyze.java
public void personWiseTableload() { multiMap = new HashMap<Object, Object[]>(); userList = new ArrayList<User>(); if (ddDepartment.getSelectedIndex() == 0) { userList = dbOps.getUser();// ww w .jav a 2 s . c o m } else { userList = dbOps.getUser(ddDepartment.getSelectedIndex()); } java.sql.Date from; java.sql.Date to; if (dtPFrom.getDate() == null && dtPTo.getDate() == null) { from = null; to = null; } else if (dtPFrom.getDate() == null) { from = null; to = new java.sql.Date(dtPTo.getDate().getTime()); } else if (dtPTo.getDate() == null) { from = new java.sql.Date(dtPFrom.getDate().getTime()); to = null; } else { from = new java.sql.Date(dtPFrom.getDate().getTime()); to = new java.sql.Date(dtPTo.getDate().getTime()); } Vector<String> columnNames = new Vector<String>(); columnNames.addElement("Person"); columnNames.addElement("Total No: of Cases"); columnNames.addElement("No:of Cases(Responsible Party)"); columnNames.addElement("Open Cases(Responsible party)"); columnNames.addElement("Open Cases Percentage(Resposible Party)"); columnNames.addElement("No:of Cases(Observer)"); columnNames.addElement("Open Cases(Observer)"); columnNames.addElement("Open Cases Percentage(Observer)"); if (from != null && to != null) { if (to.after(from)) { tableObservation = dbOps.getAnalyzeObservation(from, to); if (tableObservation.size() > 0) { for (User user : userList) { Object[] array = new Object[6]; array[0] = user.getUsername(); array[1] = 0; array[2] = 0; array[3] = 0; array[4] = 0; array[5] = 0; multiMap.put(user.getUserID(), array); } for (Vector row : tableObservation) { Object[] arrayRes = multiMap.get(row.get(7)); if (arrayRes != null) { arrayRes[2] = (int) arrayRes[2] + 1; arrayRes[1] = (int) arrayRes[1] + 1; if (row.get(8).equals("Open")) { arrayRes[3] = (int) arrayRes[3] + 1; } } Object[] arrayOb = multiMap.get(row.get(6)); if (arrayOb != null) { arrayOb[4] = (int) arrayOb[4] + 1; arrayOb[1] = (int) arrayOb[1] + 1; if (row.get(8).equals("Open")) { arrayOb[5] = (int) arrayOb[5] + 1; } } } tablePersonWise = new Vector<Vector>(); for (int i = 0; i < multiMap.size(); i++) { Vector<Object> row = new Vector<Object>(); int userID = userList.get(i).getUserID(); row.addElement(multiMap.get(userID)[0]); row.addElement((int) multiMap.get(userID)[2] + (int) multiMap.get(userID)[4]); row.addElement(multiMap.get(userID)[2]); row.addElement(multiMap.get(userID)[3]); if ((int) multiMap.get(userID)[2] != 0) { row.addElement(((Double.parseDouble(multiMap.get(userID)[3].toString()) / (int) multiMap.get(userID)[2]) * 100) + "%"); } else { row.addElement(0); } row.addElement(multiMap.get(userID)[4]); row.addElement(multiMap.get(userID)[5]); if ((int) multiMap.get(userID)[4] != 0) { row.addElement(((Double.parseDouble(multiMap.get(userID)[5].toString()) / (int) multiMap.get(userID)[4]) * 100) + "%"); } else { row.addElement(0); } tablePersonWise.addElement(row); } tblPersonVise.setModel(new DefaultTableModel(tablePersonWise, columnNames)); } else { JOptionPane.showMessageDialog(this, "There are no observation between above days!"); dtPFrom.setDate(null); dtPTo.setDate(null); } } else { JOptionPane.showMessageDialog(this, "Wrong Date Entry (from date > to date)!"); dtPFrom.setDate(null); dtPTo.setDate(null); } } else { tableObservation = dbOps.getAnalyzeObservation(from, to); if (tableObservation.size() > 0) { for (User user : userList) { Object[] array = new Object[6]; array[0] = user.getUsername(); array[1] = 0; array[2] = 0; array[3] = 0; array[4] = 0; array[5] = 0; multiMap.put(user.getUserID(), array); } for (Vector row : tableObservation) { Object[] arrayRes = multiMap.get(row.get(7)); if (arrayRes != null) { arrayRes[2] = (int) arrayRes[2] + 1; arrayRes[1] = (int) arrayRes[1] + 1; if (row.get(8).equals("Open")) { arrayRes[3] = (int) arrayRes[3] + 1; } } Object[] arrayOb = multiMap.get(row.get(6)); if (arrayOb != null) { arrayOb[4] = (int) arrayOb[4] + 1; arrayOb[1] = (int) arrayOb[1] + 1; if (row.get(8).equals("Open")) { arrayOb[5] = (int) arrayOb[5] + 1; } } } tablePersonWise = new Vector<Vector>(); for (int i = 0; i < multiMap.size(); i++) { Vector<Object> row = new Vector<Object>(); int userID = userList.get(i).getUserID(); row.addElement(multiMap.get(userID)[0]); row.addElement((int) multiMap.get(userID)[2] + (int) multiMap.get(userID)[4]); row.addElement(multiMap.get(userID)[2]); row.addElement(multiMap.get(userID)[3]); if ((int) multiMap.get(userID)[2] != 0) { row.addElement(((Double.parseDouble(multiMap.get(userID)[3].toString()) / (int) multiMap.get(userID)[2]) * 100) + "%"); } else { row.addElement(0); } row.addElement(multiMap.get(userID)[4]); row.addElement(multiMap.get(userID)[5]); if ((int) multiMap.get(userID)[4] != 0) { row.addElement(((Double.parseDouble(multiMap.get(userID)[5].toString()) / (int) multiMap.get(userID)[4]) * 100) + "%"); } else { row.addElement(0); } tablePersonWise.addElement(row); } tblPersonVise.setModel(new DefaultTableModel(tablePersonWise, columnNames)); } else { JOptionPane.showMessageDialog(this, "There are no observation between above days!"); dtPFrom.setDate(null); dtPTo.setDate(null); } } }
From source file:edu.ku.brc.specify.toycode.mexconabio.MexConvToSQLNew.java
/** * //from w ww.ja v a2s. c o m */ public void convertFROMCSV(final ConfigureCSV config, final CsvReader csv) { String str = ""; int strLen = 0; int inx = 0; CsvReader csvObj = null; Connection conn = null; Statement stmt = null; try { conn = DriverManager.getConnection( "jdbc:mysql://localhost/mex?characterEncoding=UTF-8&autoReconnect=true", "root", "root"); stmt = conn.createStatement(); StringBuilder pStmtStr = new StringBuilder(); StringBuilder sb = new StringBuilder(); StringBuilder ques = new StringBuilder(); int[] fieldLengths = null; BasicSQLUtils.deleteAllRecordsFromTable(conn, "mex", SERVERTYPE.MySQL); Vector<Integer> types = new Vector<Integer>(); Vector<String> names = new Vector<String>(); File file = new File("/Users/rods/Documents/Untitled.mer"); Element root = XMLHelper.readFileToDOM4J(new File("/Users/rods/Documents/Acer.xml")); if (root != null) { fieldLengths = new int[csv.getColumnCount()]; for (int i = 0; i < fieldLengths.length; i++) { fieldLengths[i] = 0; } int row = 0; while (csv.readRecord()) { row++; for (int col = 0; col < csv.getColumnCount(); col++) { String dataObj = csv.get(col); int len = dataObj.length() + 1; if (len > fieldLengths[inx]) { fieldLengths[inx] = len; } inx++; } if (row % 10000 == 0) System.out.println(row); } System.out.println("--------------"); HashMap<String, Integer> hashSize = new HashMap<String, Integer>(); for (int i = 0; i < names.size(); i++) { hashSize.put(names.get(i), fieldLengths[i]); System.out.println(names.get(i) + " -> " + fieldLengths[i]); } sb.append("CREATE TABLE mex ("); List<?> items = root.selectNodes("/FIELDS/FIELD"); //$NON-NLS-1$ System.out.println(items.size()); inx = 0; for (Iterator<?> capIter = items.iterator(); capIter.hasNext();) { Element fieldNode = (Element) capIter.next(); String nullOK = fieldNode.attributeValue("EMPTYOK"); //$NON-NLS-1$ String fldName = fixName(fieldNode.attributeValue("NAME").trim()); //$NON-NLS-1$ String type = fieldNode.attributeValue("TYPE"); //$NON-NLS-1$ sb.append("`"); sb.append(fldName); sb.append("` "); System.err.println("[" + fldName + "]"); int len = hashSize.get(fldName); if (pStmtStr.length() > 0) pStmtStr.append(','); pStmtStr.append("`" + fldName + "`"); if (ques.length() > 0) ques.append(','); ques.append("?"); if (type.equals("TEXT")) { if (StringUtils.contains(fldName, "img folder")) { sb.append("longtext "); } else { sb.append("VARCHAR(" + len + ") CHARACTER SET utf8 "); } types.add(DataType.TEXT.ordinal()); } else if (type.equals("NUMBER")) { sb.append("DOUBLE "); types.add(DataType.NUMBER.ordinal()); } else if (type.equals("DATE")) { sb.append("DATE "); types.add(DataType.DATE.ordinal()); } else if (type.equals("TIME")) { sb.append("VARCHAR(16) "); types.add(DataType.TIME.ordinal()); } else { System.err.println("Unhandled Type[" + type + "]"); } sb.append(nullOK.equals("YES") ? "DEFAULT NULL," : ","); sb.append("\n"); inx++; } sb.setLength(sb.length() - 2); sb.append(") ENGINE=MyISAM DEFAULT CHARSET=utf8;"); } SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); int rowCnt = 0; try { String stmtStr = "INSERT INTO mex (" + pStmtStr + ") VALUES(" + ques + ")"; System.out.println(stmtStr); try { stmt.executeUpdate("DROP TABLE mex"); } catch (SQLException e) { } System.err.println(sb.toString()); stmt.executeUpdate(sb.toString()); PreparedStatement pStmt = conn.prepareStatement(stmtStr); csv.close(); csvObj = new CsvReader(new FileInputStream(config.getFile()), config.getDelimiter(), config.getCharset()); csvObj.readRecord(); // skip header int row = 0; while (csvObj.readRecord()) { row++; for (int col = 0; col < csvObj.getColumnCount(); col++) { String dataStr = csvObj.get(col); strLen = dataStr.length(); switch (types.get(inx)) { case 3: case 0: { if (strLen > 0) { if (strLen <= fieldLengths[inx]) { pStmt.setString(col, dataStr); } else { System.err.println(String.format("The data for `%s` (%d) is too big %d", names.get(inx), fieldLengths[inx], strLen)); pStmt.setString(col, null); } } else { pStmt.setString(col, null); } } break; case 1: { if (StringUtils.isNotEmpty(dataStr)) { if (StringUtils.isNumeric(dataStr)) { pStmt.setDouble(col, strLen > 0 ? Double.parseDouble(dataStr) : null); } else { System.err.println(col + " Bad Number[" + dataStr + "] "); pStmt.setDate(col, null); } } else { pStmt.setDate(col, null); } } break; case 2: { try { if (StringUtils.isNotEmpty(dataStr)) { if (StringUtils.contains(dataStr, "/")) { dataStr = StringUtils.replace(dataStr, "/", "-"); } else if (StringUtils.contains(dataStr, " ")) { dataStr = StringUtils.replace(dataStr, " ", "-"); } pStmt.setDate(col, strLen > 0 ? new java.sql.Date(sdf.parse(dataStr).getTime()) : null); } else { pStmt.setDate(col, null); } } catch (Exception ex) { System.err.println(col + " Bad Date[" + dataStr + "]\n" + str); pStmt.setDate(col, null); } } break; default: { System.err.println("Error - " + types.get(inx)); } } inx++; col++; } pStmt.execute(); row++; } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (Exception e) { System.err.println("Row: " + rowCnt); System.err.println(str); System.err.println(inx + " " + fieldLengths[inx] + " - Field Len: " + strLen); e.printStackTrace(); } finally { if (csvObj != null) { csvObj.close(); } } } catch (Exception ex) { ex.printStackTrace(); } finally { try { stmt.close(); conn.close(); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:at.tuwien.ifs.somtoolbox.reportgenerator.output.SOMDescriptionLATEX.java
/** * this function prints some information about the possible clusters that can be found on the SOM. It tries to find * some good, or stable clusters, using a simple heuristic. For a description of this, please see * TestRunResult.getStableClusters2. (it works at least quite well with the iris and the animal dataset - more test * tbd. as maximal number of clusters, the number of units on the SOM is choosen. Besides the tree of available * clusters, the ten "best" (according to this heuristic clusters are listed and visualized. Also the image of the * UMatrix of the SOM is created and attached to the report !!! I also wanted to do some tests with the k-nearest * neighbour clustering, but couldn't find any implementation of it. !!! *///from ww w. j a v a 2s . c om protected void printClusterInfos() { this.writer.appendLatexOutput("\\section{Clusters on the SOM:}\n"); // an image of the UMatrix of the SOM if (this.testrun.createUDMatrixImage(this.imgDir, "umatrix.jpg", 30, 1)) { this.writer.appendLatexOutput("\\subsection{The U-Matrix visualization of the SOM:}\n"); this.writer.appendLatexOutput(TextualDescriptionProvider.getScientificDescription("uMatrix") + "Light, green areas on the map indicate small distances between units, whereas" + "dark, red areas indicate bigger distances.\\\\\n"); if (this.testrun.getGrowingSOM().getLayer().getXSize() * this.testrun.getGrowingSOM().getLayer().getYSize() < this.dataset.getNumberOfInputVectors()) { this.writer.appendOutput( "Since the number of prototype Vectors is smaller than the number of Training Samples, the U-Matrix Visualization contains no artifacts."); } else { this.writer.appendOutput( "Since the number of prototype Vectors is larger than the number of Training Samples, the U-Matrix Visualization contains artifacts around the positions, where data samples are mapped."); } this.writer.appendOutput("\\begin{figure}[htbp]\n" + "\\centering" + "\\includegraphics[width=4.5cm]{" + SOMDescriptionLATEX.imgSubdir + "/run_" + this.testrun.getRunId() + "_umatrix.jpg}\n" + "\\caption{The U-Matrix}" + "\\label{fig:UMatrix}" + "\\end{figure}\n"); } ClusterNode node = this.testrun.getClusterNodes(1, 1); // the root node of the cluster Tree // print the cluster tree /* * this.writer.appendLatexOutput("\\paragraph{The cluster tree</p>"); this.writer.appendLatexOutput("The following is a representation of the * cluster tree. For each cluster (=node of the tree), its level (that " + "is the number of the step in which the node is splitted) is given, * as well as the number of steps for that the node isn't splitted into two subclusters. By " + "clicking onto a node, the subtree rooted in * this node can be expanded/collapsed. (at the beginning, the whole tree is collapsed)"); * this.writer.appendLatexOutput("\\begin{itemize}\n"); */ int somDim = Integer.parseInt((String) this.testrun.getMapProperty(TestRunResultCollection.keyXDim)) * Integer.parseInt((String) this.testrun.getMapProperty(TestRunResultCollection.keyYDim)); /* * as we have no possibility to retrieve the depth of a node within the tree, given the node efficiently, and because we are netherless * traversing the tree once, we save for all node their depths. this is done in the nodeInfos array at the indices 2 ... n+1 (for node 1 ... * n). on position 0, the level of the node that is stable for the most number of steps, and on position 1, the according number of steps is * saved */ int[] nodeInfos = new int[somDim + 2]; nodeInfos[0] = 0; nodeInfos[1] = 0; // nodeInfos = this.printClusterNode(node, 1, somDim, 1, nodeInfos); // this.writer.appendLatexOutput("\\end{itemize}\n"); // this.writer.appendLatexOutput("\\max stable is level " + nodeInfos[1] + " for "+nodeInfos[0] + // " new clusters"); // print the top ten list and then the visualizations of it: // our second (and final) method Vector<double[]> stableList2 = this.testrun.getStableClusters2(node, 0.0, somDim, new Vector<double[]>()); this.writer.appendLatexOutput("\n\\subsection{Top ten stable clusters:}\n"); this.writer.appendLatexOutput( "The following list contains the 10 most stable clusters (selected according to a simple heurstic). For each cluster," + " the number of input items lying in this cluster is given. Also how the classes are distributed within the cluster. Also, for each cluster " + "a suggested name is displayed. A bigger image of the cluster can be retrieved by clicking onto the cluster image."); this.writer.appendLatexOutput("\\begin{itemize}"); for (int i = 0; i < 10 && i < stableList2.size(); i++) { Vector<String> clusterNames = this.dataset.getClusterName( this.testrun.getClusterNodes((int) stableList2.get(i)[1], 1), (int) CommonSOMViewerStateData.getInstance().clusterByValue, nodeInfos[(int) stableList2.get(i)[1]]); String label = ""; for (int j = 0; j < clusterNames.size(); j++) { if (j > 0) { label += "; "; } label += clusterNames.get(j); } this.writer.appendLatexOutput("\\item \\begin{itemize}\\item cluster " + label + "\\newline on level " + stableList2.get(i)[1] + " with gain = " + String.format("%.4f", stableList2.get(i)[0]) + "\\\\" + this.testrun.getClusterNodes((int) stableList2.get(i)[1], 1).getNumberOfInputs() + " inputs in cluster\\\\" + classDistInCluster((int) stableList2.get(i)[1], this.testrun.getClusterNodes((int) stableList2.get(i)[1], 1).getNumberOfInputs())/* * + "\\\\<a * href=\"#clusterVis_"+i+"\">(see)</a></td>" */); this.testrun.visualizeCluster((int) stableList2.get(i)[1], this.imgDir, nodeInfos, 50); this.testrun.visualizeCluster((int) stableList2.get(i)[1], this.imgDir, nodeInfos, 10); this.writer.appendOutput("\\includegraphics{" + SOMDescriptionLATEX.imgSubdir + "/run_" + this.testrun.getRunId() + "_clusterLevel_" + (int) stableList2.get(i)[1] + "_10.jpg}\n"); this.writer.appendLatexOutput("\\end{itemize}\n"); } this.writer.appendLatexOutput("\\end{itemize}"); /* * this.writer.appendLatexOutput("\\paragraph{visualization of top ten clusters:</p>"); for(int i = 0; i < 10; i++){ if( && * this.testrun.visualizeCluster((int)stableList2.get(i)[1], this.imgDir, nodeInfos, 10)){ this.writer.appendLatexOutput("<p * class=\"header2\"><a name=\"clusterVis_"+i+"\">level "+ stableList2.get(i)[1] +"</a>\\\\" + "<img * src=\""+SOMDescriptionHTML.imgSubdir+"/run_"+this.testrun.getRunId()+"_clusterLevel_"+(int)stableList2.get(i)[1]+".jpg\" alt=\"\"/>" + * "</p>"); } } */ /* * I also tried this .... //our first method - didn't work quie well, for more information, please see TestRunRest.getStableClusters1() * Vector<double[]> stableList1 = this.testrun.getStableClusters1(node, 1, somDim, new Vector<double[]>()); * this.writer.appendLatexOutput("top ten stable clusters:"); this.writer.appendLatexOutput("\\begin{itemize}"); for(int i = 0; i < * stableList1.size(); i++){ this.writer.appendLatexOutput("\\item level "+ stableList1.get(i)[1] +" with " + stableList1.get(i)[0] + ""); } * this.writer.appendLatexOutput("\\end{itemize}"); //our third method - didn't work quie well, for more information, please see * TestRunRest.getStableClusters13() Vector<double[]> stableList3 = this.testrun.getStableClusters3(node, 0.0, somDim, new * Vector<double[]>()); this.writer.appendLatexOutput("top ten stable clusters:"); this.writer.appendLatexOutput("\\begin{itemize}"); for(int * i = 0; i < stableList3.size(); i++){ this.writer.appendLatexOutput("\\item level "+ stableList3.get(i)[1] +" with " + stableList3.get(i)[0] * + ""); } this.writer.appendLatexOutput("\\end{itemize}"); */ }
From source file:com.pemikir.youtubeplus.youtube.YoutubeExtractor.java
@Override public VideoInfo getVideoInfo(String siteUrl) { String site = Downloader.download(siteUrl); VideoInfo videoInfo = new VideoInfo(); Document doc = Jsoup.parse(site, siteUrl); try {/*from w w w . j a va 2s .com*/ Pattern p = Pattern.compile("v=([0-9a-zA-Z]*)"); Matcher m = p.matcher(siteUrl); m.find(); videoInfo.id = m.group(1); } catch (Exception e) { e.printStackTrace(); } videoInfo.age_limit = 0; videoInfo.webpage_url = siteUrl; //------------------------------------- // extracting form player args //------------------------------------- JSONObject playerArgs = null; JSONObject ytAssets = null; String dashManifest = ""; { Pattern p = Pattern.compile("ytplayer.config\\s*=\\s*(\\{.*?\\});"); Matcher m = p.matcher(site); m.find(); try { playerArgs = (new JSONObject(m.group(1))).getJSONObject("args"); ytAssets = (new JSONObject(m.group(1))).getJSONObject("assets"); } catch (Exception e) { e.printStackTrace(); // If we fail in this part the video is most likely not available. // Determining why is done later. videoInfo.videoAvailableStatus = VideoInfo.VIDEO_UNAVAILABLE; } } try { videoInfo.uploader = playerArgs.getString("author"); videoInfo.title = playerArgs.getString("title"); //first attempt gating a small image version //in the html extracting part we try to get a thumbnail with a higher resolution videoInfo.thumbnail_url = playerArgs.getString("thumbnail_url"); videoInfo.duration = playerArgs.getInt("length_seconds"); videoInfo.average_rating = playerArgs.getString("avg_rating"); // View Count will be extracted from html dashManifest = playerArgs.getString("dashmpd"); String playerUrl = ytAssets.getString("js"); if (playerUrl.startsWith("//")) { playerUrl = "https:" + playerUrl; } if (decryptoinCode.isEmpty()) { decryptoinCode = loadDecryptioinCode(playerUrl); } // extract audio videoInfo.audioStreams = parseDashManifest(dashManifest, decryptoinCode); //------------------------------------ // extract video stream url //------------------------------------ String encoded_url_map = playerArgs.getString("url_encoded_fmt_stream_map"); Vector<VideoInfo.VideoStream> videoStreams = new Vector<>(); for (String url_data_str : encoded_url_map.split(",")) { Map<String, String> tags = new HashMap<>(); for (String raw_tag : Parser.unescapeEntities(url_data_str, true).split("&")) { String[] split_tag = raw_tag.split("="); tags.put(split_tag[0], split_tag[1]); } int itag = Integer.parseInt(tags.get("itag")); String streamUrl = terrible_unescape_workaround_fuck(tags.get("url")); // if video has a signature: decrypt it and add it to the url if (tags.get("s") != null) { if (decryptoinCode.isEmpty()) { decryptoinCode = loadDecryptioinCode(playerUrl); } streamUrl = streamUrl + "&signature=" + decryptSignature(tags.get("s"), decryptoinCode); } if (resolveFormat(itag) != -1) { videoStreams.add(new VideoInfo.VideoStream(streamUrl, resolveFormat(itag), resolveResolutionString(itag))); } } videoInfo.videoStreams = new VideoInfo.VideoStream[videoStreams.size()]; for (int i = 0; i < videoStreams.size(); i++) { videoInfo.videoStreams[i] = videoStreams.get(i); } } catch (Exception e) { e.printStackTrace(); } //------------------------------- // extrating from html page //------------------------------- // Determine what went wrong when the Video is not available if (videoInfo.videoAvailableStatus == VideoInfo.VIDEO_UNAVAILABLE) { if (doc.select("h1[id=\"unavailable-message\"]").first().text().contains("GEMA")) { videoInfo.videoAvailableStatus = VideoInfo.VIDEO_UNAVAILABLE_GEMA; } } // Try to get high resolution thumbnail if it fails use low res from the player instead try { videoInfo.thumbnail_url = doc.select("link[itemprop=\"thumbnailUrl\"]").first().attr("abs:href"); } catch (Exception e) { Log.i(TAG, "Could not find high res Thumbnail. Use low res instead"); } // upload date videoInfo.upload_date = doc.select("strong[class=\"watch-time-text\"").first().text(); // Try to only use date not the text around it try { Pattern p = Pattern.compile("([0-9.]*$)"); Matcher m = p.matcher(videoInfo.upload_date); m.find(); videoInfo.upload_date = m.group(1); } catch (Exception e) { e.printStackTrace(); } // description videoInfo.description = doc.select("p[id=\"eow-description\"]").first().html(); try { // likes videoInfo.like_count = doc.select("span[class=\"like-button-renderer \"]").first().getAllElements() .select("button").select("span").get(0).text(); // dislikes videoInfo.dislike_count = doc.select("span[class=\"like-button-renderer \"]").first().getAllElements() .select("button").select("span").get(2).text(); } catch (Exception e) { // if it fails we know that the video does not offer dislikes. videoInfo.like_count = "0"; videoInfo.dislike_count = "0"; } // uploader thumbnail videoInfo.uploader_thumbnail_url = doc.select("a[class*=\"yt-user-photo\"]").first().select("img").first() .attr("abs:data-thumb"); // view count videoInfo.view_count = doc.select("div[class=\"watch-view-count\"]").first().text(); /* todo finish this code // next video videoInfo.nextVideo = extractVideoInfoItem(doc.select("div[class=\"watch-sidebar-section\"]").first() .select("li").first()); int i = 0; // related videos for(Element li : doc.select("ul[id=\"watch-related\"]").first().children()) { // first check if we have a playlist. If so leave them out if(li.select("a[class*=\"content-link\"]").first() != null) { //videoInfo.relatedVideos.add(extractVideoInfoItem(li)); //i++; //Log.d(TAG, Integer.toString(i)); } } */ return videoInfo; }
From source file:edu.ku.brc.specify.toycode.RegPivot.java
/** * @param newTblName//w ww . ja v a2s. c o m * @param stmt * @param pStmt * @param fillSQL * @param secInx * @param dbFieldTypes * @param dbFieldNames * @param inxToName * @return * @throws SQLException */ private int fillTrackTable(final String newTblName, final Statement stmt, final PreparedStatement pStmt, final String fillSQL, final int secInx, final Vector<Integer> dbFieldTypes, final Vector<String> dbFieldNames, final HashMap<Integer, String> inxToName) throws SQLException { System.out.println("Filling Track Table."); int instCnt = 0; System.out.println(fillSQL); ResultSet rs = stmt.executeQuery(fillSQL); ResultSetMetaData rsmd = rs.getMetaData(); HashMap<String, Integer> nameToIndex = new HashMap<String, Integer>(); for (int c = 1; c <= rsmd.getColumnCount(); c++) { nameToIndex.put(rsmd.getColumnName(c), c); System.out.println(c + " - " + rsmd.getColumnName(c)); } boolean debug = false; String prevRegId = null; HashMap<String, HashMap<String, Object>> colHash = new HashMap<String, HashMap<String, Object>>(); HashMap<String, Object> nameToVals = new HashMap<String, Object>(); while (rs.next()) { String regId = rs.getString(1); if (prevRegId == null) prevRegId = regId; for (int i = 1; i < secInx; i++) { if (debug) System.out.println("Put: " + dbFieldNames.get(i - 1) + " " + dbFieldTypes.get(i - 1) + " = " + rs.getObject(i)); if (dbFieldTypes.get(i - 1) == java.sql.Types.TIMESTAMP) { try { String ts = rs.getString(i); if (StringUtils.isNotEmpty(ts) && ts.equals("0000-00-00 00:00:00")) { continue; } } catch (Exception ex) { continue; } } nameToVals.put(dbFieldNames.get(i - 1), rs.getObject(i)); } String name = rs.getString(secInx); name = StringUtils.replace(name, "(", "_"); name = StringUtils.replace(name, ")", "_"); if (name.equals("reg_type")) { String strVal = (String) rs.getObject(secInx + 2); name = strVal + "_number"; nameToVals.put(name, regId); if (debug) System.out.println("Put: " + name + " = " + regId); } else { Integer intVal = (Integer) rs.getObject(secInx + 1); String strVal = (String) rs.getObject(secInx + 2); nameToVals.put(name, strVal != null ? strVal : intVal); if (debug) System.out.println("Put: " + name + " = " + intVal + " / " + strVal); } if (debug) System.out.println("-------------------------------------------"); if (!prevRegId.equals(regId)) { String colNum = (String) nameToVals.get("Collection_number"); if (StringUtils.isNotEmpty(colNum)) { copyHash(colNum, colHash, nameToVals); } prevRegId = regId; nameToVals.clear(); } } writeHash(colHash, null, pStmt, dbFieldTypes, dbFieldNames, inxToName); String alterSQL = "ALTER TABLE " + newTblName + " ADD Lookup VARCHAR(64) AFTER IP"; BasicSQLUtils.update(connection, alterSQL); alterSQL = "ALTER TABLE " + newTblName + " ADD Country VARCHAR(64) AFTER Lookup"; BasicSQLUtils.update(connection, alterSQL); alterSQL = "ALTER TABLE " + newTblName + " ADD City VARCHAR(64) AFTER Country"; BasicSQLUtils.update(connection, alterSQL); return instCnt; }
From source file:edu.xtec.colex.client.beans.ColexRecordBean.java
/** * Calls the web service operation//from ww w . j a v a 2 s . c om * <I>modifyRecord(User,Owner,Collection,Record) : void</I> * * @param r the Record to modify * @param vAttachments a Vector containing the Attachments of the Record * @throws java.lang.Exception when an Exception error occurs */ protected void modifyRecord(Record r, Vector vAttachments) throws Exception { User u = new User(getUserId()); Collection c = new Collection(""); c.setName(collection); try { smRequest = mf.createMessage(); SOAPBodyElement sbeRequest = setRequestName(smRequest, "modifyRecord"); addParam(sbeRequest, u); if (owner != null) { Owner oRequest = new Owner(owner); addParam(sbeRequest, oRequest); } addParam(sbeRequest, c); addParam(sbeRequest, r); for (int i = 0; i < vAttachments.size(); i++) { FileItem fi = (FileItem) vAttachments.get(i); String sNomFitxer = Utils.getFileName(fi.getName()); File fTemp = File.createTempFile("attach", null); fi.write(fTemp); URL urlFile = new URL("file://" + fTemp.getPath()); AttachmentPart ap = smRequest.createAttachmentPart(new DataHandler(urlFile)); String fieldName = fi.getFieldName(); ap.setContentId(fieldName + "/" + sNomFitxer); smRequest.addAttachmentPart(ap); } smRequest.saveChanges(); SOAPMessage smResponse = sendMessage(smRequest, this.getJspProperties().getProperty("url.servlet.record")); SOAPBody sbResponse = smResponse.getSOAPBody(); if (sbResponse.hasFault()) { checkFault(sbResponse, "modify"); } else { } } catch (SOAPException se) { throw se; } }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartHelper.java
/*********************************************************************************************** * Crop the specified Vector of CalendarisedData to the range given by the start and end Calendars. * Return the cropped CalendarisedData, or NULL on failure. * * @param calendariseddata//from w w w .j av a 2s .c o m * @param startcalendar * @param endcalendar * * @return Vector<Object> */ public static Vector<Object> cropCalendarisedDataToRange(final Vector<Object> calendariseddata, final Calendar startcalendar, final Calendar endcalendar) { Vector<Object> vecCropped; vecCropped = null; if ((calendariseddata != null) && (!calendariseddata.isEmpty()) && (startcalendar != null) && (endcalendar != null)) { vecCropped = new Vector<Object>(calendariseddata.size()); for (int intDataIndex = 0; intDataIndex < calendariseddata.size(); intDataIndex++) { final Vector<Object> vecRow; final Calendar calendarRow; vecRow = (Vector) calendariseddata.get(intDataIndex); // We can safely assume that the data Vector is calendarised calendarRow = (Calendar) vecRow.get(DataTranslatorInterface.INDEX_TIMESTAMPED_CALENDAR); if ((calendarRow.equals(startcalendar) || calendarRow.after(startcalendar)) && (calendarRow.before(endcalendar) || calendarRow.equals(endcalendar))) { vecCropped.add(vecRow); } } } // Did we gather any data? if ((vecCropped != null) && (vecCropped.isEmpty())) { // Return NULL on failure vecCropped = null; } return (vecCropped); }
From source file:edu.ku.brc.specify.toycode.RegPivot.java
/** * @param newTblName//from ww w.ja v a 2s. c o m * @param stmt * @param pStmt * @param fillSQL * @param secInx * @param dbFieldTypes * @param dbFieldNames * @param inxToName * @return * @throws SQLException */ private int fillTrackTableX(final String newTblName, final Statement stmt, final PreparedStatement pStmt, final String fillSQL, final int secInx, final Vector<Integer> dbFieldTypes, final Vector<String> dbFieldNames, final HashMap<Integer, String> inxToName) throws SQLException { System.out.println("Filling Track Table."); int instCnt = 0; HashMap<String, Object> nameToVals = new HashMap<String, Object>(); System.out.println(fillSQL); String prevId = null; ResultSet rs = stmt.executeQuery(fillSQL); ResultSetMetaData rsmd = rs.getMetaData(); HashMap<String, Integer> nameToIndex = new HashMap<String, Integer>(); for (int c = 1; c <= rsmd.getColumnCount(); c++) { nameToIndex.put(rsmd.getColumnName(c), c); System.out.println(c + " - " + rsmd.getColumnName(c)); } while (rs.next()) { String id = rs.getString(1); if (prevId == null) prevId = id; if (!prevId.equals(id)) { for (int i = 1; i < secInx; i++) { //System.out.println("Put: "+dbFieldNames.get(i-1)+" "+dbFieldTypes.get(i-1));//+" = "+rs.getObject(i)); if (dbFieldTypes.get(i - 1) == java.sql.Types.TIMESTAMP) { try { String ts = rs.getString(i); if (StringUtils.isNotEmpty(ts) && ts.equals("0000-00-00 00:00:00")) { //nameToVals.put(dbFieldNames.get(i-1), null); continue; } } catch (Exception ex) { nameToVals.put(dbFieldNames.get(i - 1), null);//"2000-01-01 00:00:00"); continue; } } nameToVals.put(dbFieldNames.get(i - 1), rs.getObject(i)); } for (int i = 0; i < dbFieldNames.size(); i++) { int fInx = i + 1; String name = inxToName.get(i); Object value = nameToVals.get(name); pStmt.setObject(fInx, null); int typ = dbFieldTypes.get(i); if (value != null) { switch (typ) { case java.sql.Types.INTEGER: if (value instanceof Integer) { pStmt.setInt(fInx, (Integer) value); } break; case java.sql.Types.VARCHAR: if (value instanceof String) { pStmt.setString(fInx, (String) value); } break; case java.sql.Types.TIMESTAMP: { if (value instanceof Timestamp) { pStmt.setTimestamp(fInx, (Timestamp) value); } break; } } } else { pStmt.setObject(fInx, null); } } pStmt.executeUpdate(); prevId = id; nameToVals.clear(); } String name = rs.getString(secInx); name = StringUtils.replace(name, "(", "_"); name = StringUtils.replace(name, ")", "_"); Integer intVal = (Integer) rs.getObject(secInx + 1); String strVal = (String) rs.getObject(secInx + 2); nameToVals.put(name, strVal != null ? strVal : intVal); } String alterSQL = "ALTER TABLE " + newTblName + " ADD Lookup VARCHAR(64) AFTER IP"; BasicSQLUtils.update(connection, alterSQL); alterSQL = "ALTER TABLE " + newTblName + " ADD Country VARCHAR(64) AFTER Lookup"; BasicSQLUtils.update(connection, alterSQL); alterSQL = "ALTER TABLE " + newTblName + " ADD City VARCHAR(64) AFTER Country"; BasicSQLUtils.update(connection, alterSQL); return instCnt; }
From source file:gate.util.reporting.PRTimeReporter.java
/** * Reads the given file upside down.//from w w w. java 2 s . co m * * @param fileToBeRead * An object of type File representing the file to be read. * @param chunkSize * An integer specifying the size of the chunks in which file will be * read. * @return A long value pointing to the start position of the given file * chunk. * @throws BenchmarkReportInputFileFormatException */ private long tail(File fileToBeRead, int chunkSize) throws BenchmarkReportInputFileFormatException { RandomAccessFile raf = null; try { raf = new RandomAccessFile(fileToBeRead, "r"); Vector<String> lastNlines = new Vector<String>(); int delta = 0; long curPos = raf.length() - 1; long fromPos; byte[] bytearray; while (true) { fromPos = curPos - chunkSize; if (fromPos <= 0) { raf.seek(0); bytearray = new byte[(int) curPos]; raf.readFully(bytearray); if (parseLinesFromLast(bytearray, lastNlines)) { if (fromPos < 0) fromPos = 0; } break; } else { raf.seek(fromPos); bytearray = new byte[chunkSize]; raf.readFully(bytearray); if (parseLinesFromLast(bytearray, lastNlines)) { break; } delta = (lastNlines.get(lastNlines.size() - 1)).length(); lastNlines.remove(lastNlines.size() - 1); curPos = fromPos + delta; } } if (fromPos < 0) throw new BenchmarkReportInputFileFormatException( getBenchmarkFile().getAbsolutePath() + " does not contain a marker named " + getLogicalStart() + " indicating logical start of a run."); return fromPos; } catch (IOException e) { e.printStackTrace(); return -1; } finally { IOUtils.closeQuietly(raf); } }