<commit_before>package com.ubirch.avatar.util.model

import com.ubirch.avatar.config.Const
import com.ubirch.avatar.model.device.{DeviceType, DeviceTypeDefaults, DeviceTypeName}
import com.ubirch.util.json.Json4sUtil
import org.json4s.JValue

import scala.collection.mutable.ListBuffer

/**
  * author: cvandrei
  * since: 2016-11-11
  */
object DeviceTypeUtil {

  val defaultKey = "defaultDeviceType"

  val defaultDeviceTypesSet: Set[String] = Set(Const.LIGHTSSENSOR, Const.LIGHTSLAMP, Const.ENVIRONMENTSENSOR, Const.UNKNOWN_DEVICE, Const.TRACKLESENSOR
  )

  def dataSeries(prefix: String = defaultKey,
                 elementCount: Int = 5,
                 startIndex: Int = 0
                ): Set[DeviceType] = {

    val series: ListBuffer[DeviceType] = ListBuffer()

    for (i <- startIndex until startIndex + elementCount) {
      val deviceType = defaultDeviceType(s"$prefix$i")
      series += deviceType
    }

    series.toSet

  }

  def defaultDeviceTypes: Set[DeviceType] = defaultDeviceTypesSet map defaultDeviceType

  def defaultDeviceType(deviceType: String = defaultKey): DeviceType = {
    DeviceType(
      key = deviceType,
      name = defaultTranslation(deviceType),
      icon = defaultIcon(deviceType),
      transformerQueue = Some(s"ubirch.transformer.${deviceType.toLowerCase.trim}"),
      displayKeys = Some(defaultDisplayKeys(deviceType)),
      defaults = DeviceTypeDefaults(
        defaultProps(deviceType),
        defaultConf(deviceType),
        defaultTags(deviceType)
      )
    )
  }

  def defaultTranslation(deviceType: String): DeviceTypeName = {

    deviceType match {

      case Const.LIGHTSSENSOR => DeviceTypeName("Lichtsensor", "Light Sensor")

      case Const.LIGHTSLAMP => DeviceTypeName("Lampe", "Lamp")

      case Const.ENVIRONMENTSENSOR => DeviceTypeName("Umweltsensor", "Environment Sensor")

      case Const.UNKNOWN_DEVICE => DeviceTypeName("unbekannter Geräte Typ", "unknown device type")

      case _ => DeviceTypeName("Unbekanntes Gerät", "Unknown Device")

    }

  }

  def defaultIcon(deviceType: String): String = {

    deviceType match {

      case Const.LIGHTSSENSOR => "ion-ios-sunny"
      case Const.LIGHTSLAMP => "ion-ios-lightbulb"
      case Const.ENVIRONMENTSENSOR => "ion-speedometer"
      case Const.UNKNOWN_DEVICE => "ion-radio-waves"
      case _ => "ion-radio-waves"

    }

  }

  def defaultProps(deviceTypeKey: String): JValue = {

    val props = deviceTypeKey match {

      case Const.LIGHTSLAMP => Map.empty

      case Const.LIGHTSSENSOR => Map(Const.STOREDATA -> Const.BOOL_TRUE)

      case Const.ENVIRONMENTSENSOR =>
        Map(
          Const.STOREDATA -> Const.BOOL_TRUE,
          Const.BLOCKC -> Const.BOOL_TRUE
        )

      case Const.UNKNOWN_DEVICE => Map.empty

      case _ => Map.empty

    }

    Json4sUtil.any2jvalue(props).get

  }

  def defaultDisplayKeys(deviceTypeKey: String): Array[String] = {
    deviceTypeKey match {
      case Const.ENVIRONMENTSENSOR =>
        Array("temperature", "presure", "humidity", "batteryLevel")
      case Const.LIGHTSSENSOR =>
        Array("r", "g", "b", "ba")
      case _ => Array()
    }
  }

  /**
    * The following fields can be included in default configs:
    *
    * * s = sensor sensitivity
    * * ir = infrared filter
    * * bf = 0/1
    * * i = update interval
    *
    * @param deviceType device type the default config applies to
    * @return default config for the given device type<commit_msg>added deviceType defaults for trackle<commit_after>package com.ubirch.avatar.util.model

import com.ubirch.avatar.config.Const
import com.ubirch.avatar.model.device.{DeviceType, DeviceTypeDefaults, DeviceTypeName}
import com.ubirch.util.json.Json4sUtil
import org.json4s.JValue

import scala.collection.mutable.ListBuffer

/**
  * author: cvandrei
  * since: 2016-11-11
  */
object DeviceTypeUtil {

