Search in sources :

Example 11 with MutableHitCount

use of org.ff4j.audit.MutableHitCount in project ff4j by ff4j.

the class AuditBeanTest method testMutableHitCount.

@Test
public void testMutableHitCount() {
    MutableHitCount mhc = new MutableHitCount(10);
    mhc.incBy(10);
    Assert.assertEquals("20", mhc.toString());
}
Also used : MutableHitCount(org.ff4j.audit.MutableHitCount) Test(org.junit.Test)

Example 12 with MutableHitCount

use of org.ff4j.audit.MutableHitCount in project ff4j by ff4j.

the class AuditBeanTest method testTimeSerieChart.

@Test
public void testTimeSerieChart() {
    long top = System.currentTimeMillis();
    TimeSeriesChart t1 = new TimeSeriesChart(top - 100000, top + 100000, TimeUnit.MINUTES);
    new TimeSeriesChart(top - 100000, top + 100000, TimeUnit.HOURS);
    new TimeSeriesChart(top - 100000, top + 100000, TimeUnit.DAYS);
    new TimeSeriesChart(top - 100000, top + 100000, TimeUnit.SECONDS);
    t1.addEvent(new EventBuilder().name("f1").build());
    t1.addEvent(new EventBuilder().name("f2").build());
    Assert.assertNotNull(t1.getSdf());
    Assert.assertNotNull(t1.toString());
    TimeSeriesChart tsc1 = new TimeSeriesChart();
    tsc1.setSdf(new SimpleDateFormat("yyyy"));
    tsc1.setTimeSlots(new ArrayList<String>());
    tsc1.setSeries(new HashMap<String, Serie<Map<String, MutableHitCount>>>());
    Assert.assertNotNull(tsc1);
}
Also used : EventBuilder(org.ff4j.audit.EventBuilder) TimeSeriesChart(org.ff4j.audit.chart.TimeSeriesChart) SimpleDateFormat(java.text.SimpleDateFormat) Serie(org.ff4j.audit.chart.Serie) MutableHitCount(org.ff4j.audit.MutableHitCount) Test(org.junit.Test)

Example 13 with MutableHitCount

use of org.ff4j.audit.MutableHitCount in project ff4j by ff4j.

the class EventRepositorySpringJdbc method computeHitCount.

/**
 * Compute over a column.
 *
 * @param query
 *      current query definition
 * @param colName
 *      column name
 * @return
 *      hit count for this value.
 */
private Map<String, MutableHitCount> computeHitCount(EventQueryDefinition query, String colName) {
    List<HitCountDto> rawResult = getJdbcTemplate().query(getQueryBuilder().getHitCount(colName), new HitCountRowMapper(colName), new Timestamp(query.getFrom()), new Timestamp(query.getTo()));
    Map<String, MutableHitCount> mapofHitCount = new HashMap<String, MutableHitCount>();
    for (HitCountDto dto : rawResult) {
        mapofHitCount.put(dto.getColumnName(), dto.getHitcount());
    }
    return mapofHitCount;
}
Also used : HitCountDto(org.ff4j.springjdbc.store.dto.HitCountDto) HashMap(java.util.HashMap) HitCountRowMapper(org.ff4j.springjdbc.store.rowmapper.HitCountRowMapper) Timestamp(java.sql.Timestamp) MutableHitCount(org.ff4j.audit.MutableHitCount)

Example 14 with MutableHitCount

use of org.ff4j.audit.MutableHitCount in project ff4j by ff4j.

the class EventRepositoryRedis method getUsageCount.

private Map<String, MutableHitCount> getUsageCount(EventQueryDefinition query, Types type) {
    Map<String, MutableHitCount> hitCount = new HashMap<>();
    // Get events from Redis between the time range.
    Set<String> events = getEventsFromRedis(query);
    // Loop through create the buckets.
    for (String event : events) {
        Event eventObject = marshallEvent(event);
        String value = getValueFromAttribute(type, eventObject);
        MutableHitCount mutableHitCount = hitCount.get(value);
        if (mutableHitCount != null) {
            mutableHitCount.inc();
        } else {
            mutableHitCount = new MutableHitCount(1);
        }
        hitCount.put(value, mutableHitCount);
    }
    return hitCount;
}
Also used : HashMap(java.util.HashMap) Event(org.ff4j.audit.Event) MutableHitCount(org.ff4j.audit.MutableHitCount)

Example 15 with MutableHitCount

use of org.ff4j.audit.MutableHitCount in project ff4j by ff4j.

the class AbstractEventRepository method getFeatureUsageTotalHitCount.

/**
 * {@inheritDoc}
 */
@Override
public int getFeatureUsageTotalHitCount(EventQueryDefinition q) {
    Map<String, MutableHitCount> hitRatio = getFeatureUsageHitCount(q);
    int total = 0;
    if (hitRatio != null) {
        for (MutableHitCount hc : hitRatio.values()) {
            total += hc.get();
        }
    }
    return total;
}
Also used : MutableHitCount(org.ff4j.audit.MutableHitCount)

Aggregations

MutableHitCount (org.ff4j.audit.MutableHitCount)27 Event (org.ff4j.audit.Event)15 HashMap (java.util.HashMap)14 Test (org.junit.Test)10 EventQueryDefinition (org.ff4j.audit.EventQueryDefinition)8 ResultSet (com.datastax.driver.core.ResultSet)4 Row (com.datastax.driver.core.Row)4 JestResult (io.searchbox.client.JestResult)4 Map (java.util.Map)3 Timestamp (java.sql.Timestamp)2 Date (java.util.Date)2 TreeMap (java.util.TreeMap)2 Serie (org.ff4j.audit.chart.Serie)2 TimeSeriesChart (org.ff4j.audit.chart.TimeSeriesChart)2 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 SimpleDateFormat (java.text.SimpleDateFormat)1