Commit bbe224d2 authored by javier's avatar javier
Browse files

Changes in the round logic

the Client must send decisions for every redditor every round even when
no more posts are present for the redditor
parent 8090c723
......@@ -22,9 +22,11 @@ import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import org.apache.http.HttpResponse;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.irlab.erisk.util.client.vo.Post;
......@@ -37,10 +39,12 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public class Client {
private static final Logger logger = LoggerFactory.getLogger(Client.class);
private static String ENDPOINT_GET_WRITINGS = "http://erisk.irlab.org/challenge-service/getwritings/%s";
private static String ENDPOINT_SUBMIT_DECISIONS = "http://erisk.irlab.org/challenge-service/submit/%s/%d";
private static final String ENDPOINT_GET_WRITINGS = "http://erisk.irlab.org/challenge-service/getwritings/%s";
private static final String ENDPOINT_SUBMIT_DECISIONS = "http://erisk.irlab.org/challenge-service/submit/%s/%d";
private static List<String> allUsers;
public static List<Post> getUserWritings(String teamToken) {
final ObjectMapper mapper = new ObjectMapper();
try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
HttpGet request = new HttpGet(String.format(ENDPOINT_GET_WRITINGS, teamToken));
......@@ -48,18 +52,25 @@ public class Client {
request.addHeader("content-type", "application/json");
HttpResponse response = httpClient.execute(request);
Post[] writings = mapper.readValue(response.getEntity().getContent(), Post[].class);
logger.debug("Subject object: {}", Arrays.toString(writings));
if (allUsers == null) {
allUsers = new ArrayList<>();
for (Post p : writings) {
allUsers.add(p.getNick());
}
}
return Arrays.asList(writings);
} catch (IOException e) {
logger.info("IOError network: {}", e);
logger.info("IOError network / sever error: {}", e);
}
return new ArrayList<>();
}
public static void submitDecisions(List<Post> posts, String teamToken, int run) {
TeamDecision[] decisions = new TeamDecision[posts.size()];
for (int i = 0; i < decisions.length; i++) {
decisions[i] = new TeamDecision(posts.get(i).getNick(),
logger.info("Processing {} posts", posts.size());
TeamDecision[] decisions = new TeamDecision[allUsers.size()];
for (int i = 0; i < allUsers.size(); i++) {
decisions[i] = new TeamDecision(allUsers.get(i),
ThreadLocalRandom.current().nextInt(0, 2),
ThreadLocalRandom.current().nextDouble(0, 10));
}
......@@ -76,18 +87,18 @@ public class Client {
StringEntity params = new StringEntity(body);
request.addHeader("content-type", "application/json");
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
TeamDecision[] accepteddecisions = mapper.readValue(response.getEntity().getContent(),
TeamDecision[].class);
logger.debug("Accepted decisions: {}", Arrays.toString(accepteddecisions));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpClient.execute(request, responseHandler);
mapper.readValue(response, TeamDecision[].class);
logger.debug("Accepted decisions: {}", response);
} catch (IOException e) {
logger.info("IOError network: {}", e);
logger.info("IOError network / sever error: {} ", e);
}
}
public static void main(String[] args) throws IOException {
String teamToken = "";
public static void main(String[] args) {
String teamToken = "youtoken";
int runs = 5;
List<Post> posts = getUserWritings(teamToken);
int sequence = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment