public HashMap<Integer, Set> generateUserCluster(List<User> userList) { HashMap<Integer, Set> userCluster; userCluster = new HashMap<>(); Set<Integer> firstClusterList = new TreeSet<>(); Set<Integer> secondClusterList = new TreeSet<>(); Set<Integer> thirdClusterList = new TreeSet<>(); Set<Integer> fourthClusterList = new TreeSet<>(); Set<Integer> fifthClusterList = new TreeSet<>(); Set<Integer> sixthClusterList = new TreeSet<>(); for (User user : userList) { // int[] firstActivityCluster = user.getFirstActivityVector(); int[] tempClassifiedTimeVector = user.getClassifiedTimeVector(); int max = 0; int maxIndex = 0; for (int i = 0; i < tempClassifiedTimeVector.length; i++) { if (tempClassifiedTimeVector[i] > max) { max = tempClassifiedTimeVector[i]; maxIndex = i; } } if (maxIndex == 0) { Integer tempuserID = user.getId(); firstClusterList.add(tempuserID); userCluster.put(1, firstClusterList); } else if (maxIndex == 1) { int tempuserID = user.getId(); secondClusterList.add(tempuserID); userCluster.put(2, secondClusterList); } else if (maxIndex == 2) { int tempuserID = user.getId(); thirdClusterList.add(tempuserID); userCluster.put(3, thirdClusterList); } else if (maxIndex == 3) { int tempuserID = user.getId(); fourthClusterList.add(tempuserID); userCluster.put(4, fourthClusterList); } else if (maxIndex == 4) { int tempuserID = user.getId(); fifthClusterList.add(tempuserID); userCluster.put(5, fifthClusterList); } else if (maxIndex == 5) { int tempuserID = user.getId(); sixthClusterList.add(tempuserID); userCluster.put(6, sixthClusterList); } // firstActivityCluster[maxIndex] = 1; } return userCluster; }
public List<User> generateUserSecondActivityCluster(List<User> userList) { for (User user : userList) { List postList = user.getUserPost(); int requiredPostValue = (int) (0.20 * postList.size()); int[] secondActivityCluster = user.getSecondActivityVector(); int[] tempClassifiedTimeVector = user.getClassifiedTimeVector(); for (int i = 0; i < secondActivityCluster.length; i++) { if (tempClassifiedTimeVector[i] > requiredPostValue) { secondActivityCluster[i] = 1; } } user.setSecondActivityVector(secondActivityCluster); } return userList; }
/** * if user has posted less than or equal to 8 percent of total message then it will be consider as * his sleeping time * * @param userList * @return */ public List<User> generateUserSleepingCluster(List<User> userList) { for (User user : userList) { int[] sleepingCluster = user.getSleepingClusterVector(); int[] tempClassifiedTimeVector = user.getClassifiedTimeVector(); List postList = user.getUserPost(); int requiredSleepingPostValue = (int) (0.08 * postList.size()); // int requiredSleepingPostValue = 5; for (int i = 0; i < sleepingCluster.length; i++) { if (tempClassifiedTimeVector[i] <= requiredSleepingPostValue) { sleepingCluster[i] = 1; } } user.setSleepingClusterVector(sleepingCluster); } return userList; }
/** * @param user @Desc This function populates the "classifiedTimeVector" variable of the * com.post.parser.model.User class. It gives the total number of posts in the specified time * range which has been described in getTimeCategory(int hours) in this class. * @return List<User> */ public User setCategorizedTimeToUser(User user) { ClusterCommons cc = new ClusterCommons(); int[] userTimeVector = user.getClassifiedTimeVector(); for (Posts posts : user.getUserPost()) { Timestamp ts = Timestamp.valueOf( new SimpleDateFormat("yyyy-MM-dd ").format(new Date()).concat(posts.getTime())); int timeCategory = cc.getTimeCategory(ts.getHours()); if (timeCategory < 6) { userTimeVector[timeCategory] = userTimeVector[timeCategory] + 1; } } user.setClassifiedTimeVector(userTimeVector); return user; }
/* * Generates first activity user cluster by taking the maximum number * of posts posted by user */ public List<User> generateUserMostActiveCluster(List<User> userList) { for (User user : userList) { int[] firstActivityCluster = user.getFirstActivityVector(); int[] tempClassifiedTimeVector = user.getClassifiedTimeVector(); int max = 0; int maxIndex = 0; for (int i = 0; i < tempClassifiedTimeVector.length; i++) { if (tempClassifiedTimeVector[i] > max) { max = tempClassifiedTimeVector[i]; maxIndex = i; } } firstActivityCluster[maxIndex] = 1; user.setFirstActivityVector(firstActivityCluster); } return userList; }