<commit_before>import React from "react";
import classes from "./MySGonks.module.css";
import Block from "../../components/UI/Block/Block";
import LinkButton from "../../components/UI/LinkButton/LinkButton";
import LongSGonksList from "../../components/SGonksLists/LongSGonksList/LongSGonksList";
import ChartCard from "../../components/ChartCard/ChartCard";

const MySGonks = (props) => {
  const ONE_WEEK_MILLISECONDS = 7 * 24 * 60 * 60 * 1000;
  const ONE_DAY_MILLISECONDS = 24 * 60 * 60 * 1000;
  const INITIAL_WORTH = 500;

  const unsoldInvestments = !props.investments
    ? undefined
    : props.investments.filter(
        (investment) => investment.dateSoldMilliSeconds === 0
      );

  const getUsername = () => {
    const rank = props.generalInfo.rank - 1
    return props.rankings[rank].name
  }

  const getEarliestDate = (investments) => {
    var currentEarliest = Infinity;
    for (var i = 0; i < investments.length; i++) {
      currentEarliest = Math.min(currentEarliest, investments[i].dateInvestedMilliSeconds);
    }
    return currentEarliest - ONE_WEEK_MILLISECONDS;
  }

  const getTitleChartRow = (investments) => {
    var titleRow = ['x'];
    for (var i = 0; i < investments.length; i++) {
      var search = investments[i].searchItem;
      titleRow.push(search);
    }
    return titleRow;
  }

  const populateInvestmentData = (investments, data, earliestDate, currentDate) => {
    // add each investment's datapoints to correct chart indices
    for (var i = 0; i < investments.length; i++) {
      var firstDateWithData = investments[i].dateInvestedMilliSeconds - ONE_WEEK_MILLISECONDS;
      var lastDateWithData = investments[i].dateSoldMilliseconds;
      var rowCount = 1; // start at second row
      var dataCount = 0;
      var date = earliestDate;
      var row;
      while (date <= currentDate) {
        if (date < firstDateWithData || date > lastDateWithData) {
          row = data[rowCount];
          row.push(null);
          data[rowCount] = row;
        } else {
          row = data[rowCount];
          row.push(investments[i].dataPoints[dataCount]);
          data[rowCount] = row;
          dataCount++;
        }
        date += ONE_DAY_MILLISECONDS;
        rowCount++;
      }
    }
    return data;
  }

  const formatChartData = () => {
    const investments = props.investments;
    console.log(investments);
    var data = [getTitleChartRow(investments)];
    const earliestDate = getEarliestDate(investments);
    const currentDate = Date.now();
    // add every required date point to chart
    var i = 0; // start at second row 
    var date = earliestDate;
    while (date <= currentDate) {
      var row = [i];
      data.push(row);
      date += ONE_DAY_MILLISECONDS;
      i++;
    }
    populateInvestmentData(investments, data, earliestDate, currentDate);
    return data;
  }

  const chartsData = {
    haxis: "Time",
    vaxis: "Investment Value",
    data: formatChartData(),
  };

  

  return (
    <div className={classes.MySGonksContainer}>
      <div className={classes.ChartAndInfoContainer}>
        <Block className={classes.ChartContainer}>
          <ChartCard chartInfo={chartsData}></ChartCard>
        </Block>
        <div className={classes.InfoContainer}>
          <Block className={classes.InfoBlock}>
            <h3>{getUsername()}</h3>
            <div className={classes.MonetaryInfo}>
              <p>
                <span>Initial worth:</span>
                <span className={classes.TrendBucks}>t${INITIAL_WORTH}</span>
              </p>
              <p>
                <span>Net worth:</span>
                <span className={classes.TrendBucks}>
                  t${props.generalInfo.netWorth}
                </span>
              </p>
            </div>
          </Block>
          <Block className={classes.InfoBlock}>
            <h3>Currently Available:</h3>
            <p className={classes.CurrentAvail}>
              t${props.generalInfo.amountAvailable}
            </p>
          </Block>
          <LinkButton to="/toroutelater">Buy sGonks</LinkButton>
        </div>
      </div>
      <div className={classes.SGonksListContainer}>
        <LongSGonksList investments={unsoldInvestments}></LongSGonksList>
      </div>
    </div>
  );
};

export default MySGonks;<commit_msg>Fix routing of buy stocks button<commit_after>import React from "react";
import classes from "./MySGonks.module.css";
import Block from "../../components/UI/Block/Block";
import LinkButton from "../../components/UI/LinkButton/LinkButton";
import LongSGonksList from "../../components/SGonksLists/LongSGonksList/LongSGonksList";
import ChartCard from "../../components/ChartCard/ChartCard";

