<commit_before>package actors

import actors.SessionHandler._
import akka.actor.{ ActorLogging, Actor, Props }
import controllers.Permissions
import controllers.Permissions.Role
import org.apache.commons.codec.digest.DigestUtils
import org.joda.time
import org.joda.time.{ Period, DateTime }
import play.api.Play.current
import play.api.{ Play, Configuration }

import scala.concurrent.Future
import scala.util.control.NonFatal

object SessionHandler {

  case class AuthenticationRequest(user: String, password: String)

  case class NameRequest(user: String)

  case class LogoutRequest(sessionID: String)

  case class SessionRequest(id: String)

  case class Session(id: String, user: String, role: Role)

  case class SessionValidationRequest(id: String)

  case class Valid(session: Session)

  case object Invalid

  case object OnlineUserCountRequest

  case object OnlineStudentCountRequest

  case class OnlineUserCountChange(count: Int)

  case class OnlineStudentCountChange(count: Int)

  private[SessionHandler] case object SessionTick

  def props(config: Configuration) = Props(new SessionHandler(config))
}

class SessionHandler(config: Configuration) extends Actor with ActorLogging {

  import utils.LDAPAuthentication._

  import scala.concurrent.ExecutionContext.Implicits.global
  import scala.concurrent.duration._

  var sessions: Map[Session, DateTime] = Map.empty
  var userCount = 0
  var studentCount = 0

  val DN = config.getString("lwm.bindDN").get
  val GDN = config.getString("lwm.groupDN").get
  val bindHost = config.getString("lwm.bindHost").get
  val bindPort = config.getInt("lwm.bindPort").get
  val lifetime = config.getInt("lwm.sessions.lifetime").getOrElse(8)

  context.system.scheduler.schedule(lifetime.minutes, lifetime.minutes, self, SessionHandler.SessionTick)

  def receive: Receive = {
    case OnlineStudentCountRequest ⇒ sender() ! OnlineStudentCountChange(studentCount)
    case OnlineUserCountRequest    ⇒ sender() ! OnlineUserCountChange(userCount)

    case SessionTick ⇒
      sessions = sessions.filterNot { session ⇒
        new Period(DateTime.now(), session._2).getHours > lifetime
      }
<commit_msg>fixed user counting<commit_after>package actors

import actors.SessionHandler._
import akka.actor.{ ActorLogging, Actor, Props }
import controllers.Permissions
import controllers.Permissions.Role
import org.apache.commons.codec.digest.DigestUtils
import org.joda.time
import org.joda.time.{ Period, DateTime }
import play.api.Play.current
import play.api.{ Play, Configuration }

import scala.concurrent.Future
import scala.util.control.NonFatal

object SessionHandler {

  case class AuthenticationRequest(user: String, password: String)

  case class NameRequest(user: String)

  case class LogoutRequest(sessionID: String)

  case class SessionRequest(id: String)

  case class Session(id: String, user: String, role: Role)

  case class SessionValidationRequest(id: String)

  case class Valid(session: Session)

  case object Invalid

  case object OnlineUserCountRequest

  case object OnlineStudentCountRequest

  case class OnlineUserCountChange(count: Int)

  case class OnlineStudentCountChange(count: Int)

  private[SessionHandler] case object SessionTick

  def props(config: Configuration) = Props(new SessionHandler(config))
}

class SessionHandler(config: Configuration) extends Actor with ActorLogging {

  import utils.LDAPAuthentication._

  import scala.concurrent.ExecutionContext.Implicits.global
  import scala.concurrent.duration._

  var sessions: Map[Session, DateTime] = Map.empty
  var userCount = 0
  var studentCount = 0

  val DN = config.getString("lwm.bindDN").get
  val GDN = config.getString("lwm.groupDN").get
  val bindHost = config.getString("lwm.bindHost").get
  val bindPort = config.getInt("lwm.bindPort").get
  val lifetime = config.getInt("lwm.sessions.lifetime").getOrElse(8)

  context.system.scheduler.schedule(lifetime.minutes, lifetime.minutes, self, SessionHandler.SessionTick)

  def receive: Receive = {
    case OnlineStudentCountRequest ⇒ sender() ! OnlineStudentCountChange(studentCount)
    case OnlineUserCountRequest    ⇒ sender() ! OnlineUserCountChange(userCount)

    case SessionTick ⇒
      sessions.filter { session ⇒
        if(session._1.role.contains(Permissions.ScheduleAssociationModification)){
          userCount = userCount - 1
        }else{
          studentCount = studentCount -1
        }
        new Period(DateTime.now(), session._2).getHours > lifetime
      }
      sessions = sessions.filterNot { session ⇒
        new Period(DateTime.now(), session._2).getHours > lifetime
      }

{'fraction_non_alphanumeric': 0.08837510803802939, 'fraction_numerical': 0.0025929127052722557, 'mean_word_length': 4.652014652014652, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '1661580', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1282, 'n_words': 337}