<commit_before>package com.eigengo.lift.exercise.classifiers.model

import akka.actor.ActorLogging
import akka.stream.scaladsl._
import com.eigengo.lift.exercise.classifiers.ExerciseModel.Query
import com.eigengo.lift.exercise.classifiers.workflows.{ClassificationAssertions, GestureWorkflows}
import com.eigengo.lift.exercise._
import com.eigengo.lift.exercise.classifiers.ExerciseModel

/**
 * Gesture classification model.
 *
 * Essentially, we view our model traces as being streams here. As a result, all queries are evaluated (on the actual
 * stream) from the time point they are received by the model.
 */
abstract class StandardExerciseModel(sessionProps: SessionProperties, toWatch: Set[Query] = Set.empty)
  extends ExerciseModel("tap", sessionProps, toWatch)
  with StandardEvaluation
  with ActorLogging {

  this: SMTInterface =>

  import ClassificationAssertions._
  import FlowGraphImplicits._

  // Workflow for recognising 'tap' gestures
  object Tap extends GestureWorkflows("tap", context.system.settings.config)

  /**
   * Monitor wrist sensor and add in tap gesture detection.
   */
  val workflow = {
    val in = UndefinedSource[SensorNetValue]
    val out = UndefinedSink[BindToSensors]

    PartialFlowGraph { implicit builder =>
      val classifier = Tap.identifyEvent
      val split = Broadcast[SensorNetValue]
      val merge = Zip[Set[Fact], SensorNetValue]

      in ~> split

      split ~> Flow[SensorNetValue].map(_.toMap(SensorDataSourceLocationWrist).asInstanceOf[AccelerometerValue]).via(classifier.map(_.toSet)) ~> merge.left

      split ~> Flow[SensorNetValue] ~> merge.right

      merge.out ~> Flow[(Set[Fact], SensorNetValue)].map { case (facts, data) => BindToSensors(facts, Set(), Set(), Set(), Set(), data) } ~> out
    }.toFlow(in, out)
  }

}
<commit_msg>Minor simplification<commit_after>package com.eigengo.lift.exercise.classifiers.model

import akka.actor.ActorLogging
import akka.stream.OverflowStrategy
import akka.stream.scaladsl._
import com.eigengo.lift.exercise.classifiers.ExerciseModel.Query
import com.eigengo.lift.exercise.classifiers.workflows.{ClassificationAssertions, GestureWorkflows}
import com.eigengo.lift.exercise._
import com.eigengo.lift.exercise.classifiers.ExerciseModel

/**
 * Gesture classification model.
 *
 * Essentially, we view our model traces as being streams here. As a result, all queries are evaluated (on the actual
 * stream) from the time point they are received by the model.
 */
abstract class StandardExerciseModel(sessionProps: SessionProperties, toWatch: Set[Query] = Set.empty)
  extends ExerciseModel("tap", sessionProps, toWatch)
  with StandardEvaluation
  with ActorLogging {

  this: SMTInterface =>

  import ClassificationAssertions._
  import FlowGraphImplicits._

  // Workflow for recognising 'tap' gestures..
  object Tap extends GestureWorkflows("tap", context.system.settings.config)
  // ..that are detected via wrist sensors
  val tapSensor = SensorDataSourceLocationWrist

  /**
   * Monitor wrist sensor and add in tap gesture detection.
   */
  val workflow = {
    val in = UndefinedSource[SensorNetValue]
    val out = UndefinedSink[BindToSensors]

    PartialFlowGraph { implicit builder =>
      val classifier = Tap.identifyEvent
      val split = Broadcast[SensorNetValue]
      val merge = Zip[Set[Fact], SensorNetValue]

      in ~> split

      split ~> Flow[SensorNetValue].map(_.toMap(tapSensor).asInstanceOf[AccelerometerValue]).via(classifier.map(_.toSet)) ~> merge.left

      split ~> merge.right

      merge.out ~> Flow[(Set[Fact], SensorNetValue)].map { case (facts, data) => BindToSensors(facts, Set(), Set(), Set(), Set(), data) } ~> out
    }.toFlow(in, out)
  }

}

{'fraction_non_alphanumeric': 0.10334592552617378, 'fraction_numerical': 0.0, 'mean_word_length': 4.427525622254758, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '1799201', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1088, 'n_words': 277}