const MySGonks = (props) => {
  const ONE_WEEK_MILLISECONDS = 7 * 24 * 60 * 60 * 1000;
  const ONE_DAY_MILLISECONDS = 24 * 60 * 60 * 1000;
  const INITIAL_WORTH = 500;

  const unsoldInvestments = !props.investments
    ? undefined
    : props.investments.filter(
        (investment) => investment.dateSoldMilliSeconds === 0
      );

  const getUsername = () => {
    const rank = props.generalInfo.rank - 1
    return props.rankings[rank].name
  }

  const getEarliestDate = (investments) => {
    var currentEarliest = Infinity;
    for (var i = 0; i < investments.length; i++) {
      currentEarliest = Math.min(currentEarliest, investments[i].dateInvestedMilliSeconds);
    }
    return currentEarliest - ONE_WEEK_MILLISECONDS;
  }

  const getTitleChartRow = (investments) => {
    var titleRow = ['x'];
    for (var i = 0; i < investments.length; i++) {
      var search = investments[i].searchItem;
      titleRow.push(search);
    }
    return titleRow;
  }

  const populateInvestmentData = (investments, data, earliestDate, currentDate) => {
    // add each investment's datapoints to correct chart indices
    for (var i = 0; i < investments.length; i++) {
      var firstDateWithData = investments[i].dateInvestedMilliSeconds - ONE_WEEK_MILLISECONDS;
      var lastDateWithData = investments[i].dateSoldMilliseconds;
      var rowCount = 1; // start at second row
      var dataCount = 0;
      var date = earliestDate;
      var row;
      while (date <= currentDate) {
        if (date < firstDateWithData || date > lastDateWithData) {
          row = data[rowCount];
          row.push(null);
          data[rowCount] = row;
        } else {
          row = data[rowCount];
          row.push(investments[i].dataPoints[dataCount]);
          data[rowCount] = row;
          dataCount++;
        }
        date += ONE_DAY_MILLISECONDS;
        rowCount++;
      }
    }
    return data;
  }

  const formatChartData = () => {
    const investments = props.investments;
    console.log(investments);
    var data = [getTitleChartRow(investments)];
    const earliestDate = getEarliestDate(investments);
    const currentDate = Date.now();
    // add every required date point to chart
    var i = 0; // start at second row 
    var date = earliestDate;
    while (date <= currentDate) {
      var row = [i];
      data.push(row);
      date += ONE_DAY_MILLISECONDS;
      i++;
    }
    populateInvestmentData(investments, data, earliestDate, currentDate);
    return data;
  }

  const chartsData = {
    haxis: "Time",
    vaxis: "Investment Value",
    data: formatChartData(),
  };

  return (
    <div className={classes.MySGonksContainer}>
      <div className={classes.ChartAndInfoContainer}>
        <Block className={classes.ChartContainer}>
          <ChartCard chartInfo={chartsData}></ChartCard>
        </Block>
        <div className={classes.InfoContainer}>
          <Block className={classes.InfoBlock}>
            <h3>{getUsername()}</h3>
            <div className={classes.MonetaryInfo}>
              <p>
                <span>Initial worth:</span>
                <span className={classes.TrendBucks}>t${INITIAL_WORTH}</span>
              </p>
              <p>
                <span>Net worth:</span>
                <span className={classes.TrendBucks}>
                  t${props.generalInfo.netWorth}
                </span>
              </p>
            </div>
          </Block>
          <Block className={classes.InfoBlock}>
            <h3>Currently Available:</h3>
            <p className={classes.CurrentAvail}>
              t${props.generalInfo.amountAvailable}
            </p>
          </Block>
          <LinkButton to="/marketplace">Buy sGonks</LinkButton>
        </div>
      </div>
      <div className={classes.SGonksListContainer}>
        <LongSGonksList investments={unsoldInvestments}></LongSGonksList>
      </div>
    </div>
  );
};

export default MySGonks;
{'fraction_non_alphanumeric': 0.12433310136859198, 'fraction_numerical': 0.008350730688935281, 'mean_word_length': 2.4464428457234213, 'pattern_counts': {'":': 0, '<': 95, '<?xml version=': 0, '>': 99, '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': '3516592', 'n_tokens_mistral': 2708, 'n_tokens_neox': 2556, 'n_words': 560}