<commit_before>// Tideland Go Cells - Example - Behaviors - Working on individual Coins
//
// Copyright (C) 2010-2017 <NAME> / Tideland / Oldenburg / Germany
//
// All rights reserved. Use of this source code is governed
// by the new BSD license.

package behaviors

//--------------------
// IMPORTS
//--------------------

import (
	"time"

	"github.com/tideland/golib/identifier"

	"github.com/tideland/gocells/behaviors"
	"github.com/tideland/gocells/cells"
)

//--------------------
// BEHAVIORS
//--------------------

// MakeRouter returns a behavior routing individual coin events to
// their subscribed spown points.
func MakeRouter() cells.Behavior {
	router := func(emitterID, subscriberID string, event cells.Event) (bool, error) {
		return event.Topic() == subscriberID, nil
	}
	return behaviors.NewRouterBehavior(router)
}

// MakeCoinRateWindow returns a rate window behavior for one coin
// looking for raises.
func MakeCoinRateWindow() cells.Behavior {
	current := 0.0
	criterion := func(event cells.Event) (bool, error) {
		var coin Coin
		if err := event.Payload().Unmarshal(&coin); err != nil {
			return false, err
		}
		raised := coin.PriceBTC > current
		current = coin.PriceBTC
		return raised, nil
	}
	return behaviors.NewRateWindowBehavior(criterion, 3, time.Minute)
}

//--------------------
// ENVIRONMENT
//--------------------
<commit_msg>Testing with coin rate window<commit_after>// Tideland Go Cells - Example - Behaviors - Working on individual Coins
//
// Copyright (C) 2010-2017 <NAME> / Tideland / Oldenburg / Germany
//
// All rights reserved. Use of this source code is governed
// by the new BSD license.

package behaviors

//--------------------
// IMPORTS
//--------------------

import (
	"time"

	"github.com/tideland/golib/identifier"

	"github.com/tideland/gocells/behaviors"
	"github.com/tideland/gocells/cells"
)

//--------------------
// BEHAVIORS
//--------------------

// MakeRouter returns a behavior routing individual coin events to
// their subscribed spown points.
func MakeRouter() cells.Behavior {
	router := func(emitterID, subscriberID string, event cells.Event) (bool, error) {
		return event.Topic() == subscriberID, nil
	}
	return behaviors.NewRouterBehavior(router)
}

// MakeCoinRateWindow returns a rate window behavior for one coin
// looking for raises.
func MakeCoinRateWindow() cells.Behavior {
	current := 0.0
	criterion := func(event cells.Event) (bool, error) {
		var coin Coin
		if err := event.Payload().Unmarshal(&coin); err != nil {
			return false, err
		}
		raised := coin.PriceBTC >= current
		current = coin.PriceBTC
		return raised, nil
	}
	return behaviors.NewRateWindowBehavior(criterion, 3, time.Minute)
}

//--------------------
// ENVIRONMENT
//--------------------

{'fraction_non_alphanumeric': 0.19622778382299602, 'fraction_numerical': 0.00797968806673921, 'mean_word_length': 2.4867256637168142, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3796005', 'n_tokens_mistral': 873, 'n_tokens_neox': 812, 'n_words': 238}