Commits

Anonymous committed 8a0b3c7
  • Participants
  • Parent commits bcca11b

Comments (0)

Files changed (9)

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

             maxResults = this.MAX_RESULTS;
         }
         log.debug("Max Results HashTag -----> "+maxResults);
-        List<HashTag> tags = new ArrayList<HashTag>();
-        tags.addAll(getHashTagDao().getHashTags(maxResults, start, tagCriteria));
-        // Selecciona el Max y Minimo de Hits en HashTag
-
+        final List<HashTag> tags = getHashTagDao().getHashTags(maxResults, start, tagCriteria);
         final List<Object[]> maxMin = getHashTagDao().getMaxMinTagFrecuency();
         final long maxFrecuency =  (Long) maxMin.get(0)[0];
         final long minFrecuency =  (Long) maxMin.get(0)[1];
-        log.debug("MAX FRECUENCY ------> "+ maxFrecuency);
-        log.debug("MIN FRECUENCY ------> "+ minFrecuency);
         for (HashTag hashTag : tags) {
-           // log.debug("******///*********************************************///*********");
-            //  Selecciona el Numero de Uso del Tag en TweetPoll
-            final Long tagFrecuency = getHashTagFrecuency(hashTag.getHashTagId(),2);
-            final Long relevance = tagFrecuency + hashTag.getHits();
-            final Double logFrecuency = EnMeUtils.calculateSizeTag(relevance, maxFrecuency, minFrecuency);
-           // log.debug("LOG FRECUENCY ------> "+ logFrecuency);
-            hashTag.setSize(logFrecuency.longValue());
-           // log.debug("Hashtag total size a Convertir ---> "+hashTag.getSize());
+            long tagFrecuency = getHashTagFrecuency(hashTag.getHashTagId(), 2);
+            long relevance = (tagFrecuency + (hashTag.getHits() == null ? 0 : hashTag.getHits()));
+            double logFrecuency = EnMeUtils.calculateSizeTag(relevance, maxFrecuency, minFrecuency);
+            hashTag.setSize(Math.round(logFrecuency));
             getFrontEndDao().saveOrUpdate(hashTag);
-           // log.debug("******///*********************************************///*********");
         }
         hashBean.addAll(ConvertDomainBean.convertListHashTagsToBean(tags));
         return hashBean;

encuestame-business/src/test/java/org/encuestame/test/business/service/TestFrontEndService.java

  */
 package org.encuestame.test.business.service;
 
+import java.util.List;
+
 import org.encuestame.business.service.FrontEndService;
 import org.encuestame.business.service.imp.IFrontEndService;
 import org.encuestame.persistence.domain.HashTag;
 import org.encuestame.persistence.domain.HashTagHits;
+import org.encuestame.persistence.domain.question.Question;
+import org.encuestame.persistence.domain.question.QuestionAnswer;
 import org.encuestame.persistence.domain.security.UserAccount;
+import org.encuestame.persistence.domain.tweetpoll.TweetPoll;
 import org.encuestame.test.business.service.config.AbstractServiceBase;
+import org.encuestame.utils.web.HashTagBean;
 import org.junit.Before;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
     final String ipAddress2 = "192.168.1.2";
 
+    /** {@link TweetPoll}. **/
+    private TweetPoll tweetPoll;
+
     @Before
     public void initData(){
         this.secondary = createUserAccount("paola", createAccount());
-        this.hashTag = createHashTag("software");
         this.hashTagHit = createHashTagHit(hashTag, this.ipAddress, this.secondary);
+        final Question question = createQuestion("Who I am?", "");
+        createQuestionAnswer("yes", question, "12345");
+        createQuestionAnswer("no", question, "12346");
+        this.tweetPoll = createPublishedTweetPoll(secondary.getAccount(), question);
+        this.hashTag = createHashTag("hardware",50L);
+        final HashTag hashTag2 = createHashTag("programmer",80L);
+        this.tweetPoll.getHashTags().add(hashTag);
+        this.tweetPoll.getHashTags().add(hashTag2);
+        getTweetPoll().saveOrUpdate(this.tweetPoll);
+
         //System.out.println("hashTag ID --->"+ hashTag.getHashTagId());
     }
 
         System.out.println(" previous tag hit --> "+ this.hashTag.getHits());
         final Boolean registerHit = getFrontEndService().registerHashTagHit(this.hashTag.getHashTag(), this.ipAddress,
                                     this.secondary.getUsername());
-        System.out.println(" Se agrego registro nuevo? --> "+ registerHit);
-        System.out.println(" tag hit anterior 2--> "+ this.hashTag.getHits());
         getFrontEndService().registerHashTagHit(this.hashTag.getHashTag(), this.ipAddress2,
                              this.secondary.getUsername());
