<commit_before>package controllers

import (
	"io"
	"log"
	"time"

	r "github.com/dancannon/gorethink"
	"github.com/david-torres/duelyst-casual/models"
	"golang.org/x/net/websocket"
)

// Socket handles the websocket
func Socket(session *r.Session) websocket.Handler {
	return websocket.Handler(func(ws *websocket.Conn) {
		// Initial socket connection, get changefeed
		games, _ := r.Table("games").Filter(
			r.Row.Field("accepted").Eq(false)).Changes(r.ChangesOpts{IncludeInitial: true}).Run(session)

		// write changes to socket
		go func() {
			for {
				var changefeed interface{}

				for games.Next(&changefeed) {
					err := websocket.JSON.Send(ws, changefeed)
					if err != nil {<commit_msg>add 30m decay<commit_after>package controllers

import (
	"io"
	"log"
	"time"

	r "github.com/dancannon/gorethink"
	"github.com/david-torres/duelyst-casual/models"
	"golang.org/x/net/websocket"
)

// Socket handles the websocket
func Socket(session *r.Session) websocket.Handler {
	return websocket.Handler(func(ws *websocket.Conn) {
		// Initial socket connection, get changefeed

		games, _ := r.Table("games").
			// find games that are +/-30m old (unfortunately now() doesn't update automatically its a point in time from when this changefeed is created)
			Filter(r.Row.Field("timestamp").During(r.EpochTime(r.Now().ToEpochTime().Sub(1800)), r.EpochTime(r.Now().ToEpochTime().Add(1800)))).
			// find games that have not been accepted
			Filter(r.Row.Field("accepted").Eq(false)).
			Changes(r.ChangesOpts{IncludeInitial: true}).
			Run(session)

		// write changes to socket
		go func() {
			for {
				var changefeed interface{}

				for games.Next(&changefeed) {
					err := websocket.JSON.Send(ws, changefeed)
					if err != nil {
{'fraction_non_alphanumeric': 0.14417001723147616, 'fraction_numerical': 0.0068925904652498565, 'mean_word_length': 3.9488636363636362, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5866412', 'n_tokens_mistral': 670, 'n_tokens_neox': 583, 'n_words': 131}