Commits

Anonymous committed 69dbea2

Progress in ENCUESTAME-191

  • Participants
  • Parent commits 25ccf64

Comments (0)

Files changed (8)

encuestame-business/src/main/java/org/encuestame/business/service/FrontEndService.java

 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
-
 import javax.servlet.http.HttpServletRequest;
-
 import org.apache.log4j.Logger;
 import org.encuestame.business.service.imp.IFrontEndService;
 import org.encuestame.core.util.ConvertDomainBean;
+import org.encuestame.core.util.EnMeUtils;
 import org.encuestame.persistence.dao.SearchPeriods;
 import org.encuestame.persistence.domain.HashTag;
 import org.encuestame.persistence.domain.HashTagHits;
         log.debug("Max Results HashTag -----> "+maxResults);
         List<HashTag> tags = new ArrayList<HashTag>();
         tags.addAll(getHashTagDao().getHashTags(maxResults, start, tagCriteria));
+        for (HashTag hashTag : tags) {
+            final Integer tagFrecuency = getHashTagFrecuency(hashTag.getHashTagId(),2);
+            final List<Object[]> maxMin = getHashTagDao().getMaxMinTagFrecuency();
+            final Integer maxFrecuency = (Integer) maxMin.get(0)[0];
+            final Integer minFrecuency = (Integer) maxMin.get(0)[1];
+            final Double logFrecuency = EnMeUtils.calculateSizeTag(tagFrecuency, maxFrecuency, minFrecuency);
+            hashTag.setSize(logFrecuency.longValue());
+        }
+
         log.debug("Hashtag total size ---> "+tags.size());
         hashBean.addAll(ConvertDomainBean.convertListHashTagsToBean(tags));
 
     }
 */
     /**
-     * Get hashTag relevance.
+     * Get hashTag counter.
      * @param hashTagId
      * @param limit
      * @return
      */
-    public Integer getHashTagRelevance(final Long hashTagId, final Integer limit){
+    public Integer getHashTagFrecuency(final Long hashTagId, final Integer limit){
         final Integer totalRelTweetPoll;
-        final Integer relevance;
+        final Integer frecuency;
         final List<TweetPoll> tweetPolls = getTweetPollDao().getTweetpollByHashTagId(hashTagId, limit, "");
         totalRelTweetPoll = tweetPolls.size();
-        relevance = totalRelTweetPoll;
+        frecuency = totalRelTweetPoll;
         //TODO:Pending count relevance hashtags for polls and surveys.
-        return relevance;
+        return frecuency;
+    }
+
+    /**
+     * Get Hit by Hash Tag
+     * @param hashTagId
+     * @return
+     */
+    public Long getHitbyHashTag(final Long hashTagId){
+        final Integer hit;
+        final HashTag tagHit = getHashTagDao().getHashTagById(hashTagId);
+        return (tagHit.getHits());
     }
 
     /**
         return tagHit;
     }
 
-
+    /**
+     * Register hash tag hit.
+     * @param tagName
+     * @param hitDate
+     * @param ipAddress
+     * @return
+     */
     public Boolean registerHashTagHit(final String tagName, final String ip, final String username){
         final HashTagHits hashHit ;
         Long hitCount = 1L;

encuestame-business/src/main/java/org/encuestame/business/service/imp/IFrontEndService.java

      * @param username
      */
     Boolean registerHashTagHit(final String tagName, final String ip, final String username);
+
+    /**
+     * Get hashTag Counter.
+     * @param hashTagId
+     * @param limit
+     * @return
+     */
+    Integer getHashTagFrecuency(final Long hashTagId, final Integer limit);
 }

encuestame-core/src/main/java/org/encuestame/core/util/ConvertDomainBean.java

         unitHashTag.setId(hashTag.getHashTagId());
         unitHashTag.setHits(hashTag.getHits());
         //TODO: ENCUESTAME-191
-        int x = (10 + (int)(Math.random() * ((40) - 5) + 10)); //TEMP.
-        log.debug("random hastag number "+x);
-        unitHashTag.setSize(x);
+        // int x = (10 + (int)(Math.random() * ((40) - 5) + 10)); //TEMP.
+        log.debug("random hastag number "+hashTag.getSize());
+        unitHashTag.setSize(hashTag.getSize().intValue());
         return unitHashTag;
     }
 

