Search in sources :

Example 1 with TimeSeriesChart

use of org.ff4j.audit.chart.TimeSeriesChart in project ff4j by ff4j.

the class OperationsController method graphTimeSeriesasJson.

/**
 * Generation of JSON to render Features.
 *
 * @param req
 *      current request
 * @param res
 *      current response
 * @throws IOException
 */
private void graphTimeSeriesasJson(HttpServletRequest req, HttpServletResponse res) throws IOException {
    res.setContentType(CONTENT_TYPE_JSON);
    EventQueryDefinition query = parseQuery(req);
    TimeSeriesChart tsc = getFf4j().getEventRepository().getFeatureUsageHistory(query, TimeUnit.HOURS);
    res.getWriter().println(tsc.toString());
}
Also used : TimeSeriesChart(org.ff4j.audit.chart.TimeSeriesChart) EventQueryDefinition(org.ff4j.audit.EventQueryDefinition)

Example 2 with TimeSeriesChart

use of org.ff4j.audit.chart.TimeSeriesChart in project ff4j by ff4j.

the class EventRepositoryCassandra method getFeatureUsageHistory.

/**
 * {@inheritDoc}
 */
@Override
public TimeSeriesChart getFeatureUsageHistory(EventQueryDefinition query, TimeUnit units) {
    // Create the interval depending on units
    TimeSeriesChart tsc = new TimeSeriesChart(query.getFrom(), query.getTo(), units);
    // Search All events
    Iterator<Event> iterEvent = searchFeatureUsageEvents(query).iterator();
    // Dispatch events into time slots
    while (iterEvent.hasNext()) {
        tsc.addEvent(iterEvent.next());
    }
    return tsc;
}
Also used : TimeSeriesChart(org.ff4j.audit.chart.TimeSeriesChart) Event(org.ff4j.audit.Event)

Example 3 with TimeSeriesChart

use of org.ff4j.audit.chart.TimeSeriesChart in project ff4j by ff4j.

the class EventRepositoryElastic method getFeatureUsageHistory.

@Override
public TimeSeriesChart getFeatureUsageHistory(EventQueryDefinition query, TimeUnit units) {
    // Create the interval depending on units
    TimeSeriesChart tsc = new TimeSeriesChart(query.getFrom(), query.getTo(), units);
    // Search All events
    Iterator<Event> iterEvent = searchFeatureUsageEvents(query).iterator();
    // Dispatch events into time slots
    while (iterEvent.hasNext()) {
        tsc.addEvent(iterEvent.next());
    }
    return tsc;
}
Also used : TimeSeriesChart(org.ff4j.audit.chart.TimeSeriesChart) Event(org.ff4j.audit.Event)

Example 4 with TimeSeriesChart

use of org.ff4j.audit.chart.TimeSeriesChart in project ff4j by ff4j.

the class InMemoryEventRepository method getFeatureUsageHistory.

/**
 * {@inheritDoc}
 */
@Override
public TimeSeriesChart getFeatureUsageHistory(EventQueryDefinition query, TimeUnit units) {
    // Create the interval depending on units
    TimeSeriesChart tsc = new TimeSeriesChart(query.getFrom(), query.getTo(), units);
    for (String currentDay : getCandidateDays(query.getFrom(), query.getTo())) {
        // There are some event this day
        if (featureUsageEvents.containsKey(currentDay)) {
            for (Map.Entry<String, EventSeries> entry : featureUsageEvents.get(currentDay).entrySet()) {
                String currentFeatureName = entry.getKey();
                // Filter feature names if required
                Set<String> filteredFeatures = query.getNamesFilter();
                if (filteredFeatures == null || filteredFeatures.isEmpty() || filteredFeatures.contains(currentFeatureName)) {
                    // Loop over events
                    for (Event evt : entry.getValue()) {
                        // Between bounds (keydate not enough)
                        if (isEventInInterval(evt, query.getFrom(), query.getTo())) {
                            // Create new serie if new feature Name
                            if (!tsc.getSeries().containsKey((currentFeatureName))) {
                                tsc.createNewSerie(currentFeatureName);
                            }
                            // Match FeatureName
                            Serie<Map<String, MutableHitCount>> serie = tsc.getSeries().get(currentFeatureName);
                            // Match SlotName
                            String slotName = tsc.getSdf().format(new Date(evt.getTimestamp()));
                            // Should be always 'true' as the tsc.getsdf().format() will get a slotName.
                            if (serie.getValue().containsKey(slotName)) {
                                // Fast Increment
                                serie.getValue().get(slotName).inc();
                            }
                        }
                    }
                }
            }
        }
    }
    // Recolor series
    List<String> colors = Util.generateHSVGradient("ee1100", "442299", tsc.getSeries().size());
    int idxColor = 0;
    for (Map.Entry<String, Serie<Map<String, MutableHitCount>>> serie : tsc.getSeries().entrySet()) {
        serie.getValue().setColor(colors.get(idxColor));
        idxColor++;
    }
    return tsc;
}
Also used : TimeSeriesChart(org.ff4j.audit.chart.TimeSeriesChart) EventSeries(org.ff4j.audit.EventSeries) Date(java.util.Date) MutableHitCount(org.ff4j.audit.MutableHitCount) Event(org.ff4j.audit.Event) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Serie(org.ff4j.audit.chart.Serie)

Example 5 with TimeSeriesChart

use of org.ff4j.audit.chart.TimeSeriesChart in project ff4j by ff4j.

the class JdbcEventRepository method getFeatureUsageHistory.

/**
 * {@inheritDoc}
 */
@Override
public TimeSeriesChart getFeatureUsageHistory(EventQueryDefinition query, TimeUnit units) {
    // Create the interval depending on units
    TimeSeriesChart tsc = new TimeSeriesChart(query.getFrom(), query.getTo(), units);
    // Search All events
    Iterator<Event> iterEvent = searchFeatureUsageEvents(query).iterator();
    // Dispatch events into time slots
    while (iterEvent.hasNext()) {
        tsc.addEvent(iterEvent.next());
    }
    return tsc;
}
Also used : TimeSeriesChart(org.ff4j.audit.chart.TimeSeriesChart) Event(org.ff4j.audit.Event)

Aggregations

TimeSeriesChart (org.ff4j.audit.chart.TimeSeriesChart)11 Event (org.ff4j.audit.Event)8 EventQueryDefinition (org.ff4j.audit.EventQueryDefinition)3 Test (org.junit.Test)3 MutableHitCount (org.ff4j.audit.MutableHitCount)2 Serie (org.ff4j.audit.chart.Serie)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 EventBuilder (org.ff4j.audit.EventBuilder)1 EventSeries (org.ff4j.audit.EventSeries)1