Categories inside categories

Hi there,

We came to a problem when we need to find all events for a given device, and for all devices in general.

Our current EventStore structure for Device is:

device-id

for events we’re thinking to use

device-id-event-eventTypeId

We need to

1.get exact events by event type and deviceId( fromStream("device-id-event-eventTypeId")?),

2.get all events for exact device( fromCategory(“device-id-event**”**)?),

3.get all events of same type for all devices(Don’t know how),

4.get all events from all devices(Don’t know how).

Any better/other/best ideas?

Thanks.

Karolis.

Assuming you have streams like this:

Stream: device-id
Events: eventTypeA
             eventTypeB
             eventTypeB
             eventTypeA

You can use the following:

1. get exact events by event type and deviceId:

fromStream(‘device-id’)
  .when({
    eventTypeA: function(state, event) { },
    eventTypeB: function(state, event) { }
  })

2. get all events for exact device

fromStream(‘device-id’)
  //Whatever

3. get all events of same type for all devices

fromCategory(‘device’)
  .when({
    eventTypeA: function(state, event) { }
  })

4. get all events from all devices

fromCategory(‘device’)
  .when({
    $any: function(state, event) { }
  })

Hope this helps,

James

Thanks for swift reply,

Each device has more information than it’s events(logs*) like readout data, configuration changes and so on, so number 4 would fail.

__*__Events in my scenario is like a log book. Maybe it will be clearer :slight_smile: event == log

I’m thinking about making stream log-logTypeId and run a projection to link those to device-id-log-logTypeId, in that case it would be available to do :

1 get exact log by event type and deviceId: fromStream(“device-id-log-logTypeId”)

2 get all logs for given device - fromCategory(“device-id-log”)

3 get all logs of same type for all devices - fromStream(“log-logTypeId”),

4 get all logs for all devices - fromCategory(“log”)

Is it a better option? And how to get 4th in Yours example

BTW I saw that you can read category as a single stream in .NET API ($ce- )so i’m thinking of running a projection for all single device data and all it’s events. Can i write a projection using fromStreams(["$ce- ",“device-id” ])

Thanks in advance

2014 m. birželis 26 d., ketvirtadienis 15:49:40 UTC+3, James Nugent rašė:

Without some concrete examples it’s a bit hard to tell what would actually be required.

An important think to note is that subcategories are NOT currently supported. Either the first or last “-“ (or other delimiter as defined) are matched as the category name.

If you can post some more specific examples we might be able to give some more guidance.

Cheers,

James

I already found that only last - delimiter works for categories.

My devices are electricity meters, they events in device-id are like : ipChanged, requestForRead, electricityConsumtion and so on.

Each meter has ~15 EventLogs like: PowerOut, ClockChangetLog, OverVoltageLog, ParametrisationLog…

Questions for system are these:

Give me specific log for specific device;

Subscribe me to PowerOut event from all devices,

Give me last 100 EventLogs events from all system

Give me all EventLogs events for given device

Is it any clearer?

2014 m. birželis 26 d., ketvirtadienis 17:12:42 UTC+3, James Nugent rašė:

Are all events in OverVoltageLog the same type or are there many event types per conceptual log you describe?

Same type per log

2014 birž. 26 17:33 “Greg Young” [email protected] rašė:

So you have a stream per device.

/streams/device-12345

Give me specific log for specific device;

A small projection:

fromCategory(‘device’).

when({

$any : function(s,e) {linkTo(e.data.deviceName + ‘-’ + e.type)}

})

this will create streams

/stream/device-12345-eventType

eg your different logs

Subscribe me to PowerOut event from all devices,

There is an internal projection that does this (by event type)

/streams/$et-PowerOut

Give me last 100 EventLogs events from all system

/streams/$all

Give me all EventLogs events for given device

/streams/device-12345

I think this covers them

Everything looks good except the last one :
Give me last 100 EventLogs events from all system

/streams/$all

There are more events in my system beside EventLogs, so this projection would show all data, not only EventLogs.

Maybe store EventLog types outside ES?

Thanks for “/streams/$et-PowerOut”, I’ve totally forgot that one. :slight_smile:

2014 m. birželis 26 d., ketvirtadienis 17:46:01 UTC+3, Greg Young rašė:

If EventLog are all the same type of event the stream $et-EventLog will work as well