<commit_before>import { Observable } from 'rx';
import dedent from 'dedent';
import moment from 'moment';

import { timeCache, observeMethod } from '../utils/rx';

function numberWithCommas(x) {
  return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}

// userCount(where: Object) => Observable[Number]
// getCertCount(userCount: userCount, cert: String) => Observable[Number]
function getCertCount(userCount, cert) {
  return userCount({ [cert]: true })
    // using This-Bind operator
    ::timeCache(2, 'hours');
}

export default function about(app) {
  const router = app.loopback.Router();
  const User = app.models.User;
  const userCount = observeMethod(User, 'count');
  const frontEndCount$ = getCertCount(userCount, 'isFrontEndCert');
  const dataVisCount$ = getCertCount(userCount, 'isDataVisCert');
  const backEndCount$ = getCertCount(userCount, 'isBackEndCert');

  function showAbout(req, res, next) {
    const daysRunning = moment().diff(new Date('10/15/2014'), 'days');

    Observable.combineLatest(
      frontEndCount$,
      dataVisCount$,
      backEndCount$,
      (frontEndCount = 0, dataVisCount = 0, backEndCount = 0) => ({
        frontEndCount,
        dataVisCount,
        backEndCount
      })
    )
      .doOnNext(({ frontEndCount, dataVisCount, backEndCount }) => {
        res.render('resources/about', {
          frontEndCount,
          dataVisCount,
          backEndCount,
          daysRunning,
          title: dedent`
            About our Open Source Community, our social media presence,
            and how to contact us
          `.split('\n').join(' '),
          globalCompletedCount: numberWithCommas(
            5612952 + (Math.floor((Date.now() - 1446268581061) / 1800))
          ),
          globalPledgedAmount: numberWithCommas(Math.floor(
            28000 +
            ((Date.now() - 1456207176902) / (2629746000 / 2000) * 8.30)
          ))
        });
      })<commit_msg>Add commas to certs earned on about page<commit_after>import { Observable } from 'rx';
import dedent from 'dedent';
import moment from 'moment';

import { timeCache, observeMethod } from '../utils/rx';

function numberWithCommas(x) {
  return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}

// userCount(where: Object) => Observable[Number]
// getCertCount(userCount: userCount, cert: String) => Observable[Number]
function getCertCount(userCount, cert) {
  return userCount({ [cert]: true })
    // using This-Bind operator
    ::timeCache(2, 'hours');
}

export default function about(app) {
  const router = app.loopback.Router();
  const User = app.models.User;
  const userCount = observeMethod(User, 'count');
  const frontEndCount$ = getCertCount(userCount, 'isFrontEndCert');
  const dataVisCount$ = getCertCount(userCount, 'isDataVisCert');
  const backEndCount$ = getCertCount(userCount, 'isBackEndCert');

  function showAbout(req, res, next) {
    const daysRunning = moment().diff(new Date('10/15/2014'), 'days');

    Observable.combineLatest(
      frontEndCount$,
      dataVisCount$,
      backEndCount$,
      (frontEndCount = 0, dataVisCount = 0, backEndCount = 0) => ({
        frontEndCount,
        dataVisCount,
        backEndCount
      })
    )
      .doOnNext(({ frontEndCount, dataVisCount, backEndCount }) => {
        res.render('resources/about', {
          frontEndCount: numberWithCommas(frontEndCount),
          dataVisCount: numberWithCommas(dataVisCount),
          backEndCount: numberWithCommas(backEndCount),
          daysRunning,
          title: dedent`
            About our Open Source Community, our social media presence,
            and how to contact us
          `.split('\n').join(' '),
          globalCompletedCount: numberWithCommas(
            5612952 + (Math.floor((Date.now() - 1446268581061) / 1800))
          ),
          globalPledgedAmount: numberWithCommas(Math.floor(
            28000 +
            ((Date.now() - 1456207176902) / (2629746000 / 2000) * 8.30)
          ))
        });
      })
{'fraction_non_alphanumeric': 0.1374750499001996, 'fraction_numerical': 0.03592814371257485, 'mean_word_length': 2.9342492639842983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5152553', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1200, 'n_words': 268}