Search in sources :

Example 1 with ChartValueByTime

use of com.geminimobile.chart.ChartValueByTime 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;
}
Also used : ArrayList(java.util.ArrayList) ChartSeries(com.geminimobile.chart.ChartSeries) Date(java.util.Date) ChartValueByTime(com.geminimobile.chart.ChartValueByTime) HColumn(me.prettyprint.hector.api.beans.HColumn) Row(me.prettyprint.hector.api.beans.Row)

Example 2 with ChartValueByTime

use of com.geminimobile.chart.ChartValueByTime 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;
}
Also used : ArrayList(java.util.ArrayList) ChartSeries(com.geminimobile.chart.ChartSeries) ChartValueByTime(com.geminimobile.chart.ChartValueByTime) HColumn(me.prettyprint.hector.api.beans.HColumn)

Aggregations

ChartSeries (com.geminimobile.chart.ChartSeries)2 ChartValueByTime (com.geminimobile.chart.ChartValueByTime)2 ArrayList (java.util.ArrayList)2 HColumn (me.prettyprint.hector.api.beans.HColumn)2 Date (java.util.Date)1 Row (me.prettyprint.hector.api.beans.Row)1