<commit_before>import React, { Component } from 'react';
import { connect } from 'react-redux';
import { fetchInvestments } from '../../actions';
import Card, { CardActions, CardContent } from 'material-ui/Card';
import Button from 'material-ui/Button';
import Typography from 'material-ui/Typography';
import Grid from 'material-ui/Grid';
import '../App.css';

class InvestmentList extends Component {
  componentDidMount() {
    this.props.fetchInvestments();
  }

  getSymbol(currency) {
    return this.props.crypto.map((c) => {
      if (c.id === currency) {
        return(
          c.symbol
        )
      }
    })
  }

  getCurrentPrice(currency) {
    const price = this.props.crypto.filter((c) => {
      if (c.id === currency) {
        return(
          c
        )
      }
    })
    return price[0].price_usd
  }

  calculateProfitDollars(units, currentPrice, pastPrice) {
    const purchasePrice = units * pastPrice
    return ((parseInt(units, 10) * parseInt(currentPrice, 10))- parseInt(currentPrice, 10))
  }

  calculateProfitPercentage(units, dollarValue, currentPrice) {
    const currentDollars = (parseInt(units, 10) * parseInt(currentPrice, 10))
    const pastWorth = units * dollarValue
    return parseInt((currentDollars / pastWorth) * 100, 10)
  }

  renderInvestments() {
    return this.props.investments.map(investment => {
      return (
        <Grid item xs={4} key={investment._id}>
          <Card>
            <CardContent>
              <div id="wrapper">
                <Typography type="headline" component="h2" id="first-div">
                  <div style={{ marginBottom: -10 }}>{this.getSymbol(investment.currency)}<small>(x{investment.units})</small></div>
                </Typography>
                <Typography type="subheading" align="right" id="third-div">
                  <div>
                    profits: +{this.calculateProfitPercentage(investment.units, investment.dollarValue, this.getCurrentPrice(investment.currency))}%
                    |
                    {" +" + this.calculateProfitDollars(investment.units, this.getCurrentPrice(investment.currency), investment.dollarValue)}$
                  </div>
                </Typography>
              </div>
              <div>
                <Typography type="subheading" align="center" id="third-div">
                  <div style={{ paddingTop: 10 }}>{investment.dollarValue * investment.units}$  =>
                  {this.getCurrentPrice((investment.currency), investment.dollarValue) * investment.units}$</div>
                </Typography>
              </div>
              <Typography style={{ paddingTop: 24, marginBottom: -18 }} type="body1">
                {new Date(investment.date).toLocaleDateString()}
              </Typography>
            </CardContent>
          </Card>
        </Grid>
      )
    })
  }
<commit_msg>feat: Use kFormatter for big money numbers<commit_after>import React, { Component } from 'react';
import { connect } from 'react-redux';
import { fetchInvestments } from '../../actions';
import Card, { CardActions, CardContent } from 'material-ui/Card';
import Button from 'material-ui/Button';
import Typography from 'material-ui/Typography';
import Grid from 'material-ui/Grid';
import '../App.css';

class InvestmentList extends Component {
  componentDidMount() {
    this.props.fetchInvestments();
  }

  getSymbol(currency) {
    return this.props.crypto.map((c) => {
      if (c.id === currency) {
        return(
          c.symbol
        )
      }
    })
  }

  getCurrentPrice(currency) {
    const price = this.props.crypto.filter((c) => {
      if (c.id === currency) {
        return(
          c
        )
      }
    })
    return price[0].price_usd
  }

  kFormatter(num) {
    return num > 999 ? (num/1000).toFixed(1) + 'k' : num
  }

  calculateProfitDollars(units, currentPrice, pastPrice) {
    const purchasePrice = units * parseInt(pastPrice, 10)
    const priceNow = units * parseInt(currentPrice, 10)
    const result = priceNow - purchasePrice
    return this.kFormatter(result)
  }

  calculateProfitPercentage(units, dollarValue, currentPrice) {
    const currentDollars = (parseInt(units, 10) * parseInt(currentPrice, 10))
    const pastWorth = units * dollarValue
    return parseInt((currentDollars / pastWorth) * 100, 10) - 100
  }

  renderInvestments() {
    return this.props.investments.map(investment => {
      return (
        <Grid item xs={4} key={investment._id}>
          <Card>
            <CardContent>
              <div id="wrapper">
                <Typography type="headline" component="h2" id="first-div">
                  <div style={{ marginBottom: -10 }}>{this.getSymbol(investment.currency)}<small>(x{investment.units})</small></div>
                </Typography>
                <Typography type="subheading" align="right" id="third-div">
                  <div>
                    profits: +{this.calculateProfitPercentage(investment.units, investment.dollarValue, this.getCurrentPrice(investment.currency))}%
                    |
                    {" +" + this.calculateProfitDollars(investment.units, this.getCurrentPrice(investment.currency), investment.dollarValue)}$
                  </div>
                </Typography>
              </div>
              <div>
                <Typography type="subheading" align="center" id="third-div">
                  <div style={{ paddingTop: 10 }}>{this.kFormatter(investment.dollarValue * investment.units)}$  =>
                  {this.kFormatter(this.getCurrentPrice((investment.currency), investment.dollarValue) * investment.units)}$</div>
                </Typography>
              </div>
              <Typography style={{ paddingTop: 24, marginBottom: -18 }} type="body1">
                {new Date(investment.date).toLocaleDateString()}
              </Typography>
            </CardContent>
          </Card>
        </Grid>
      )
    })
  }

{'fraction_non_alphanumeric': 0.13547297297297298, 'fraction_numerical': 0.010641891891891892, 'mean_word_length': 2.3133743704532734, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 64, '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': '366508', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1665, 'n_words': 331}