Package org.jboss.bpm.monitor.model.metric

Examples of org.jboss.bpm.monitor.model.metric.Average


  public static Average getInstanceAverage(List<Event> events)
  {
    assert events.size()>0 : "Empty event list";
    assert events.size()%2==0 : "Parity error: "+events.size() +" events. Every event should have closing counterpart!";

    Average stat = new Average(events.get(0).getProcessDefinitionID());

    Map<String, Long> duration = new HashMap<String,Long>(events.size()/2);
    for(Event e : events)
    {
      String processInstance = e.getProcessInstanceID();
      Long l0 = duration.get(processInstance);
      if(l0!=null)
      {
        long l1 = e.getTimestamp();
        if(l0<l1)
          duration.put(processInstance, (l1-l0));   // not necessarily in order
        else
          duration.put(processInstance, (l0-l1));
      }
      else
      {
        duration.put(processInstance, e.getTimestamp());
      }
    }

    long sum = 0;
    for(String processInstance : duration.keySet())
    {
      long l3 = duration.get(processInstance);
      if(stat.getMin()==-1) // first iteration
        stat.setMin(l3);
      else if(l3<stat.getMin())
        stat.setMin(l3);
      else if(l3>stat.getMax())
        stat.setMax(l3);

      sum+=l3;
    }

    stat.setAvg(sum/duration.entrySet().size());

    return stat;
  }
View Full Code Here


  public static Average getActivityAverage(List<Event> events, String activityDefinition)
  {
    assert events.size()>0 : "Empty event list";
    assert events.size()%2==0 : "Parity error: "+events.size() +" events. Every event should have closing counterpart!";

    Average stat = new Average(activityDefinition);

    Map<String, Long> in = new HashMap<String,Long>(events.size()/2);
    List<Long> out = new ArrayList<Long>();
    for(Event e : events)
    {
      String activity = e.getActivityDefinitionID();

      if(!activity.equals(activityDefinition)) // skip non related events
        continue;
     
      Long l0 = in.get(activity);
      if(l0!=null)
      {
        long l1 = e.getTimestamp();
        if(l0<l1)
          out.add(l1-l0);   // not necessarily in order
        else
          out.add(l0-l1);
      }
      else
      {
        in.put(activity, e.getTimestamp());
      }
    }

    long sum = 0;
    for(Long l3: out)
    {     
      if(stat.getMin()==-1) // first iteration
      {
        stat.setMin(l3);
        stat.setMax(l3);
      }
      else if(l3<stat.getMin())
        stat.setMin(l3);
      else if(l3>stat.getMax())
        stat.setMax(l3);

      sum+=l3;
    }

    stat.setAvg(sum/out.size());

    return stat;
  }
View Full Code Here

TOP

Related Classes of org.jboss.bpm.monitor.model.metric.Average

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.