-        System.out.println(" tag hit posterior --> "+ this.hashTag.getHits());
+    }
+
+    /**
+     * Test Get hash tags
+     */
+    @Test
+    public void testGetHashTags(){
+
+        /** Hash Tags **/
+        final HashTag hashTag1 = createHashTag("software",50L);
+        final HashTag hashTag2 = createHashTag("holidays",70L);
+        final HashTag hashTag3 = createHashTag("futboll",80L);
+        final HashTag hashTag4 = createHashTag("championsLeague",90L);
+        final HashTag hashTag5 = createHashTag("copaAmerica",150L);
+
+        /** Question 2 **/
+        final Question question2 = createQuestion("Question 1", "");
+        createQuestionAnswer("yes", question2, "12345");
+        createQuestionAnswer("no", question2, "12346");
+        this.tweetPoll = createPublishedTweetPoll(secondary.getAccount(), question2);
+
+        this.tweetPoll.getHashTags().add(hashTag1);
+        this.tweetPoll.getHashTags().add(hashTag2);
+        getTweetPoll().saveOrUpdate(this.tweetPoll);
+
+        /** Question 3 **/
+        final Question question3 = createQuestion("Question 2", "");
+        createQuestionAnswer("yes", question3, "12345");
+        createQuestionAnswer("no", question3, "12346");
+        this.tweetPoll = createPublishedTweetPoll(secondary.getAccount(), question3);
+
+        this.tweetPoll.getHashTags().add(hashTag1);
+        this.tweetPoll.getHashTags().add(hashTag2);
+        this.tweetPoll.getHashTags().add(hashTag3);
+        getTweetPoll().saveOrUpdate(this.tweetPoll);
+
+        /** Question 4 **/
+        final Question question4 = createQuestion("Question 3", "");
+        createQuestionAnswer("yes", question4, "12345");
+        createQuestionAnswer("no", question4, "12346");
+        this.tweetPoll = createPublishedTweetPoll(secondary.getAccount(), question4);
+
+        this.tweetPoll.getHashTags().add(hashTag1);
+        this.tweetPoll.getHashTags().add(hashTag4);
+        this.tweetPoll.getHashTags().add(hashTag5);
+        getTweetPoll().saveOrUpdate(this.tweetPoll);
+
+        /** Question 5 **/
+        final Question question5 = createQuestion("Question 4", "");
+        createQuestionAnswer("yes", question5, "12345");
+        createQuestionAnswer("no", question5, "12346");
+        this.tweetPoll = createPublishedTweetPoll(secondary.getAccount(), question5);
+
+        this.tweetPoll.getHashTags().add(hashTag4);
+        this.tweetPoll.getHashTags().add(hashTag5);
+        this.tweetPoll.getHashTags().add(hashTag3);
+        getTweetPoll().saveOrUpdate(this.tweetPoll);
+
+        final Question question6 = createQuestion("Question 5", "");
+        createQuestionAnswer("yes", question6, "12345");
+        createQuestionAnswer("no", question6, "12346");
+        this.tweetPoll = createPublishedTweetPoll(secondary.getAccount(), question6);
+
+        this.tweetPoll.getHashTags().add(hashTag3);
+        this.tweetPoll.getHashTags().add(hashTag4);
+        this.tweetPoll.getHashTags().add(hashTag5);
+        getTweetPoll().saveOrUpdate(this.tweetPoll);
+
+        final List<HashTagBean> hashBean = getFrontEndService().getHashTags(30, 0, "");
+        System.out.println(" Hash Bean size --> "+hashBean.size());
+        for (HashTagBean hashTagBean : hashBean) {
+           // System.out.println(" Hash Bean size --> "+hashTagBean.getSize());
+        }
     }
 
     /**

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

 
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
-import java.util.Calendar;
 import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
         unitHashTag.setHits(hashTag.getHits());
         //TODO: ENCUESTAME-191
         // int x = (10 + (int)(Math.random() * ((40) - 5) + 10)); //TEMP.
-        log.debug("Hastag Number GET SIZE---> "+hashTag.getSize().intValue());
-        unitHashTag.setSize(hashTag.getSize().intValue());
+        if(hashTag.getSize() != null){
+            unitHashTag.setSize(hashTag.getSize().intValue());
+        }
+
         return unitHashTag;
     }
 

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

     /** Front End Service Log. **/
     private static Logger log = Logger.getLogger(EnMeUtils.class);
 
