package it.cybion.socialeyeser;

import java.util.HashMap;
import java.util.Random;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.apache.log4j.Logger;

import com.google.inject.Inject;

@Produces(MediaType.APPLICATION_JSON)
@Path("/twitter")
public class InfluencersService {
    
    private static final Logger LOGGER = Logger.getLogger(InfluencersService.class);
    
    private HashMap<String, Double> cache;
    private Random randomGenerator;
    
    @Inject
    public InfluencersService() {
    
        LOGGER.info("Starting influence service");
        cache = new HashMap<String, Double>();
        randomGenerator = new Random(System.nanoTime());
    }
    
    @GET
    @Path("/{userId}")
    public InfluenceScore add(@PathParam("userId") String twitterUserId) throws ServiceException {
    
        try {
            LOGGER.info("Request for user " + twitterUserId);
            
            if (cache.containsKey(twitterUserId))
                return new InfluenceScore(cache.get(twitterUserId));
            else {
                
                // ranging random scores [0.01, 0.51]
                double score = (randomGenerator.nextInt(5000) / 10000.0) + 0.01;
                cache.put(twitterUserId, score);
                return new InfluenceScore(cache.get(twitterUserId));
            }
        } catch (final Exception e) {
            throw new ServiceException("Error", e);
        }
        
    }
    
}
@@ -147,24 +147,23 @@
 .ws.rs.P
-athParam
+roduces
 ;%0Aimport
@@ -171,32 +171,34 @@
 javax.ws.rs.
-Produces
+QueryParam
 ;%0Aimport jav
@@ -471,24 +471,83 @@
 lass);%0A    %0A
+    private static final double MAX_FOLLOWERS = 1000000.0;%0A
     private 
@@ -848,31 +848,8 @@
 GET%0A
-    @Path(%22/%7BuserId%7D%22)%0A
     
@@ -875,20 +875,21 @@
 re add(@
-Path
+Query
 Param(%22u
@@ -903,29 +903,74 @@
  String 
-twitterUserId
+userId,%0A            @QueryParam(%22followers%22) int followers
 ) throws
@@ -1054,29 +1054,60 @@
 ser %22 + 
-twitterUserId
+userId + %22 with %22 + followers + %22 followers%22
 );%0A     
@@ -1148,24 +1148,17 @@
 ainsKey(
-twitterU
+u
 serId))%0A
@@ -1205,32 +1205,25 @@
 e(cache.get(
-twitterU
+u
 serId));%0A   
@@ -1304,14 +1304,12 @@
 %5B0.0
-1, 0.5
+05, 
 1%5D%0A 
@@ -1367,30 +1367,232 @@
 Int(
-5
+1
 000) / 
-1
+2
 0000.0)
- + 0.0
+%0A                        + (Math.log10(Math.min(followers, MAX_FOLLOWERS)) / Math%0A                                .log10(MAX_FOLLOWERS)) - 0.05;%0A                if (score %3C 0)%0A                    score *= -0.
 1;%0A 
@@ -1601,24 +1601,27 @@
             
+ //
  cache.put(t
@@ -1619,24 +1619,17 @@
 che.put(
-twitterU
+u
 serId, s
@@ -1681,32 +1681,13 @@
 ore(
-cache.get(twitterUserId)
+score
 );%0A 

refined score formula. removed cache