use of org.ff4j.audit.EventSeries 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.EventSeries in project ff4j by ff4j.
the class JdbcEventRepository method searchEvents.
/**
* {@inheritDoc}
*/
private EventSeries searchEvents(String sqlQuery, long from, long to) {
Connection sqlConn = null;
PreparedStatement ps = null;
ResultSet rs = null;
EventSeries es = new EventSeries();
try {
sqlConn = getDataSource().getConnection();
ps = sqlConn.prepareStatement(sqlQuery);
ps.setTimestamp(1, new Timestamp(from));
ps.setTimestamp(2, new Timestamp(to));
rs = ps.executeQuery();
while (rs.next()) {
es.add(EVENT_MAPPER.mapEvent(rs));
}
} catch (SQLException sqlEX) {
throw new IllegalStateException("CANNOT_READ_AUDITTABLE", sqlEX);
} finally {
closeResultSet(rs);
closeStatement(ps);
closeConnection(sqlConn);
}
return es;
}
use of org.ff4j.audit.EventSeries in project ff4j by ff4j.
the class AbstractEventRepositoryTest method testSearchFeatureUsageEvents.
@Test
public void testSearchFeatureUsageEvents() throws InterruptedException {
long start = System.currentTimeMillis();
repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CREATE));
for (int i = 0; i < 8; i++) {
Thread.sleep(100);
repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OK));
repo.saveEvent(new Event(SOURCE_WEB, TARGET_FEATURE, "f2", ACTION_CHECK_OK));
}
Thread.sleep(100);
// Then
EventQueryDefinition testQuery = new EventQueryDefinition(start - 20, System.currentTimeMillis());
EventSeries es = repo.searchFeatureUsageEvents(testQuery);
Assert.assertEquals(16, es.size());
// Then
}
use of org.ff4j.audit.EventSeries in project ff4j by ff4j.
the class EventRepositoryTestSupport method testSearchFeatureUsageEvents.
@Test
public void testSearchFeatureUsageEvents() throws InterruptedException {
long start = System.currentTimeMillis();
repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CREATE));
for (int i = 0; i < 8; i++) {
Thread.sleep(100);
repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OK));
repo.saveEvent(new Event(SOURCE_WEB, TARGET_FEATURE, "f2", ACTION_CHECK_OK));
}
Thread.sleep(100);
// Then
EventQueryDefinition testQuery = new EventQueryDefinition(start - 20, System.currentTimeMillis());
EventSeries es = repo.searchFeatureUsageEvents(testQuery);
Assert.assertEquals(16, es.size());
// Then
}
use of org.ff4j.audit.EventSeries in project ff4j by ff4j.
the class EventRepositoryTestSupport method testLimitEventSeries.
/**
* TDD.
*/
@Test
public void testLimitEventSeries() throws InterruptedException {
EventSeries es = new EventSeries(5);
for (int i = 0; i < 10; i++) {
Thread.sleep(10);
es.add(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CREATE));
}
Assert.assertEquals(5, es.size());
}
Aggregations