+
+    private static final int BASE = 2;
+    private static final int MIN_SIZE = 12;
+
     /**
      * Calculate percent.
      * @param total
     }
 
     /**
-     *
+     * Description.
+     * <p>
+     * The frequency is calculated based on the hits (visits) that receives the hashtag
+     * and use has on tweetPolls, survey, etc.. Frequency is the use of hashtag.
+     * </p>
      * @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(long frecuency, long  frecMax, long frecMin){
-         double perRelative ;
-         float frec = Float.valueOf(frecuency);
-         float maxiFrec = Float.valueOf(frecMax);
-         float miniFrec = Float.valueOf(frecMin);
-         double minValue = Double.valueOf(12);
-         final float frecDiff = frec - miniFrec;
-         perRelative = ((frec-miniFrec)/frecDiff);
-         double perLog = (Math.log(perRelative)/Math.log(2))+minValue;
-
-        return perLog;
+    public static long calculateSizeTag(long frecuency, long  frecMax, long frecMin) {
+        float frec = Float.valueOf(frecuency);
+        float maxiFrec = Float.valueOf(frecMax);
+        float miniFrec = Float.valueOf(frecMin);
+        double minValue = Double.valueOf(EnMeUtils.MIN_SIZE);
+        final float frecDiff = frecMax - miniFrec;
+        double perRelative = ((frec - miniFrec) / (frecDiff == 0 ? 1 : frecDiff)) * maxiFrec;
+        double perLog;
+        if (perRelative == 0) {
+            perLog = minValue;
+        } else {
+            perLog = (Math.log(perRelative) / Math.log(EnMeUtils.BASE))
+             + minValue;
+        }
+        log.debug("Size tag Value ---------------> " + Math.round(perLog) );
+        return Math.round(perLog);
     }
 }

encuestame-core/src/test/java/org/encuestame/core/test/util/EnMeUtilsTestCase.java

  */
 public class EnMeUtilsTestCase extends TestCase {
 
+    /**
+    * Test calculate size tag.
+    */
     @Test
-    public void testCalculateSizeTag(){
-        long f = 32;
-        long mi = 10;
-        long ma = 85;
-        float frecuency = Float.valueOf(f);
-        float max = Float.valueOf(ma);
-        float min = Float.valueOf(mi);
-        double fijo = Double.valueOf(12);
-
-        final float frecDiff = max - min;
-        //System.out.println("FRECUENCY Relevance ------> "+ frecuency);
-        //System.out.println("MIN FRECUENCY ------> "+ max);
-        //System.out.println("MAX FRECUENCY ------> "+ min);
-        //System.out.println("DIFFERENCE FRECUENCY ------> "+ frecDiff);
-        double perRelative = ((frecuency-min)/frecDiff);
-        final double perLog = (Math.log(perRelative)/Math.log(2))+fijo;
+    public void testCalculateSizeTag() {
+        final double calc1 = EnMeUtils.calculateSizeTag(40, 0, 0);
+        assertEquals(calc1, 12D);
+        final double calc2 = EnMeUtils.calculateSizeTag(3, 5, 1);
+        assertEquals(calc2, 13D);
+        final double calc3 = EnMeUtils.calculateSizeTag(40, 75, 15);
+        assertEquals(calc3, 17D);
+        final double calc4 = EnMeUtils.calculateSizeTag(75, 152, 75);
+        assertEquals(calc4, 12D);
+        final double calc5 = EnMeUtils.calculateSizeTag(140, 600000, 50);
+        assertEquals(calc5, 18D);
+        final double calc6 = EnMeUtils.calculateSizeTag(145001, 600000000, 5000);
+        assertEquals(calc6, 29D);
+        final double calc9 = EnMeUtils.calculateSizeTag(5003, 600000000, 5000);
+        assertEquals(calc9, 14D);
+        final double calc7 = EnMeUtils.calculateSizeTag(30, 85, 0);
+        assertEquals(calc7, 17D);
+        final double calc8 = EnMeUtils.calculateSizeTag(79, 85, 0);
+        assertEquals(calc8, 18D);
      }
-
 }

encuestame-mvc/src/main/java/org/encuestame/mvc/view/HashTagController.java

     @RequestMapping(value = "/tag/{name}", method = RequestMethod.GET)
     public String tagController(ModelMap model , HttpServletRequest request,
                   HttpServletResponse response,
-                  @PathVariable String name) throws EnmeFailOperation{
+                  @PathVariable String name){
         final IFrontEndService service = getFrontService();
         log.debug("hashTag Name ---> "+name);
         name = filterValue(name);
-        final String IP = "192.168.1.3";
-            //getIpClient();
+        final String IP = getIpClient();
         log.info("IP" + IP);
-
-        // Search HashTag hits.
-        boolean hashTagVisite = service.checkPreviousHashTagHit(IP);
-        // TODO: Check that previous hash Tag hit has been visited the same day.
-        if (!hashTagVisite) {
-           final Boolean tagHit = service.registerHashTagHit(name, IP, "paola");
-           System.out.println(" Registro hit? ---> "+tagHit);
-
-        }
         try {
+            // Search HashTag hits.
+              boolean hashTagVisite = service.checkPreviousHashTagHit(IP);
+            // TODO: Check that previous hash Tag hit has been visited the same day.
+              if (!hashTagVisite) {
+               final Boolean tagHit = service.registerHashTagHit(name, IP, "paola");
+            }
             final HashTagBean tag = service.getHashTagItem(name);
-            log.debug("hashTag Id ---> "+ tag.getId());
             final List<TweetPollBean> tweetPollbyTags = service.getTweetPollsbyHashTagId(tag.getId(), LIMIT_HASHTAG, "hashtag", request);
-            log.debug("TweetPolls by HashTag Id ---> "+ tweetPollbyTags.size());
-
             final List<TweetPollBean> tweetPollbyRated = service.getTweetPollsbyHashTagId(tag.getId(), LIMIT_HASHTAG, "hashtagRated", request);
-            log.debug("TweetPolls by Top rated ---> "+ tweetPollbyTags.size());
             if (tag == null) {
                 return "pageNotFound";
             } else {

encuestame-mvc/src/test/java/org/encuestame/mvc/test/view/HashTagControllerTestCase.java

 import org.encuestame.mvc.test.config.AbstractMvcUnitBeans;
 import org.encuestame.mvc.view.HashTagController;
 import org.encuestame.persistence.domain.HashTag;
+import org.encuestame.persistence.domain.HashTagHits;
+import org.encuestame.persistence.domain.security.Account;
+import org.encuestame.persistence.domain.security.UserAccount;
 import org.junit.Before;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
     @Test
     public void testHashTagController() throws Exception {
-      /*  final HashTag hashTag = createHashTag("software");
+        final HashTag hashTag = createHashTag("software", 50L);
+        final String ipAddress = "192.168.1.99";
+        final Account account = createAccount();
+        final UserAccount userAcc = createUserAccount("paola", account);
+        final HashTagHits tagHits = createHashTagHit(hashTag, ipAddress, userAcc);
         request = new MockHttpServletRequest(MethodJson.GET.toString(), "/tag/software");
         final ModelAndView mav = handlerAdapter.handle(request, response,
                 hashTagController);
         assertViewName(mav, "tag/detail");
-*/
         System.out.println("Test hash Tag Controller");
 
     }

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

         assertNotNull(this.hashTagHit);
         flushIndexes();
         final List<HashTagHits> hitsbyIp = getFrontEndDao().getHashTagsHitByIp(this.ipAddress);
-        System.out.print("SIZE HASHTAG hit---> "+ hitsbyIp.size());
+       // System.out.print("SIZE HASHTAG hit---> "+ hitsbyIp.size());
         assertNotNull(hitsbyIp);
         assertEquals("Should be equals", hitsbyIp.get(0).getIpAddress(), this.ipAddress);
         assertEquals("Should be equals", hitsbyIp.size(),1);

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

         getTweetPoll().saveOrUpdate(tweetPoll2);
 
         final Calendar calendar3 = Calendar.getInstance();
-        System.out.println("THIRD CALENDAR --> "+calendar3.getTime());
+        //System.out.println("THIRD CALENDAR --> "+calendar3.getTime());
 
         final HashMap<Integer, RelativeTimeEnum> hm3 = DateUtil.getRelativeTime(tweetPoll1.getCreateDate());
-        System.out.println("HM 3 ---------->"+hm3);
+        //System.out.println("HM 3 ---------->"+hm3);
 
         final List<TweetPoll> tweetPolls2 = getTweetPoll().getTweetpollByHashTagId(this.hashTag1.getHashTagId(), limit, "hashtag");
-        System.out.println("------------- HASH TAG NAME---------> " + this.hashTag1.getHashTag());
+        //System.out.println("------------- HASH TAG NAME---------> " + this.hashTag1.getHashTag());
 
 
         final Calendar calendar4 = Calendar.getInstance();
-        System.out.println(calendar.getTime());
+        //System.out.println(calendar.getTime());
 
         final HashMap<Integer, RelativeTimeEnum> hm4 = DateUtil.getRelativeTime(tweetPoll2.getCreateDate());
-        System.out.println("HM---------->"+hm4);
+        //System.out.println("HM---------->"+hm4);
 
         for (TweetPoll tweetPoll : tweetPolls2) {
-             System.out.println(" TWITS BY HASHTAG --> " + tweetPoll.getQuestion().getQuestion() + "Published -->" + tweetPoll.getCreateDate());
+             //System.out.println(" TWITS BY HASHTAG --> " + tweetPoll.getQuestion().getQuestion() + "Published -->" + tweetPoll.getCreateDate());
         }
         assertEquals("Should be equals", 3, tweetPolls2.size());
     }