use of com.geminimobile.chart.ChartSeries in project logprocessing by cloudian.
the class CDRDataAccess method getChartDataByHour.
public List<ChartSeries> getChartDataByHour(long minTimestamp, long maxTimestamp, String market, String messageType, int limit) {
List<ChartSeries> chartData = new ArrayList<ChartSeries>();
ChartSeries series = new ChartSeries("CDR count for all MSISDNs for " + market + ", with type = " + messageType);
List<ChartValueByTime> chartVals = new ArrayList<ChartValueByTime>();
try {
// Modify the maxTimestamp, since it is 'inclusive'. Decrease it by 1ms
maxTimestamp--;
// Truncate minTime and maxTime to nearest hour
long maxHour = (maxTimestamp / MS_PER_HOUR) * MS_PER_HOUR;
long minHour = (minTimestamp / MS_PER_HOUR) * MS_PER_HOUR;
String strMinHour = m_sdfHourly.format(new Date(minHour));
String strMaxHour = m_sdfHourly.format(new Date(maxHour));
//long begColTS = 0;
int currentCount = 0;
// Get a chunk of rows - one row contains one data value. TODO: Need to take care of the last row in the
// list as a special case - since it will probably not contain all the entries for the hour.
// TODO: query the DB in a loop, getting all records between min and max hour.
List<Row<String, String, String>> rows = m_daoHourlyTimeline.getRangeSlice(strMinHour, strMaxHour, "", LIMIT, false);
for (Row<String, String, String> row : rows) {
// Hourly time stamp.
String strTime = row.getKey();
long timeStamp = Long.parseLong(strTime);
// One row contains all the CDRs for a particular hour. Count them.
List<HColumn<String, String>> cols = row.getColumnSlice().getColumns();
for (int i = 0; i < cols.size(); ++i) {
HColumn<String, String> result = cols.get(i);
String sEntryID = new String(result.getValue());
String sType = m_daoCDREntry.get(sEntryID, COL_TYPE, StringSerializer.get());
String sMarket = m_daoCDREntry.get(sEntryID, COL_MARKET, StringSerializer.get());
// Filter by market and message type
if (sType == null || sMarket == null || (sType.compareTo(messageType) != 0 && !messageType.equals(MESSAGE_TYPE_ALL)) || sMarket.compareTo(market) != 0) {
// Skip this entry
continue;
}
currentCount++;
}
if (currentCount > 0) {
ChartValueByTime chartval = new ChartValueByTime(currentCount, timeStamp);
chartVals.add(chartval);
}
currentCount = 0;
}
} catch (Exception e) {
logger.error(e.getMessage());
e.printStackTrace();
}
series.setData(chartVals);
chartData.add(series);
return chartData;
}
use of com.geminimobile.chart.ChartSeries in project logprocessing by cloudian.
the class CDRDataAccess method getChartDataByMSISDN.
public List<ChartSeries> getChartDataByMSISDN(String msisdn, long minTimestamp, long maxTimestamp, String market, String messageType, int limit) {
List<ChartSeries> chartData = new ArrayList<ChartSeries>();
ChartSeries series = new ChartSeries("CDR count for : " + msisdn);
List<ChartValueByTime> chartVals = new ArrayList<ChartValueByTime>();
try {
// Modify the maxTimestamp, since it is 'inclusive'. Decrease it by 1 ms
maxTimestamp--;
String strMinStamp = Long.toString(minTimestamp);
String strMaxStamp = Long.toString(maxTimestamp);
List<HColumn<String, String>> results = m_daoMSISDNTimeline.getSliceUsingTimestamp(msisdn, strMinStamp, strMaxStamp, limit, false);
long currentHour = minTimestamp;
currentHour = (currentHour / MS_PER_HOUR) * MS_PER_HOUR;
int currentCount = 0;
// Split up the data based on hour
for (int i = 0; i < results.size(); i++) {
HColumn<String, String> result = results.get(i);
String entryTimestampStr = result.getName();
String[] colNameParts = entryTimestampStr.split("_");
if (colNameParts == null || colNameParts.length < 2) {
logger.error("Invalid key from MSISDNTimeline table: " + entryTimestampStr);
break;
}
long entryTimestamp = Long.parseLong(colNameParts[0]);
String sEntryID = new String(result.getValue());
String sType = m_daoCDREntry.get(sEntryID, COL_TYPE, StringSerializer.get());
String sMarket = m_daoCDREntry.get(sEntryID, COL_MARKET, StringSerializer.get());
// Filter by market and message type
if (sType == null || sMarket == null || (sType.compareTo(messageType) != 0 && !messageType.equals(MESSAGE_TYPE_ALL)) || sMarket.compareTo(market) != 0) {
// Skip this entry
continue;
}
//long entryTimestamp = Long.parseLong(sTimestamp);
if (entryTimestamp < (currentHour + MS_PER_HOUR)) {
// Keep count of the number of CDRs for this hour
currentCount++;
} else {
// Done with this hour
ChartValueByTime chartval = new ChartValueByTime(currentCount, currentHour);
chartVals.add(chartval);
// Reset counters
currentHour = currentHour + MS_PER_HOUR;
currentCount = 1;
}
}
// Take care of final hour
if (currentCount > 0) {
ChartValueByTime chartval = new ChartValueByTime(currentCount, currentHour);
chartVals.add(chartval);
currentCount = 0;
}
} catch (Exception e) {
logger.error(e.getMessage());
e.printStackTrace();
}
series.setData(chartVals);
chartData.add(series);
return chartData;
}
use of com.geminimobile.chart.ChartSeries in project logprocessing by cloudian.
the class GeminiChartController method handleRequestInternal.
//This controller linked to by an img control on gemstats.jsp (message stats reporting page).
//Call the JFreeChart tool to generate the chart. The result goes into the OutputStream.
//Only cummulative-type reports use this controller - not snapshot-type.
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
// The data to be reported on this chart was put in the session by GenerateGemStatsController
// Example of query string is:
// tableTitleText=MM3 Messages Sent by Hour for Service Provider 1111 for Vasp 4444&intervalText=Hour&messageType=MM3.MPS;
List<ChartSeries> chartData = (List<ChartSeries>) request.getSession(true).getAttribute("chartData");
String chartTitle = (String) request.getParameter("chartTitle");
String intervalText = (String) request.getParameter("intervalText");
try {
response.setContentType("image/png");
if (chartData != null && chartData.size() > 0) {
//Create the chart with chart tool
GeminiChartUtil chartUtil = new GeminiChartUtil();
// chartData - are the data points themselves- ex. [<number>, <time interval>]
// tableTitleText - is displayed as the chart's title. Ex. "MM3 Msgs Sent for Service Provider 1111 and Vasp 6543"
// intervalText - displayed as part of the X-Axis label. Ex. "Hour"
chartUtil.createReport(response.getOutputStream(), chartData, chartTitle, intervalText);
}
// write data to CSV file
// System.out.println("GCC Calling CSV generation");
// GemStatsCSVGeneration csvGeneration = new GemStatsCSVGeneration();
// String csvData = csvGeneration.generateCSV(chartData, messageType);
// request.getSession().setAttribute(CSVDATA,csvData); // set in session for csv file data
} catch (Exception e) {
e.printStackTrace();
throw new ServletException("Could not get statistic values. Probably a Database issue");
}
return null;
}
Aggregations