<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

const React = require('react')
const ImmutableComponent = require('../../components/immutableComponent')

class Stats extends ImmutableComponent {
  get millisecondsPerItem () {
    return 50
  }
  get trackedBlockersCount () {
    return this.props.newTabData.get('trackedBlockersCount') || 0
  }
  get adblockCount () {
    return this.props.newTabData.get('adblockCount') || 0
  }
  get httpsUpgradedCount () {
    return this.props.newTabData.get('httpsUpgradedCount') || 0
  }
  get estimatedTimeSaved () {
    const estimatedMillisecondsSaved = (this.adblockCount + this.trackedBlockersCount) * this.millisecondsPerItem || 0
    const hours = estimatedMillisecondsSaved < 1000 * 60 * 60 * 24
    const minutes = estimatedMillisecondsSaved < 1000 * 60 * 60
    const seconds = estimatedMillisecondsSaved < 1000 * 60
    let counter
    let text

    if (seconds) {
      counter = Math.ceil(estimatedMillisecondsSaved / 1000)
      text = 'seconds'
    } else if (minutes) {
      counter = Math.ceil(estimatedMillisecondsSaved / 1000 / 60)
      text = 'minutes'
    } else if (hours) {
      counter = Math.ceil(estimatedMillisecondsSaved / 1000 / 60 / 60)
      text = 'hours'
    } else {
      // Otherwise the output is in days
      counter = Math.ceil(estimatedMillisecondsSaved / 1000 / 60 / 60 / 24)
      text = 'days'
    }

    return {
      id: text,
      value: counter,
      args: JSON.stringify({ value: counter })
    }
  }
  render () {
    const trackedBlockersCount = this.trackedBlockersCount
    const adblockCount = this.adblockCount
    const httpsUpgradedCount = this.httpsUpgradedCount
    const timeSaved = this.estimatedTimeSaved
    const blockedArgs = JSON.stringify({
      adblockCount: adblockCount,
      trackedBlockersCount: trackedBlockersCount,
      httpsUpgradedCount: httpsUpgradedCount
    })
    return <ul className='statsContainer'>
      <li className='statsBlock'>
        <span className='counter trackers'>{trackedBlockersCount}</span>
        <span className='statsText' data-l10n-id='trackersBlocked' data-l10n-args={blockedArgs} />
      </li>
      <li className='statsBlock'>
        <span className='counter ads'>{adblockCount}</span>
        <span className='statsText' data-l10n-id='adsBlocked' data-l10n-args={blockedArgs} />
      </li>
      <li className='statsBlock'>
        <span className='counter https'>{httpsUpgradedCount}</span>
        <span className='statsText' data-l10n-id='httpsUpgraded' data-l10n-args={blockedArgs} />
      </li>
      <li className='statsBlock'>
        <span className='counter timeSaved'>
          {timeSaved.value} <span className='text' data-l10n-id={timeSaved.id} data-l10n-args={timeSaved.args} />
        </span>
        <span className='statsText' data-l10n-id='estimatedTimeSaved' />
      </li>
    </ul>
  }
}
module.exports = Stats<commit_msg>Update newtab stats to have locale-aware formatting<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

const React = require('react')
const ImmutableComponent = require('../../components/immutableComponent')

class Stats extends ImmutableComponent {
  get millisecondsPerItem () {
    return 50
  }
  get trackedBlockersCount () {
    return this.props.newTabData.get('trackedBlockersCount') || 0
  }
  get adblockCount () {
    return this.props.newTabData.get('adblockCount') || 0
  }
  get httpsUpgradedCount () {
    return this.props.newTabData.get('httpsUpgradedCount') || 0
  }
  get estimatedTimeSaved () {
    const estimatedMillisecondsSaved = (this.adblockCount + this.trackedBlockersCount) * this.millisecondsPerItem || 0
    const hours = estimatedMillisecondsSaved < 1000 * 60 * 60 * 24
    const minutes = estimatedMillisecondsSaved < 1000 * 60 * 60
    const seconds = estimatedMillisecondsSaved < 1000 * 60
    let counter
    let text

    if (seconds) {
      counter = Math.ceil(estimatedMillisecondsSaved / 1000)
      text = 'seconds'
    } else if (minutes) {
      counter = Math.ceil(estimatedMillisecondsSaved / 1000 / 60)
      text = 'minutes'
    } else if (hours) {
      counter = Math.ceil(estimatedMillisecondsSaved / 1000 / 60 / 60)
      text = 'hours'
    } else {
      // Otherwise the output is in days
      counter = Math.ceil(estimatedMillisecondsSaved / 1000 / 60 / 60 / 24)
      text = 'days'
    }

    return {
      id: text,
      value: counter,
      args: JSON.stringify({ value: counter })
    }
  }
  render () {
    const trackedBlockersCount = this.trackedBlockersCount
    const adblockCount = this.adblockCount
    const httpsUpgradedCount = this.httpsUpgradedCount
    const timeSaved = this.estimatedTimeSaved
    const blockedArgs = JSON.stringify({
      adblockCount: adblockCount,
      trackedBlockersCount: trackedBlockersCount,
      httpsUpgradedCount: httpsUpgradedCount
    })
    return <ul className='statsContainer'>
      <li className='statsBlock'>
        <span className='counter trackers'>{trackedBlockersCount.toLocaleString()}</span>
        <span className='statsText' data-l10n-id='trackersBlocked' data-l10n-args={blockedArgs} />
      </li>
      <li className='statsBlock'>
        <span className='counter ads'>{adblockCount.toLocaleString()}</span>
        <span className='statsText' data-l10n-id='adsBlocked' data-l10n-args={blockedArgs} />
      </li>
      <li className='statsBlock'>
        <span className='counter https'>{httpsUpgradedCount.toLocaleString()}</span>
        <span className='statsText' data-l10n-id='httpsUpgraded' data-l10n-args={blockedArgs} />
      </li>
      <li className='statsBlock'>
        <span className='counter timeSaved'>
          {timeSaved.value} <span className='text' data-l10n-id={timeSaved.id} data-l10n-args={timeSaved.args} />
        </span>
        <span className='statsText' data-l10n-id='estimatedTimeSaved' />
      </li>
    </ul>
  }
}
module.exports = Stats
{'fraction_non_alphanumeric': 0.11710126379779236, 'fraction_numerical': 0.02559590465525516, 'mean_word_length': 3.181939799331104, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 49, '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': '1989285', 'n_tokens_mistral': 2030, 'n_tokens_neox': 1864, 'n_words': 439}