src/lib/session.js
// assign a session to an event
assign a session to an event
assign a session to an event
assign({ type, id, time, gap }) {
    let session = this.sessions.getIn([type, id]);
    if (!session || time - session.get('end') > gap) {
      session = Map({
        type: type,
        id: id,
        updated: now(),
        start: time,
        end: time + gap,
        speed: Map({
          per_minute: new Speed(60, 15).hit(time),
          per_hour: new Speed(3600, 24).hit(time),
        }),
      });
    } else {
      session = session
        .set('updated', now())
        .update('start', start => Math.min(start, time))
        .update('end', end => Math.max(end, time))
        .updateIn(['speed', 'per_minute'], speed => speed.hit(time))
        .updateIn(['speed', 'per_hour'], speed => speed.hit(time));
    }
    this.save(session);
    this.index(session);
    return session;
  }
assign ( { type , id , time , gap } ) { let session = this . sessions . getIn ( [ type , id ] ) ; if ( ! session || time - session . get ( 'end' ) > gap ) { session = Map ( { type : type , id : id , updated : now ( ) , start : time , end : time + gap , speed : Map ( { per_minute : new Speed ( 60 , 15 ) . hit ( time ) , per_hour : new Speed ( 3600 , 24 ) . hit ( time ) , } ) , } ) ; } else { session = session . set ( 'updated' , now ( ) ) . update ( 'start' , start => Math . min ( start , time ) ) . update ( 'end' , end => Math . max ( end , time ) ) . updateIn ( [ 'speed' , 'per_minute' ] , speed => speed . hit ( time ) ) . updateIn ( [ 'speed' , 'per_hour' ] , speed => speed . hit ( time ) ) ; } this . save ( session ) ; this . index ( session ) ; return session ; }
assign a session to an event
assign a session to an event