<commit_before>// @flow
import React from 'react';
import { formatTime } from '../../helpers';
import Spinner from '../layout/Spinner';

type Props = {
  initialTime: number,
  time: number,
  dashboardData: any
};

const MotivationBlock = (props: Props) => {
  if (props.dashboardData.isFetching) {
    return <Spinner />;
  }
  let thisWeekString = '';
  let lastWeekString = '';
  let diffString = '';
  const { time, initialTime } = props;
  const initialDifference = Number(time) - Number(initialTime);
  const { dashboardData } = props;
  if (dashboardData.lastWeek && dashboardData.thisWeek) {
    const { lastWeek, thisWeek } = dashboardData;

    if (lastWeek && lastWeek.seconds) {
      lastWeekString = (
        <p>
          Last week you did <b>{formatTime(lastWeek.seconds)}</b> on this
          project.
        </p>
      );
    }
    if (thisWeek && thisWeek.seconds) {
      const difference = time - initialTime;
      thisWeekString = (
        <p>
          This week you did <b>{formatTime(thisWeek.seconds + difference)}</b>.
        </p>
      );
    }

    if (lastWeek && lastWeek.seconds && thisWeek && thisWeek.seconds) {
      const difference =
        lastWeek.seconds - initialDifference - thisWeek.seconds;
      if (difference > 0) {
        diffString = (
          <p>
            Do no less this week - <b>{formatTime(difference)}</b> to do
          </p>
        );
      } else {
        diffString = (
          <p>
            You did - <b>{formatTime(Math.abs(difference))}</b> more than last
            week!
          </p>
        );
      }
    }
  }

  return (
    <div>
      {lastWeekString} {thisWeekString} {diffString}
    </div>
  );
};<commit_msg>bugfix: get source of truth from state, dont calculate<commit_after>// @flow
import React from 'react';
import { formatTime } from '../../helpers';
import Spinner from '../layout/Spinner';

type Props = {
  dashboardData: any
};

const MotivationBlock = (props: Props) => {
  if (props.dashboardData.isFetching) {
    return <Spinner />;
  }
  let thisWeekString = '';
  let lastWeekString = '';
  let diffString = '';
  const { dashboardData } = props;
  if (dashboardData.lastWeek && dashboardData.thisWeek) {
    const { lastWeek, thisWeek } = dashboardData;

    if (lastWeek && lastWeek.seconds) {
      lastWeekString = (
        <p>
          Last week you did <b>{formatTime(lastWeek.seconds)}</b> on this
          project.
        </p>
      );
    }
    if (thisWeek && thisWeek.seconds) {
      thisWeekString = (
        <p>
          This week you did <b>{formatTime(thisWeek.seconds)}</b>.
        </p>
      );
    }

    if (lastWeek && lastWeek.seconds && thisWeek && thisWeek.seconds) {
      const difference = lastWeek.seconds - thisWeek.seconds;
      if (difference > 0) {
        diffString = (
          <p>
            Do no less this week - <b>{formatTime(difference)}</b> to do
          </p>
        );
      } else {
        diffString = (
          <p>
            You did - <b>{formatTime(Math.abs(difference))}</b> more than last
            week!
          </p>
        );
      }
    }
  }

  return (
    <div>
      {lastWeekString} {thisWeekString} {diffString}
    </div>
  );
};
{'fraction_non_alphanumeric': 0.13993174061433447, 'fraction_numerical': 0.0006205398696866273, 'mean_word_length': 2.0501419110690633, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 45, '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': '816673', 'n_tokens_mistral': 1008, 'n_tokens_neox': 995, 'n_words': 240}