changeset 27:e246e0dac9c8

modified checkConsensus
author one
date Wed, 03 Oct 2012 04:44:45 +0900
parents ad7cfb1f9d03
children 7112b826a53a
files app/models/TPGraph.java logs/application.log target/scala-2.9.1/cache/compile/compile test/RequestTest.java
diffstat 4 files changed, 38 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/app/models/TPGraph.java	Wed Oct 03 03:52:03 2012 +0900
+++ b/app/models/TPGraph.java	Wed Oct 03 04:44:45 2012 +0900
@@ -1,5 +1,6 @@
 package models;
 
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Iterator;
 
@@ -114,23 +115,42 @@
 	
 	public Object[] checkConsensus(HashSet<Object> set) {
 		Iterator<Object> iter = set.iterator();
-		while(iter.hasNext()) {
+
+		while (iter.hasNext()) {
 			Object childId = iter.next();
-			Object parentId;
-			while ( (parentId = checkUpperVertex(childId)) != null){
+			ArrayList<Object> array = getAllUpperVertex(childId);
+			for (Object parentId: array.toArray()) {
 				if (set.contains(parentId)) {
-					set.remove(childId);
-					iter = set.iterator();
-					childId = parentId;
-					continue;
+					if (set.contains(childId)) {
+
+						// This behavior is anxiety.
+						set.remove(childId);
+						iter = set.iterator();
+					}
+					childId = parentId;	
 				}
-				childId = parentId;
 			}
 		}
 		return set.toArray();
 	}
 	
-	public Object checkUpperVertex(Object id) {
+	
+	public ArrayList<Object> getAllUpperVertex(Object id) {
+		Vertex startV = graph.getVertex(id);
+		GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();		
+		pipe.start(startV).in(NodeModel.L_QUESTION, NodeModel.L_REFUTATION, NodeModel.L_SUGGESTION);
+		ArrayList<Object> vertexArray = new ArrayList<Object>();
+
+		while (pipe.hasNext()) {
+			Object e = pipe.next().getId();
+			vertexArray.add(e);
+			pipe.start(graph.getVertex(e)).in(NodeModel.L_QUESTION, NodeModel.L_REFUTATION, NodeModel.L_SUGGESTION);
+		}
+		
+		return vertexArray;
+	}
+	
+	public Object getOneUpperVertex(Object id) {
 		Vertex startV = graph.getVertex(id);
 		GremlinPipeline<Vertex,Vertex> pipe = new GremlinPipeline<Vertex,Vertex>();
 		pipe.start(startV).in(NodeModel.L_QUESTION, NodeModel.L_REFUTATION, NodeModel.L_SUGGESTION);
--- a/logs/application.log	Wed Oct 03 03:52:03 2012 +0900
+++ b/logs/application.log	Wed Oct 03 04:44:45 2012 +0900
@@ -1,12 +1,6 @@
-2012-10-03 03:39:11,946 - [INFO] - from play in main 
+2012-10-03 04:40:32,947 - [INFO] - from play in main 
 Listening for HTTP on port 9000...
 
-2012-10-03 03:39:18,488 - [INFO] - from play in play-akka.actor.default-dispatcher-1 
+2012-10-03 04:40:40,342 - [INFO] - from play in play-akka.actor.default-dispatcher-1 
 Application started (Dev)
 
-2012-10-03 03:40:19,534 - [INFO] - from application in play-akka.actor.default-dispatcher-3 
-Application shutdown...
-
-2012-10-03 03:40:19,554 - [INFO] - from play in play-akka.actor.default-dispatcher-3 
-Application started (Dev)
-
Binary file target/scala-2.9.1/cache/compile/compile has changed
--- a/test/RequestTest.java	Wed Oct 03 03:52:03 2012 +0900
+++ b/test/RequestTest.java	Wed Oct 03 04:44:45 2012 +0900
@@ -29,27 +29,27 @@
 		createUser(user3);
 
 		String[] users1 = {user2,user3};
-//		createClaim(user1, users1);
+		createClaim(user1, users1);
 		String[] users2 = {user2};
-//		createClaim(user1, users2);
+		createClaim(user1, users2);
 		
 
 		getUser(user1);
-		getUserInfo(user1,"claims/");
+		getUserInfo(user1,"consensus/");
+
 
 
 		String[] users3 = {user1};
-
 		createMention(user2, users3, NodeModel.L_QUESTION, "5");
 		createMention(user3, users3, NodeModel.L_REFUTATION, "5");
 
 		createMention(user2, users3, NodeModel.L_QUESTION, "10");
 		createMention(user3, users3, NodeModel.L_REFUTATION, "10");
 
-
+		getUserInfo(user1,"requests/");
 		getUserInfo(user1,"claims/");
+
 		getUserInfo(user1,"consensus/");
-		getUserInfo(user1,"requests/");
 
 		getUserInfo(user2,"claims/");
 		getUserInfo(user2,"consensus/");
@@ -57,12 +57,11 @@
 		getUserInfo(user3,"claims/");
 		getUserInfo(user3,"consensus/");
 
-/*		
 		getUserInfo(user3,"requests/");
 		getUserInfo(user3,"claims/");
 		getUserInfo(user2,"consensus/");
 		getUserInfo(user3,"consensus/");
-*/
+
 	}
 
 	public static void createMention(String author, String[] users, String type, Object id) throws JSONException {