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());
}
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;
}
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;
}
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;
}
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;
}
Aggregations