Skip to content

Commit

Permalink
Merge pull request #41 from qcri-social/staging
Browse files Browse the repository at this point in the history
Merging staging to master (Release 2.0)
  • Loading branch information
kushalkantgoyal committed Aug 6, 2015
2 parents 700e9b6 + 03eeccf commit e6cb594
Show file tree
Hide file tree
Showing 244 changed files with 3,482 additions and 2,647 deletions.
4 changes: 2 additions & 2 deletions aidr-analytics/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
<artifactId>aidr-common</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<!-- dependency>
<groupId>qa.qcri.aidr.output</groupId>
<artifactId>aidr-output</artifactId>
<version>1.0</version>
<type>jar</type>
</dependency>
</dependency -->

<!-- Web dependencies -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @author Imran
*/
@javax.ws.rs.ApplicationPath("rest")
@javax.ws.rs.ApplicationPath("/rest/analytics/")
public class ApplicationConfig extends Application {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import qa.qcri.aidr.analysis.facade.ConfidenceStatisticsResourceFacade;
import qa.qcri.aidr.common.code.DateFormatConfig;
import qa.qcri.aidr.output.getdata.ChannelBufferManager;


/**
Expand All @@ -31,7 +30,7 @@
*/

@Path("/confData/")
public class GetConfidenceStatistics extends GetStatistics implements ServletContextListener {
public class GetConfidenceStatistics implements ServletContextListener {

// Debugging
private static Logger logger = Logger.getLogger(GetConfidenceStatistics.class);
Expand Down Expand Up @@ -64,25 +63,6 @@ public Response ping() {
return Response.ok(obj).build();
}


@GET
@Path("/manage/restart/{passcode}")
@Produces("application/json")
public Response restartAnalyticsService(@PathParam("passcode") String passcode) {
logger.info("Request received");
if (passcode.equals("sysadmin2013")) {
if (masterCBManager != null) {
masterCBManager.close();
}
masterCBManager = new ChannelBufferManager();
masterCBManager.initiateChannelBufferManager(CHANNEL_REG_EX);
logger.info("aidr-output analytics service restarted...");
final String statusStr = "{\"aidr-output analytics ConfidenceStats service\":\"RESTARTED\"}";
return Response.ok(statusStr).build();
}
return Response.ok(new String("{\"password\":\"invalid\"}")).build();
}

@Override
public void contextDestroyed(ServletContextEvent arg0) {
// TODO Auto-generated method stub
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package qa.qcri.aidr.analysis.api;

import qa.qcri.aidr.output.getdata.ChannelBufferManager;


public abstract class GetStatistics {
Expand All @@ -9,6 +8,4 @@ public abstract class GetStatistics {
public static final String CHANNEL_REG_EX = "aidr_predict.*";
public static final String CHANNEL_PREFIX_STRING = "aidr_predict.";

public volatile static ChannelBufferManager masterCBManager = null; // managing buffers for each publishing channel

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package qa.qcri.aidr.analysis.api;


import javax.ejb.EJB;
import javax.json.Json;
import javax.json.JsonObject;
import javax.servlet.ServletContextEvent;
Expand All @@ -19,19 +20,62 @@

import org.apache.log4j.Logger;


import qa.qcri.aidr.analysis.facade.TagDataStatisticsResourceFacade;
import qa.qcri.aidr.analysis.service.GetTagDataStatisticsService;

/**
* This is the REST API interface for accessing the aidr_analytics DB's tag_data entity.
*/

@Path("/tagData/")
public class GetTagDataStatistics extends GetStatistics implements ServletContextListener {
/**
* @author koushik
*
*/
@Path("/tagdata/")
public class GetTagDataStatistics implements ServletContextListener {

// Debugging
private static Logger logger = Logger.getLogger(GetTagDataStatistics.class);

@EJB
private GetTagDataStatisticsService tagDataService;


/**
* @param crisisCode
* @param granularity
* @param startTime
* @return Tag counts for individual attributes of a crisis, only for the specified granularity and since 'startTime'
*/
@GET
@Path("/getlabelsum/{crisisCode}/{granularity}")
@Produces(MediaType.APPLICATION_JSON)
public Response getTagCountSumForAllAttributesFromTime(@PathParam("crisisCode") String crisisCode,
@PathParam("granularity") Long granularity,
@DefaultValue("0") @QueryParam("startTime") Long startTime) {

JSONObject json = tagDataService.getTagCountSumForAllAttributesFromTime(crisisCode, granularity, startTime);
return Response.ok(json.toJSONString()).build();
}



/**
* @param crisisCode
* @param startTime
* @return Tag counts over all attributes for a crisis, sorted by granularity levels
*/
@GET
@Path("/getlabelsum/{crisisCode}")
@Produces(MediaType.APPLICATION_JSON)
public Response getTagCountSumForAllGranularitiesFromTime(@PathParam("crisisCode") String crisisCode,
@DefaultValue("0") @QueryParam("startTime") Long startTime) {

JSONObject json = tagDataService.getTagCountSumByGranularity(crisisCode, startTime);
return Response.ok(json.toJSONString()).build();
}


/**
*
* @param crisisCode
Expand All @@ -41,14 +85,14 @@ public class GetTagDataStatistics extends GetStatistics implements ServletContex
* @return Count sum per label from startTime to current time at the given granularity, for crisisCode and attributeCode
*/
@GET
@Path("/getLabelSum/{crisisCode}/{classifierCode}/{granularity}")
@Path("/getlabelsum/{crisisCode}/{attributeCode}/{granularity}")
@Produces(MediaType.APPLICATION_JSON)
public Response getTagCountSumFromTime(@PathParam("crisisCode") String crisisCode,
@PathParam("attributeCode") String attributeCode,
@PathParam("granularity") Long granularity,
@DefaultValue("0") @QueryParam("startTime") Long startTime) {

JSONObject json = new GetTagDataStatisticsService().getTagCountSumFromTime(crisisCode, attributeCode, granularity, startTime);
JSONObject json = tagDataService.getTagCountSumFromTime(crisisCode, attributeCode, granularity, startTime);
return Response.ok(json.toJSONString()).build();
}

Expand All @@ -61,14 +105,14 @@ public Response getTagCountSumFromTime(@PathParam("crisisCode") String crisisCod
* @return Count per label in the specified time window at the given granularity, for crisisCode and attributeCode
*/
@GET
@Path("/getLabelCount/{crisisCode}/{attributeCode}/{granularity}")
@Path("/getlabelcount/{crisisCode}/{attributeCode}/{granularity}")
@Produces(MediaType.APPLICATION_JSON)
public Response getTagCountInTimeWindow(@PathParam("crisisCode") String crisisCode,
@PathParam("attributeCode") String attributeCode,
@PathParam("granularity") Long granularity,
@DefaultValue("0") @QueryParam("startTime") Long startTime) {

JSONObject json = new GetTagDataStatisticsService().getTagCountInTimeWindow(crisisCode, attributeCode, granularity, startTime);
JSONObject json = tagDataService.getTagCountInTimeWindow(crisisCode, attributeCode, granularity, startTime);
return Response.ok(json.toJSONString()).build();
}

Expand All @@ -82,7 +126,7 @@ public Response getTagCountInTimeWindow(@PathParam("crisisCode") String crisisCo
* @return Time series data for each label in the interval [startTime, endTime] at the given granularity, for crisisCode and attributeCode
*/
@GET
@Path("/getLabelTimeSeries/{crisisCode}/{attributeCode}/{granularity}")
@Path("/getlabeltimeseries/{crisisCode}/{attributeCode}/{granularity}")
@Produces(MediaType.APPLICATION_JSON)
public Response getTagCountTimeSeries(@PathParam("crisisCode") String crisisCode,
@PathParam("attributeCode") String attributeCode,
Expand All @@ -93,7 +137,7 @@ public Response getTagCountTimeSeries(@PathParam("crisisCode") String crisisCode
if (null == endTime || endTime < startTime) {
endTime = System.currentTimeMillis();
}
JSONObject json = new GetTagDataStatisticsService().getTagCountTimeSeries(crisisCode, attributeCode, granularity, startTime, endTime);
JSONObject json = tagDataService.getTagCountTimeSeries(crisisCode, attributeCode, granularity, startTime, endTime);
return Response.ok(json.toJSONString()).build();
}

Expand All @@ -107,15 +151,15 @@ public Response getTagCountTimeSeries(@PathParam("crisisCode") String crisisCode
* @return Count sum for each label in the interval [startTime, endTime] at the given granularity, for crisisCode and attributeCode
*/
@GET
@Path("/getIntervalLabelSum/{crisisCode}/{attributeCode}/{granularity}")
@Path("/getintervallabelsum/{crisisCode}/{attributeCode}/{granularity}")
@Produces(MediaType.APPLICATION_JSON)
public Response getTagCountSumInInterval(@PathParam("crisisCode") String crisisCode,
@PathParam("attributeCode") String attributeCode,
@PathParam("granularity") Long granularity,
@DefaultValue("0") @QueryParam("startTime") Long startTime,
@QueryParam("endTime") Long endTime) {

JSONObject json = new GetTagDataStatisticsService().getTagCountSumInInterval(crisisCode, attributeCode, granularity, startTime, endTime);
JSONObject json = tagDataService.getTagCountSumInInterval(crisisCode, attributeCode, granularity, startTime, endTime);
return Response.ok(json.toJSONString()).build();
}

Expand All @@ -130,14 +174,14 @@ public Response getTagCountSumInInterval(@PathParam("crisisCode") String crisisC
* @return The count for a label in the specified time window at the given granularity, for crisisCode and attributeCode
*/
@GET
@Path("/getOneLabelData/{crisisCode}/{attributeCode}/{labelCode}/{granularity}/{startTime}")
@Path("/getonelabeldata/{crisisCode}/{attributeCode}/{labelCode}/{granularity}/{startTime}")
@Produces(MediaType.APPLICATION_JSON)
public Response getSingleItem(@PathParam("crisisCode") String crisisCode,
@PathParam("attributeCode") String attributeCode,
@PathParam("labelCode") String labelCode,
@PathParam("granularity") Long granularity,
@PathParam("startTime") Long startTime) {
JSONObject json = new GetTagDataStatisticsService().getSingleItem(crisisCode, attributeCode, labelCode, granularity, startTime);
JSONObject json = tagDataService.getSingleItem(crisisCode, attributeCode, labelCode, granularity, startTime);
return Response.ok(json.toJSONString()).build();
}

Expand Down
Loading

0 comments on commit e6cb594

Please sign in to comment.