Search in sources :

Example 1 with BarChart

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

the class OperationsController method graphFeatureUsageHitCountasJson.

/**
 * Generation of JSON to render Features.
 *
 * @param req
 *      current request
 * @param res
 *      current response
 * @throws IOException
 */
private void graphFeatureUsageHitCountasJson(HttpServletRequest req, HttpServletResponse res) throws IOException {
    res.setContentType(CONTENT_TYPE_JSON);
    String[] pathParts = req.getPathInfo().split("/");
    EventQueryDefinition query = parseQuery(req);
    if (pathParts.length > 3) {
        String graphName = pathParts[3];
        if (GRAPH_PIE_HITRATIO.equalsIgnoreCase(graphName)) {
            PieChart pc = getFf4j().getEventRepository().getFeatureUsagePieChart(query);
            res.getWriter().println(pc.toJson());
        } else if (GRAPH_BAR_HITRATIO.equalsIgnoreCase(graphName)) {
            BarChart bc = getFf4j().getEventRepository().getFeatureUsageBarChart(query);
            res.getWriter().println(bc.toJson());
        } else if (GRAPH_PIE_HOST.equalsIgnoreCase(graphName)) {
            PieChart pc = getFf4j().getEventRepository().getHostPieChart(query);
            res.getWriter().println(pc.toJson());
        } else if (GRAPH_PIE_SOURCE.equalsIgnoreCase(graphName)) {
            PieChart pc = getFf4j().getEventRepository().getSourcePieChart(query);
            res.getWriter().println(pc.toJson());
        } else if (GRAPH_PIE_USER.equalsIgnoreCase(graphName)) {
            PieChart pc = getFf4j().getEventRepository().getUserPieChart(query);
            res.getWriter().println(pc.toJson());
        }
    }
}
Also used : PieChart(org.ff4j.audit.chart.PieChart) EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) BarChart(org.ff4j.audit.chart.BarChart)

Example 2 with BarChart

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

the class AbstractEventRepositoryTest method testFeatureUsageBarCharts.

@Test
public void testFeatureUsageBarCharts() throws InterruptedException {
    long start = System.currentTimeMillis();
    // Create Event
    repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", EventConstants.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));
    }
    // Assert bar chart (2 bars with 8 and 8)
    EventQueryDefinition testQuery = new EventQueryDefinition(start - 10, System.currentTimeMillis() + 10);
    BarChart bChart = repo.getFeatureUsageBarChart(testQuery);
    Assert.assertEquals(2, bChart.getChartBars().size());
    Assert.assertEquals(new Integer(8), bChart.getChartBars().get(0).getValue());
    Assert.assertEquals(new Integer(8), bChart.getChartBars().get(1).getValue());
    Assert.assertNotNull(bChart.getChartBars().get(0).getColor());
    Assert.assertNotNull(bChart.getChartBars().get(1).getColor());
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) BarChart(org.ff4j.audit.chart.BarChart) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 3 with BarChart

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

the class AuditBeanTest method testBarChart.

@Test
public void testBarChart() {
    BarChart bc = new BarChart("Title");
    bc.setTitle("title2");
    Assert.assertEquals("title2", bc.getTitle());
    Serie<Integer> s1 = new Serie<Integer>("s1", 12);
    Serie<Integer> s2 = new Serie<Integer>("s2", 14);
    bc.getChartBars().add(s1);
    bc.getChartBars().add(s2);
    Assert.assertNotNull(bc.toString());
}
Also used : BarChart(org.ff4j.audit.chart.BarChart) Serie(org.ff4j.audit.chart.Serie) Test(org.junit.Test)

Example 4 with BarChart

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

the class AbstractEventRepository method renderBarChart.

/**
 * Convert hicount into pieChart.
 *
 * @param hitRatio
 *      current hist ratio
 * @return
 *      pie chart
 */
private BarChart renderBarChart(String title, Map<String, MutableHitCount> hitRatio, List<String> colors) {
    BarChart barChart = new BarChart(title);
    int idxColor = 0;
    for (String key : hitRatio.keySet()) {
        Serie<Integer> bar = new Serie<Integer>(key, new Double(hitRatio.get(key).get()).intValue(), colors.get(idxColor));
        barChart.getChartBars().add(bar);
        idxColor++;
    }
    orderBarDecrecent(barChart);
    return barChart;
}
Also used : BarChart(org.ff4j.audit.chart.BarChart) Serie(org.ff4j.audit.chart.Serie)

Example 5 with BarChart

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

the class EventRepositoryTestSupport method testFeatureUsageBarCharts.

/**
 * TDD.
 */
@Test
public void testFeatureUsageBarCharts() throws InterruptedException {
    long start = System.currentTimeMillis();
    // Given empty event repository
    // When
    repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", EventConstants.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));
    }
    // Then : Assert bar chart (2 bars with 8 and 8)
    EventQueryDefinition testQuery = new EventQueryDefinition(start - 10, System.currentTimeMillis() + 10);
    BarChart bChart = repo.getFeatureUsageBarChart(testQuery);
    Assert.assertEquals(2, bChart.getChartBars().size());
    Assert.assertEquals(new Integer(8), bChart.getChartBars().get(0).getValue());
    Assert.assertEquals(new Integer(8), bChart.getChartBars().get(1).getValue());
    Assert.assertNotNull(bChart.getChartBars().get(0).getColor());
    Assert.assertNotNull(bChart.getChartBars().get(1).getColor());
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) BarChart(org.ff4j.audit.chart.BarChart) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Aggregations

BarChart (org.ff4j.audit.chart.BarChart)5 EventQueryDefinition (org.ff4j.audit.EventQueryDefinition)3 Test (org.junit.Test)3 Event (org.ff4j.audit.Event)2 Serie (org.ff4j.audit.chart.Serie)2 PieChart (org.ff4j.audit.chart.PieChart)1