List of usage examples for com.mongodb DBCursor hasNext
@Override public boolean hasNext()
From source file:com.bigdid.model.Revenue_Location.java
public Map<String, Integer> getLocationRevenue() throws UnknownHostException { HashMap<String, Integer> locationRevenue = new HashMap<String, Integer>(); int i = 0;/*from w w w . java 2 s . c o m*/ BasicDBObject whereQuery = new BasicDBObject("Order_Value", -1); DBCursor obj = coll.find().sort(whereQuery).limit(10); while (obj.hasNext()) { DBObject dbObj = obj.next(); locationRevenue.put((String) dbObj.get("Location"), (Integer) dbObj.get("Order_Value")); } Map<String, Integer> map = sortByValues(locationRevenue); return map; }
From source file:com.bigdid.model.Sentiment_Date_Revised_one.java
public LinkedHashMap<String, int[]> getSentiment() { DBCursor obj = coll.find(); String current_date = "0"; String prev_date = "0"; int prev_positive = 0; while (obj.hasNext()) { DBObject dbObj = obj.next();//from w ww .ja v a2 s . com prev_date = current_date; current_date = (String) dbObj.get("date").toString().substring(4, 10) + " " + (String) dbObj.get("date").toString().substring(24); int[] count = new int[3]; if (prev_date.equals(current_date)) { //current day is previous day so negative sentiment for sure count[0] = (Integer) dbObj.get("order_count"); count[1] = prev_positive; count[2] = (Integer) dbObj.get("count"); data.put(current_date, count); } else { //new day---- 2 cases positive or negative if (dbObj.get("sentiment").equals("positive")) { count[0] = (Integer) dbObj.get("order_count"); count[1] = (Integer) dbObj.get("count"); count[2] = 0; data.put(current_date, count); prev_positive = count[1]; } if (dbObj.get("sentiment").equals("negative")) { //first date is negative count[0] = (Integer) dbObj.get("order_count"); count[1] = 0; count[2] = (Integer) dbObj.get("count"); data.put(current_date, count); } } } return data; }
From source file:com.bigdid.model.Sentiment_Month_Revised_one.java
public LinkedHashMap<String, int[]> getSentiment() { DBCursor obj = coll.find(); String current_date = "0"; String prev_date = "0"; int prev_positive = 0; while (obj.hasNext()) { DBObject dbObj = obj.next();/*from ww w . j a va 2 s.co m*/ prev_date = current_date; current_date = (String) dbObj.get("month"); int[] count = new int[3]; if (prev_date.equals(current_date)) { //current day is previous day so negative sentiment for sure count[0] = (Integer) dbObj.get("o_count"); count[1] = prev_positive; count[2] = (Integer) dbObj.get("s_count"); data.put(current_date, count); } else { //new day---- 2 cases positive or negative if (dbObj.get("sentiment").equals("positive")) { count[0] = (Integer) dbObj.get("o_count"); count[1] = (Integer) dbObj.get("s_count"); ; count[2] = 0; data.put(current_date, count); prev_positive = count[1]; } if (dbObj.get("sentiment").equals("negative")) { //first date is negative count[0] = (Integer) dbObj.get("o_count"); count[1] = 0; count[2] = (Integer) dbObj.get("s_count"); data.put(current_date, count); } } } return data; }
From source file:com.bigdid.model.Sentiment_Week_Revised_one.java
public LinkedHashMap<String, int[]> getSentiment() { DBCursor obj = coll.find(); String current_date = "0"; String prev_date = "0"; int prev_positive = 0; while (obj.hasNext()) { DBObject dbObj = obj.next();//from www .j av a2 s. co m prev_date = current_date; current_date = (String) dbObj.get("week"); int[] count = new int[3]; if (prev_date.equals(current_date)) { //current day is previous day so negative sentiment for sure count[0] = (Integer) dbObj.get("o_count"); count[1] = prev_positive; count[2] = (Integer) dbObj.get("s_count"); data.put(current_date, count); } else { //new day---- 2 cases positive or negative if (dbObj.get("sentiment").equals("positive")) { count[0] = (Integer) dbObj.get("o_count"); count[1] = (Integer) dbObj.get("s_count"); ; count[2] = 0; data.put(current_date, count); prev_positive = count[1]; } if (dbObj.get("sentiment").equals("negative")) { //first date is negative count[0] = (Integer) dbObj.get("o_count"); count[1] = 0; count[2] = (Integer) dbObj.get("s_count"); data.put(current_date, count); } } } return data; }
From source file:com.bigdid.scrap.model.Sentiment_Date.java
public HashMap<String, int[]> getSentiment() { DBCursor obj = coll.find(); int i = 0;// ww w .j ava 2 s . c o m String current_date = "0"; String prev_date = "0"; int[] count = new int[3]; while (obj.hasNext()) { DBObject dbObj = obj.next(); prev_date = current_date; current_date = (String) dbObj.get("date").toString().substring(4, 10) + " " + (String) dbObj.get("date").toString().substring(24); System.out.println("current date" + current_date); System.out.println("previous date :" + prev_date); int prev_positive = 0; int prev_orderValue = 0; String prev_sentiment = "0"; if (prev_date.equals(current_date)) { //repeat date entry having negative count for sure count[1] = prev_positive; count[2] = (Integer) dbObj.get("count"); count[0] = (Integer) dbObj.get("order_count"); data.put(current_date, count); prev_positive = 0; count[0] = 0; count[1] = 0; count[2] = 0; } else { //new date if (prev_sentiment.equals("positive") && dbObj.get("sentiment").equals("positive")) { count[0] = prev_orderValue; count[1] = prev_positive; count[2] = 0; data.put(prev_date, count); count[0] = 0; count[1] = 0; count[2] = 0; prev_sentiment = "0"; } if (dbObj.get("Sentiment").equals("positive")) { prev_positive = (Integer) dbObj.get("count"); prev_orderValue = (Integer) dbObj.get("order_count"); prev_sentiment = "positive"; } else { //new date with negative count prev_positive = 0; count[1] = prev_positive; count[2] = (Integer) dbObj.get("count"); count[0] = (Integer) dbObj.get("order_count"); data.put(current_date, count); count[0] = 0; count[1] = 0; count[2] = 0; } } } return data; }
From source file:com.bosscs.spark.mongodb.extractor.MongoNativeExtractor.java
License:Apache License
/** * Gets shards.//w w w .j a v a 2s . co m * * @param collection the collection * @return the shards */ private Map<String, String[]> getShards(DBCollection collection) { DB config = collection.getDB().getSisterDB("config"); DBCollection configShards = config.getCollection("shards"); DBCursor cursorShards = configShards.find(); Map<String, String[]> map = new HashMap<>(); while (cursorShards.hasNext()) { DBObject currentShard = cursorShards.next(); String currentHost = (String) currentShard.get("host"); int slashIndex = currentHost.indexOf("/"); if (slashIndex > 0) { map.put((String) currentShard.get(MONGO_DEFAULT_ID), currentHost.substring(slashIndex + 1).split(",")); } } return map; }
From source file:com.bosscs.spark.mongodb.extractor.MongoNativeExtractor.java
License:Apache License
/** * Calculates shard chunks./* w w w . j a v a 2 s . c o m*/ * * @param collection the collection * @return the deep partition [ ] */ private HadoopPartition[] calculateShardChunks(DBCollection collection) { DBCursor chuncks = getChunks(collection); Map<String, String[]> shards = getShards(collection); MongoPartition[] deepPartitions = new MongoPartition[chuncks.count()]; int i = 0; boolean keyAssigned = false; String key = null; while (chuncks.hasNext()) { DBObject dbObject = chuncks.next(); if (!keyAssigned) { Set<String> keySet = ((DBObject) dbObject.get("min")).keySet(); for (String s : keySet) { key = s; keyAssigned = true; } } deepPartitions[i] = new MongoPartition( mongoDeepJobConfig.getRddId(), i, new TokenRange(shards.get(dbObject.get("shard")), ((DBObject) dbObject.get("min")).get(key), ((DBObject) dbObject.get("max")).get(key)), key); i++; } List<MongoPartition> mongoPartitions = Arrays.asList(deepPartitions); Collections.shuffle(mongoPartitions); return mongoPartitions.toArray(new MongoPartition[mongoPartitions.size()]); }
From source file:com.bugull.mongo.fs.BuguFS.java
License:Apache License
private List<GridFSDBFile> toFileList(DBCursor cursor) { List<GridFSDBFile> list = new ArrayList<GridFSDBFile>(); while (cursor.hasNext()) { DBObject dbo = cursor.next();/*w ww .j av a 2 s . c o m*/ list.add((GridFSDBFile) dbo); } cursor.close(); return list; }
From source file:com.bugull.mongo.utils.MapperUtil.java
License:Apache License
public static <T> List<T> toList(Class<T> clazz, DBCursor cursor) { List<T> list = new ArrayList<T>(); while (cursor.hasNext()) { DBObject dbo = cursor.next();/*w w w .ja v a 2 s . c o m*/ list.add(fromDBObject(clazz, dbo)); } cursor.close(); return list; }
From source file:com.buzz.buzzdata.MongoBuzz.java
private String getBuzz(BasicDBObject query, Double lat, Double lng) { String retval = ""; DBCollection buzzCollection = mongoDB.getCollection("BuzzInfo"); DBObject sort = new BasicDBObject(); sort.put("modified", -1); DBCursor cursor = buzzCollection.find(query).sort(sort); try {//from ww w . j a va2 s. c o m while (cursor.hasNext()) { //get buzzid DBObject buzz_obj = cursor.next(); ObjectId buzz_id = (ObjectId) buzz_obj.get("_id"); //get images for buzzid GridFS gridFS = new GridFS(mongoDB); BasicDBObject check_images = new BasicDBObject("BuzzID", buzz_id); List<GridFSDBFile> dbfiles = gridFS.find(check_images); String image_links = ""; for (GridFSDBFile file : dbfiles) { String _buzz_id = buzz_id.toString(); String pic_num = file.get("PicNum").toString(); if (!image_links.equals("")) { image_links += ",http://192.168.0.11:8080/BuzzRestAPI/webresources/buzz/Image?buzzid=" + _buzz_id + "&pic_num=" + pic_num; } else { image_links += "http://192.168.0.11:8080/BuzzRestAPI/webresources/buzz/Image?buzzid=" + _buzz_id + "&pic_num=" + pic_num; } } String imgs = "\"Images\": " + "\"" + image_links + "\""; retval += buzz_obj; retval = retval.substring(0, retval.length() - 1); retval += ", " + imgs; double lat2 = (double) ((BasicDBList) buzz_obj.get("loc")).get(0); double lng2 = (double) ((BasicDBList) buzz_obj.get("loc")).get(1); double dist = this.haversine(lat, lng, lat2, lng2); retval += ", \"Distance\": " + dist; String directions_url = "https://maps.google.com/maps?saddr=" + lat + "," + lng + "&daddr=" + lat2 + "," + lng2 + "&hl=en&sll=" + lat + "," + lng + "&sspn=" + lat2 + "," + lng2 + "&t=m&mra=mift&mrsp=1&sz=5&z=18"; retval += ", \"Directions\": \"" + directions_url + "\""; retval += "},"; } } catch (Exception exc) { } finally { cursor.close(); } retval = retval.substring(0, retval.length() - 1); retval = "callback({\"Buzzes\": [" + retval + "]})"; return retval; }