<commit_before>/*
 * == BSD2 LICENSE ==
 * Copyright (c) 2016, Tidepool Project
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the associated License, which is identical to the BSD 2-Clause
 * License as published by the Open Source Initiative at opensource.org.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the License for more details.
 *
 * You should have received a copy of the License along with this program; if
 * not, you can obtain one from Tidepool Project at tidepool.org.
 * == BSD2 LICENSE ==
 */

import React, { PropTypes } from 'react';

import styles from './Tandem.css';

import Table from '../../../components/common/Table';
import CollapsibleContainer from '../../common/CollapsibleContainer';
import Header from '../header/Header';
import * as common from '../common';

const Tandem = (props) => {
  const { bgUnits, pumpSettings } = props;

  const schedules = common.getScheduleNames(pumpSettings.bgTargets);

  const getScheduleData = (scheduleName) => {
    const starts = pumpSettings.bgTargets[scheduleName].map(s => s.start);

    const data = starts.map((startTime) => ({
      start: common.getTime(
        pumpSettings.bgTargets[scheduleName],
        startTime,
      ),
      rate: common.getBasalRateT(
        pumpSettings.basalSchedules,
        scheduleName,
        startTime,
      ),
      bgTarget: common.getBloodGlucoseValue(
        pumpSettings.bgTargets[scheduleName],
        'target',
        startTime,
        bgUnits,
      ),
      carbRatio: common.getValue(
        pumpSettings.carbRatios[scheduleName],
        'amount',
        startTime,
      ),
      insulinSensitivity: common.getBloodGlucoseValue(
        pumpSettings.insulinSensitivities[scheduleName],
        'amount',
        startTime,
        bgUnits,
      ) })
    );

    data.push({
      start: 'Total',
      rate: common.getTotalBasalRatesT(
        pumpSettings.basalSchedules,
        scheduleName,
      ),
      bgTarget: '',
      carbRatio: '',
      insulinSensitivity: '',
    });

    return data;
  };

  const COLUMNS = [
    { key: 'start',
      label: 'Start time',
      className: '' },
    { key: 'rate',
      label: 'Basal Rates (U/hr)',
      className: styles.basalSchedulesHeader },
    { key: 'bgTarget',
      label: `BG Target (${bgUnits})`,
      className: styles.bolusSettingsHeader },
    { key: 'carbRatio',
      label: 'I : C Ratio (g)',
      className: styles.bolusSettingsHeader },
    { key: 'insulinSensitivity',
      label: `ISF (${bgUnits}/U)`,
      className: styles.bolusSettingsHeader },
  ];

  const tables = schedules.map((schedule) => (
    <div>
      <CollapsibleContainer
        styledLabel={{ label: schedule, className: styles.collapsibleHeader }}
        openByDefault={schedule === pumpSettings.activeSchedule}
        openedStyle={styles.collapsibleOpened}
        closedStyle={styles.collapsibleClosed}
      >
        <Table
          rows={getScheduleData(schedule)}
          columns={COLUMNS}
          tableStyle={styles.basalTable}
        />
      </CollapsibleContainer>
    </div>
  ));<commit_msg>update from review feedback<commit_after>/*
 * == BSD2 LICENSE ==
 * Copyright (c) 2016, Tidepool Project
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the associated License, which is identical to the BSD 2-Clause
 * License as published by the Open Source Initiative at opensource.org.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the License for more details.
 *
 * You should have received a copy of the License along with this program; if
 * not, you can obtain one from Tidepool Project at tidepool.org.
 * == BSD2 LICENSE ==
 */

import React, { PropTypes } from 'react';

import styles from './Tandem.css';

import Table from '../../../components/common/Table';
import CollapsibleContainer from '../../common/CollapsibleContainer';
import Header from '../header/Header';
import * as common from '../common';

const Tandem = (props) => {
  const { bgUnits, pumpSettings } = props;

  const schedules = common.getScheduleNames(pumpSettings.bgTargets);

  const getScheduleData = (scheduleName) => {
    const starts = pumpSettings.bgTargets[scheduleName].map(s => s.start);

    const data = starts.map((startTime) => ({
      start: common.getTime(
        pumpSettings.bgTargets[scheduleName],
        startTime,
      ),
      rate: common.getBasalRateT(
        pumpSettings.basalSchedules,
        scheduleName,
        startTime,
      ),
      bgTarget: common.getBloodGlucoseValue(
        pumpSettings.bgTargets[scheduleName],
        'target',
        startTime,
        bgUnits,
      ),
      carbRatio: common.getValue(
        pumpSettings.carbRatios[scheduleName],
        'amount',
        startTime,
      ),
      insulinSensitivity: common.getBloodGlucoseValue(
        pumpSettings.insulinSensitivities[scheduleName],
        'amount',
        startTime,
        bgUnits,
      ) })
    );

    data.push({
      start: 'Total',
      rate: common.getTotalBasalRatesT(
        pumpSettings.basalSchedules,
        scheduleName,
      ),
      bgTarget: '',
      carbRatio: '',
      insulinSensitivity: '',
    });

    return data;
  };

  const COLUMNS = [
    { key: 'start',
      label: 'Start time',
      className: '' },
    { key: 'rate',
      label: 'Basal Rates (U/hr)',
      className: styles.basalSchedulesHeader },
    { key: 'bgTarget',
      label: `BG Target (${bgUnits})`,
      className: styles.bolusSettingsHeader },
    { key: 'carbRatio',
      label: 'I:C Ratio (g/U)',
      className: styles.bolusSettingsHeader },
    { key: 'insulinSensitivity',
      label: `ISF (${bgUnits}/U)`,
      className: styles.bolusSettingsHeader },
  ];

  const tables = schedules.map((schedule) => (
    <div>
      <CollapsibleContainer
        styledLabel={{ label: schedule, className: styles.collapsibleHeader }}
        openByDefault={schedule === pumpSettings.activeSchedule}
        openedStyle={styles.collapsibleOpened}
        closedStyle={styles.collapsibleClosed}
      >
        <Table
          rows={getScheduleData(schedule)}
          columns={COLUMNS}
          tableStyle={styles.basalTable}
        />
      </CollapsibleContainer>
    </div>
  ));
{'fraction_non_alphanumeric': 0.11576876513317191, 'fraction_numerical': 0.00211864406779661, 'mean_word_length': 2.7360090446579988, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, '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': '1998195', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1853, 'n_words': 500}