  val defaultKey = "defaultDeviceType"

  val defaultDeviceTypesSet: Set[String] = Set(Const.LIGHTSSENSOR, Const.LIGHTSLAMP, Const.ENVIRONMENTSENSOR, Const.UNKNOWN_DEVICE, Const.TRACKLESENSOR
  )

  def dataSeries(prefix: String = defaultKey,
                 elementCount: Int = 5,
                 startIndex: Int = 0
                ): Set[DeviceType] = {

    val series: ListBuffer[DeviceType] = ListBuffer()

    for (i <- startIndex until startIndex + elementCount) {
      val deviceType = defaultDeviceType(s"$prefix$i")
      series += deviceType
    }

    series.toSet

  }

  def defaultDeviceTypes: Set[DeviceType] = defaultDeviceTypesSet map defaultDeviceType

  def defaultDeviceType(deviceType: String = defaultKey): DeviceType = {
    DeviceType(
      key = deviceType,
      name = defaultTranslation(deviceType),
      icon = defaultIcon(deviceType),
      transformerQueue = Some(s"ubirch.transformer.${deviceType.toLowerCase.trim}"),
      displayKeys = Some(defaultDisplayKeys(deviceType)),
      defaults = DeviceTypeDefaults(
        defaultProps(deviceType),
        defaultConf(deviceType),
        defaultTags(deviceType)
      )
    )
  }

  def defaultTranslation(deviceType: String): DeviceTypeName = {

    deviceType match {

      case Const.LIGHTSSENSOR => DeviceTypeName("Lichtsensor", "Light Sensor")

      case Const.LIGHTSLAMP => DeviceTypeName("Lampe", "Lamp")

      case Const.ENVIRONMENTSENSOR => DeviceTypeName("Umweltsensor", "Environment Sensor")

      case Const.UNKNOWN_DEVICE => DeviceTypeName("unbekannter Geräte Typ", "unknown device type")

      case _ => DeviceTypeName("Unbekanntes Gerät", "Unknown Device")

    }

  }

  def defaultIcon(deviceType: String): String = {

    deviceType match {

      case Const.LIGHTSSENSOR => "ion-ios-sunny"
      case Const.LIGHTSLAMP => "ion-ios-lightbulb"
      case Const.ENVIRONMENTSENSOR => "ion-speedometer"
      case Const.UNKNOWN_DEVICE => "ion-radio-waves"
      case _ => "ion-radio-waves"

    }

  }

  def defaultProps(deviceTypeKey: String): JValue = {

    val props = deviceTypeKey match {

      case Const.LIGHTSLAMP => Map.empty

      case Const.LIGHTSSENSOR => Map(Const.STOREDATA -> Const.BOOL_TRUE)

      case Const.ENVIRONMENTSENSOR =>
        Map(
          Const.STOREDATA -> Const.BOOL_TRUE,
          Const.BLOCKC -> Const.BOOL_TRUE
        )

      case Const.UNKNOWN_DEVICE => Map.empty

      case _ => Map.empty

    }

    Json4sUtil.any2jvalue(props).get

  }

  def defaultDisplayKeys(deviceTypeKey: String): Array[String] = {
    deviceTypeKey match {
      case Const.ENVIRONMENTSENSOR =>
        Array("temperature", "presure", "humidity", "batteryLevel")
      case Const.LIGHTSSENSOR =>
        Array("r", "g", "b", "ba")
      case Const.TRACKLESENSOR =>
        Array("t1", "t2", "tAvg", "batteryPower")
      case _ => Array()
    }
  }

  /**
    * The following fields can be included in default configs:
    *
    * * s = sensor sensitivity
    * * ir = infrared filter
    * * bf = 0/1
    * * i = update interval
    *
    * @param deviceType device type the default config applies to
    * @return default config for the given device type
{'fraction_non_alphanumeric': 0.10733503256867744, 'fraction_numerical': 0.004814500141602946, 'mean_word_length': 3.0429307384087005, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 46, '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': '5108159', 'n_tokens_mistral': 2243, 'n_tokens_neox': 2142, 'n_words': 455}