List of usage examples for com.mongodb DBObject get
Object get(String key);
From source file:com.bigdid.model.Sentiment_Date_Revised_one.java
public LinkedHashMap<String, int[]> getSentiment() { DBCursor obj = coll.find();//from ww w.ja v a2 s .c o m String current_date = "0"; String prev_date = "0"; int prev_positive = 0; 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); 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();//www . jav a2 s. co m String current_date = "0"; String prev_date = "0"; int prev_positive = 0; while (obj.hasNext()) { DBObject dbObj = obj.next(); 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();/*w ww .ja v a 2 s. co m*/ String current_date = "0"; String prev_date = "0"; int prev_positive = 0; while (obj.hasNext()) { DBObject dbObj = obj.next(); 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();/*from w w w . ja va2 s . c om*/ int i = 0; 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.biz.mongo.MongoDBConnection.java
public String getMongoDBContext(SkillFlowContext skillFlowContext) { DBObject clause_sessionId = new BasicDBObject("sessionId", skillFlowContext.getSessionId()); // DBObject clause_contextId = new BasicDBObject("contextId", skillFlowContext.getContextId()); // DBObject clause_contextId = new BasicDBObject("queryParameter", java.util.regex.Pattern.compile(skillFlowContext.getQueryParameter())); DBObject clause_contextId = new BasicDBObject("queryParameter", skillFlowContext.getQueryParameter()); BasicDBList and_query = new BasicDBList(); and_query.add(clause_sessionId);/*from www.j a v a2 s .com*/ and_query.add(clause_contextId); String contextId = null; String nextStep = null; DBObject query_text = new BasicDBObject("$and", and_query); context_cursor = context.find(query_text); System.out.println("context_cursor " + context_cursor); System.out.println("context_cursor.hasNext() " + context_cursor.hasNext()); while (context_cursor.hasNext()) { System.out.println("step 1"); DBObject db_obj = context_cursor.next(); contextId = db_obj.get("sessionId").toString(); System.out.println("contextId " + contextId); nextStep = db_obj.get("nextStep").toString(); System.out.println("nextStep " + nextStep); } System.out.println("contextId+\"::\"+nextStep : " + contextId + "::" + nextStep); return contextId + "::" + nextStep; }
From source file:com.biz.mongo.MongoDBConnection.java
public String getProgressStatus(SkillFlowContext skillFlowContext) { DBObject clause_sessionId = new BasicDBObject("sessionId", skillFlowContext.getSessionId()); // DBObject clause_contextId = new BasicDBObject("contextId", skillFlowContext.getContextId()); // DBObject clause_contextId = new BasicDBObject("queryParameter", java.util.regex.Pattern.compile(skillFlowContext.getQueryParameter())); DBObject clause_contextId = new BasicDBObject("queryParameter", skillFlowContext.getQueryParameter()); BasicDBList and_query = new BasicDBList(); and_query.add(clause_sessionId);//w w w. j a v a 2 s . co m and_query.add(clause_contextId); String sessionId = null; String contextId = null; String nextStep = null; String contextState = null; String progress_result = null; DBObject query_text = new BasicDBObject("$and", and_query); context_cursor = context.find(query_text); // System.out.println("context_cursor "+context_cursor); // System.out.println("context_cursor.hasNext() "+context_cursor.hasNext()); if (context_cursor.hasNext()) { while (context_cursor.hasNext()) { System.out.println("step 1"); DBObject db_obj = context_cursor.next(); sessionId = db_obj.get("sessionId").toString(); // System.out.println("sessionId "+sessionId); contextId = db_obj.get("contextId").toString(); // System.out.println("contextId "+contextId); nextStep = db_obj.get("nextStep").toString(); // System.out.println("nextStep "+nextStep); contextState = db_obj.get("contextState").toString(); // System.out.println("contextState "+contextState); // System.out.println("sessionId::contextId::nextStep::contextState "+sessionId+"::"+contextId+"::"+nextStep+"::"+contextState); progress_result = sessionId + "::" + contextId + "::" + nextStep + "::" + contextState; } } else { progress_result = "NoRecord"; } return progress_result; }
From source file:com.bosscs.spark.mongodb.extractor.MongoNativeExtractor.java
License:Apache License
/** * Gets shards./*from w w w . jav a 2s . c o 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./*from w w w. j a v a 2s.c om*/ * * @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.bryanreinero.purchase.PurchaseDAO.java
License:Open Source License
private static Purchase toPurchase(DBObject object) { return new Purchase((Integer) object.get("_id"), (String) object.get("buyer"), (String) object.get("seller"), (Integer) object.get("value"), State.parseState((String) object.get("state"))); }
From source file:com.bugull.mongo.AdvancedDao.java
License:Apache License
private double max(String key, DBObject query) { if (!this.exists(query)) { return 0; }//from w ww . ja v a 2 s . com StringBuilder map = new StringBuilder("function(){emit('"); map.append(key); map.append("', {'value':this."); map.append(key); map.append("});}"); String reduce = "function(key, values){var max=values[0].value; for(var i=1;i<values.length; i++){if(values[i].value>max){max=values[i].value;}} return {'value':max}}"; Iterable<DBObject> results = null; try { results = mapReduce(map.toString(), reduce, query); } catch (MapReduceException ex) { logger.error(ex.getMessage(), ex); } DBObject result = results.iterator().next(); DBObject dbo = (DBObject) result.get("value"); return Double.parseDouble(dbo.get("value").toString()); }