<commit_before>/*
 * Copyright (c) 2012 SnowPlow Analytics Ltd. All rights reserved.
 *
 * This program is licensed to you under the Apache License Version 2.0,
 * and you may not use this file except in compliance with the Apache License Version 2.0.
 * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the Apache License Version 2.0 is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
 */
package com.snowplowanalytics.snowplow.hadoop.etl
package enrichments

// UserAgentUtils
import nl.bitwalker.useragentutils._

/**
 * Contains enrichments related to the
 * client - i.e. useragent, browser
 * details etc.
 */
object ClientEnrichments {
  
  /**
   * Case class to wrap everything we
   * can extract from the useragent
   * using UserAgentUtils.
   *
   * TODO: update this definition when
   * we swap out UserAgentUtils for
   * ua-parser
   */
  case class ClientAttributes(
    // Browser
    val browserName: String,
    val browserFamily: String,
    val browserVersion: Option[String],
    val browserType: String,
    val browserRenderEngine: String,
    // OS the browser is running on
    val osName: String,
    val osFamily: String,
    val osManufacturer: String,
    // Hardware the OS is running on
    val deviceType: String,
    val deviceIsMobile: Boolean)

  /**
   * Extracts the client attributes
   * from a useragent string, using
   * UserAgentUtils.
   *
   * TODO: rewrite this when we swap
   * out UserAgentUtils for ua-parser
   *
   * TODO: update this to return a
   * Scalaz Validation instead of Option
   *
   * @param useragent The useragent
   *                  string<commit_msg>Updated to stub extractScreenResolution<commit_after>/*
 * Copyright (c) 2012 SnowPlow Analytics Ltd. All rights reserved.
 *
 * This program is licensed to you under the Apache License Version 2.0,
 * and you may not use this file except in compliance with the Apache License Version 2.0.
 * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the Apache License Version 2.0 is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
 */
package com.snowplowanalytics.snowplow.hadoop.etl
package enrichments

// UserAgentUtils
import nl.bitwalker.useragentutils._

/**
 * Contains enrichments related to the
 * client - where the client is the
 * software which is using the SnowPlow
 * tracker.
 *
 * Enrichments relate to the useragent,
 * browser resolution, etc.
 */
object ClientEnrichments {
  
  /**
   * Case class to capture a client's
   * screen resolution
   */
  case class ScreenResolution(
    val width: Int,
    val height: Int)

  /**
   * Case class to wrap everything we
   * can extract from the useragent
   * using UserAgentUtils.
   *
   * TODO: update this definition when
   * we swap out UserAgentUtils for
   * ua-parser
   */
  case class ClientAttributes(
    // Browser
    val browserName: String,
    val browserFamily: String,
    val browserVersion: Option[String],
    val browserType: String,
    val browserRenderEngine: String,
    // OS the browser is running on
    val osName: String,
    val osFamily: String,
    val osManufacturer: String,
    // Hardware the OS is running on
    val deviceType: String,
    val deviceIsMobile: Boolean)

  // TODO: write the extractor.

  /**
   * Extracts the screen resolution
   * from the packed format used by
   * the Tracker Protocol:
   *
   * https://github.com/snowplow/snowplow/wiki/snowplow-tracker-protocol#wiki-browserandos
   *
   * TODO: update this to return a
   * Scalaz Validation instead of Option
   *
   * @param res The resolution string
   * @return the ScreenResolution,
   *         Option-boxed, or None if
   *         we had a problem
   */
  def extractScreenResolution(res: String): Option[ScreenResolution] = res match {

    /*
      String[] resolution = value.split("x");
    if (resolution.length != 2)
      throw new Exception("Couldn't parse res field");
    this.dvce_screenwidth = Integer.parseInt(resolution[0]);
    this.dvce_screenheight = Integer.parseInt(resolution[1]);
    break; */

    case _ => None // TODO: change to "Could not extract screen resolution [%s]" format res
  }



  /**
   * Extracts the client attributes
   * from a useragent string, using
   * UserAgentUtils.
   *
   * TODO: rewrite this when we swap
   * out UserAgentUtils for ua-parser
   *
   * TODO: update this to return a
   * Scalaz Validation instead of Option
   *
   * @param useragent The useragent
   *                  string
{'fraction_non_alphanumeric': 0.0752203721841332, 'fraction_numerical': 0.0068560235063663075, 'mean_word_length': 3.026813880126183, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, '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': '1095034', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1398, 'n_words': 573}