event projections - referral example. ideas appreciated

Hey guys.

To get straight to the chase. Would people be able to give me some ideas for good queries to run which demonstrate the power of event sourcing.

I have a Referral domain ( if you want to call it that ) in which referrers refer friends to jobs or departments which are then reviewed by recruiters.

So some of the Events are basically

ReferralSubmitted - ( aka the making of the referral )

ReferralAccepted - the referree accepted the referral

ReferralDecisionMade - Recruiter made decision ( basically yes this is good or bad candidate, allows recruiters to invite that person to apply for specific job. )

Using the following I transform it into per referrer streams ( which I could probably do for recruiters as well )

fromCategory(“Referral”)

.foreachStream()

.when(

{

ReferralSubmitted: function(state, event) {

linkTo(event.body.referrer.referrerId;, event);

},

ReferralAccepted: function(state, event) {

linkTo(event.body.referrer.referrerId;, event);

},

ReferralDecisionMade: function(state, event) {

linkTo(event.body.referrerInfo.referrerId, event);

}

}

);

``

And now I would like to be able to query that.

Some of the thoughts I have had are

  1. Referrals contain 2 sets of text, one sent to the recruiter and the other to the referree. Create streams based on words within those text to try find common wording etc.

  2. Does a positive referral decision mean that a referrer will refer again within 24 hours? 48 hours? etc?

Any other ideas or suggestions would be really appreciated. Sadly this is a really poor area of my skill set. Coming up with questions/problems to solve.

Thanks

Alistair.

ps.

We are implemented gamification of our referral program which I threw together view easily using the following projections. One issue I did seem to encounter was that I couldn’t emit an event into the same stream as I was projecting. Is that actually possible?

Also does event.streamId refer to the origin stream or the linked stream for linked events?

fromCategory(“Referrer”)

.foreachStream()

.when(

{

$init: function() {

return {

referralCount: 0,

};

},

ReferralSubmitted: function(state, event) {

state.referralCount++;

        // make a new stream as emitting to event.streamId didn't seem to work.

var streamId = event.streamId.replace(“Referrer”, “ReferrerBadges”);

if (state.referralCount === 1) {

emit(streamId, “BadgeAwarded”, { name: “Lively Bee”, points: 10 } );

}

if (state.referralCount === 5) {

emit(streamId, “BadgeAwarded”, { name: “Active Bee”, points: 25 } );

}

if (state.referralCount === 15) {

emit(streamId, “BadgeAwarded”, { name: “Busy Bee”, points: 50 } );

}

if (state.referralCount === 50) {

emit(streamId, “BadgeAwarded”, { name: “Super Bee”, points: 100 } );

}

return state;

}

});

fromCategory(“ReferrerBadges”)

.foreachStream()

.when(

{

$init: function() {

return {

totalPoints: 0,

badges: []

};

},

BadgeAwarded: function(state, event) {

state.badges.push(event.body.name);

state.totalPoints = state.totalPoints + event.body.points;

return state;

}

});

``

These are just basic indexes (any system could do them really).

For me the place where the querying model shines is when you need to correlate together multiple events

e.g.

this happens

then within 15 minutes Y happens

then within 45 minutes X and Z happen