[rules-users] Drools Fusion: updating event duration

Matteo Cusmai cusmaimatteo at gmail.com
Wed Feb 22 14:52:56 EST 2012


Hi Wolfgang,
this is an extract of drl file:

declare GasObservation
    @role(event)
    @startTimestamp(timestamp)
    @expires( 10s )
    @duration(duration)
end

declare GasEvent
    @startTimestamp(timestampDate)
    @role(event)
    @duration(duration)
end

rule "gas1-event"
    no-loop
    when
        $obs    : GasObservation( $obsLocation : location, gasname == "UN
1017", value > 60 ) over window:length(1) from entry-point
lowLevelSensorStream
        not GasEvent( location geoIsWithinDistance[ 5m ] $obsLocation,
gasname == "UN 1017", this before[1s, 25s] $obs )
    then
        insert(new GasEvent( $obs, "UN 1017 value > threshold[60]",
Event.THREAT_HIGH, $obsLocation, $obs.getSensor()));
end
rule "gas1-event-update"
    no-loop
    when
        $obs    : GasObservation( $obsLocation : location, gasname == "UN
1017", value > 60 ) over window:length(1) from entry-point
lowLevelSensorStream
        $event     : GasEvent( location geoIsWithinDistance[ 5m ]
$obsLocation, gasname == "UN 1017", this before[1s, 25s] $obs )
    then
        modify($event) {
            updateDuration(),
            addObservation($obs)
        }
end

and these are abstract Observation class and abstract Event

public abstract class Observation implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 3483256523801072709L;
    private long timestamp;
    private long duration;

    private Geometry location;
    private Sensor sensor;

    public long getTimestamp() { return timestamp; }
    public void setTimestamp(long timestamp) { this.timestamp = timestamp; }

    public long getDuration() { return duration; }
    public void setDuration(long duration) { this.duration = duration; }

    public Sensor getSensor() { return sensor; }
    public void setSensor(Sensor sensor) { this.sensor = sensor; }

    public Geometry getLocation() { return location; }
    public void setLocation(Geometry location) { this.location = location; }

    /**
     * @param newTimeStamp
     * this methods allows to update the duration of event by setting the
timestamp of new observation.
     */
    public void updateDuration(long newTimeStamp) {
        setDuration(newTimeStamp - getTimestamp());
    }

    public Date getTimestampDate() {  return new Date(timestamp);  }
    public void setTimestampDate(Date timestamp) {  this.timestamp =
timestamp.getTime();  }

    public Observation(Sensor sensor, Geometry location, long timestamp) {
        this.setLocation(location);
        this.setTimestamp( timestamp );
        this.setSensor( sensor );
    }

    /**
     * @return identification by servicename:timestamp
     */
    public String getServiceIdentification() {
        return getSensor().getServiceName() + ":" + getTimestamp() ;
    }


}




public  abstract class Event implements Serializable {

   .....


    /**
     *
     */
    private static final long serialVersionUID = 1L;

    /**
     * The timestamp of event.
     */
    private long timestamp;


    /**
     * The level of threat of the event.
     */
    private int threat_level;

    /**
     * The description of event.
     */
    private String description;

    /**
     * The location of event.
     */
    private Geometry location;

    /**
     * Duration of event.
     */
    private long duration;

    /**
     * Id of sensor.
     */
    private Sensor sensor;

    /**
     * The map feature involved into Event.
     */
    private MapFeature feature;

    /**
     * link to the timestamp of parent event.
     */
    private long parent;

    private Collection<Observation> observations;
    private Collection<Event> relatedEvents;

    public abstract int getType();

    public Collection<Observation> getObservations() { return observations;
}
    public void addObservation(Observation obs) { observations.add(obs); }

    public Collection<Event> getRelatedEvents() { return relatedEvents; }
    public void addRelatedEvent(Event evnt) { relatedEvents.add(evnt); }

    public Sensor getSensor() { return sensor; }
    public void setSensor(Sensor sensorId) { this.sensor = sensorId; }

    public long getDuration() { return duration; }
    public void setDuration(long duration) { this.duration = duration; }

    public int getThreat_level() { return threat_level; }
    public void setThreat_level(int threatLevel) { threat_level =
threatLevel; }

    /**
     * @param newTimeStamp
     * this methods allows to update the duration of event by setting the
timestamp of new observation.
     */
    public void updateDuration() {
        setDuration(System.currentTimeMillis() - getTimestamp());
    }

    public long getTimestamp() { return timestamp; }
    public void setTimestamp(long timestamp) { this.timestamp = timestamp; }

    public Date getTimestampDate() {  return new Date(timestamp);  }
    public void setTimestampDate(Date timestamp) {  this.timestamp =
timestamp.getTime();  }

    public String getDescription() { return description; }
    public void setDescription(String description) { this.description =
description; }

    public Geometry getLocation() { return location; }
    public void setLocation(Geometry location) { this.location = location; }

    /*
    public int getType() { return type; }
    public void setType(int type) { this.type = type; }
    */

    public MapFeature getFeature() { return feature; }
    public void setFeature(MapFeature feature) { this.feature = feature; }

    public long getParent() { return parent; }
    public void setParent(long timestamp) { parent = timestamp; }

    /**
     * @param description        description of event
     * @param threat_level        threat level of timestamp
     * @param location                location of event
     * @param sensor                sensor related to this event
     * @param feature                map feature related to event
     */
    protected Event(String description, int threat_level, Geometry
location, Sensor sensor, MapFeature feature) {
        this.setTimestamp(System.currentTimeMillis());
        this.observations = new ArrayList<Observation>();
        this.relatedEvents = new ArrayList<Event>();
        this.setTimestamp( timestamp );
        this.setDescription( description );
        this.setThreat_level( threat_level );
        this.setLocation( location );
        this.setSensor(sensor);
        this.setFeature( feature );
    }

    public String getServiceIdentification() {
        return "events:" + this.timestamp;
    }

}


Thanks a lot in advance.

2012/2/22 Wolfgang Laun <wolfgang.laun at gmail.com>

> A minimum but complete set of *.java and *.drl files would help.
> -W
>
> 2012/2/22 Matteo Cusmai <cusmaimatteo at gmail.com>
>
>>
>> Hi all,
>> i am using Drools Fusion in multi sensor data fusion system. I have some
>> rules that generate a new event when some situations occur. But from the
>> other hand, i would like to update the event, when i understand that new
>> sensor observation is referring to the same event. I have my Event clazz
>> with duration field, i try to update it in modify clause, but i have
>> concern about it, because when i use temporal operator (such as before,
>> meets, so on) it seems that Drools manage them as event with duration null.
>> I could post the code too.
>> Bye bye,
>> Matteo.
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20120222/c9d3652c/attachment.html 


More information about the rules-users mailing list