encuestame-core/src/main/java/org/encuestame/core/util/EnMeUtils.java

             return "0.00%";
         }
     }
+
+    /**
+     *
+     * @param frecuency Number of times the label has been used in polls, survey or tweetPolls
+     * @param frecMax : Maximum number of frequency.
+     * @param frecMin : Minimum number of frecuency.
+     * @return
+     */
+    public static Double calculateSizeTag(final Integer frecuency, final Integer frecMax, final Integer frecMin){
+
+        final Integer frecDiff = frecMax - frecMin;
+        final Integer v = 30;
+        final Long perRelative =   (long) ((frecuency - (frecMax - frecMin) / frecDiff) * v);
+        final double perLog = (Math.log(perRelative)/Math.log(2));
+        return perLog;
+    }
 }

encuestame-persistence/src/main/java/org/encuestame/persistence/dao/IHashTagDao.java

      * @return
      */
     List<HashTag> getHashTags( final Integer maxResults,final Integer start, final String tagCriteria);
+
+    /**
+     * Get hashTag by Id.
+     * @param hashTagId
+     * @return
+     * @throws HibernateException
+     */
+    HashTag getHashTagById(final Long hashTagId) throws HibernateException;
+
+    /**
+     * Get max-min tag frecuency.
+     * @return
+     */
+    List<Object[]>  getMaxMinTagFrecuency();
 }

encuestame-persistence/src/main/java/org/encuestame/persistence/dao/imp/HashTagDao.java

 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
+
 import org.apache.commons.collections.set.ListOrderedSet;
 import org.apache.lucene.analysis.SimpleAnalyzer;
 import org.encuestame.persistence.dao.IHashTagDao;
                 });
         return searchResult;
     }
+
+    /**
+     * Get hashTag by Id.
+     * @param hashTagId
+     * @return
+     * @throws HibernateException
+     */
+    public HashTag getHashTagById(final Long hashTagId) throws HibernateException {
+        return (HashTag) getHibernateTemplate().get(HashTag.class, hashTagId);
+    }
+
+    /**
+     * Get max-min tag frecuency.
+     * @param tag
+     * @param filter
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    public List<Object[]> getMaxMinTagFrecuency(){
+        final String maxHit = "Select max(hits) as maximum, min(hits) as minimum from HashTag";
+        return getHibernateTemplate().find(maxHit);
+    }
 }

encuestame-persistence/src/main/java/org/encuestame/persistence/domain/HashTag.java

 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.JoinTable;
 import javax.persistence.ManyToMany;
 import javax.persistence.Table;
-
 import org.encuestame.persistence.domain.tweetpoll.TweetPoll;
 import org.hibernate.search.annotations.DocumentId;
 import org.hibernate.search.annotations.Field;

encuestame-persistence/src/test/java/org/encuestame/test/persistence/dao/TestHashTagDao.java

 
     @Before
     public void initData(){
-        this.hashTag = createHashTag("software");
+        this.hashTag = createHashTag("software",10L);
     }
 
     /**
         assertEquals("Should be equals", hashTag3.getHashTag(), expHas4.getHashTag());
     }
 
+    /**
+     * Test get max-min tag frecuency.
+     */
+    @Test
+    public void testGetMaxMinTagFrecuency(){
+        createHashTag("America", 20L);
+        createHashTag("Amazonas", 90L);
+        createHashTag("Carazo",  50L);
+        final List<Object[]>  frecuency = getHashTagDao().getMaxMinTagFrecuency();
+        //System.out.println("MAX 1-------->"+ frecuency.get(0)[0]);
+        //System.out.println(" MIN 1-------->"+ frecuency.get(0)[1]);
+         for (Object[] objects : frecuency) {
+           // System.out.println("---- MAX ----****"+ objects[0]);
+           // System.out.println("---- MIN ----****"+ objects[1]);
+        }
+    }
 
 }