<commit_before>import React from 'react';
import _ from 'underscore';
import StudentProfileUnit from './student_profile_unit.jsx';

export default React.createClass({

  groupUnits() {
    const groupedUnits = _.groupBy(this.props.data, 'unit_id');
    const unitsWithGroupedActivities = {};
    for (const unit in groupedUnits) {
      const partitionedActivities = _.partition(groupedUnits[unit], activity => (activity.max_percentage != null));
      unitsWithGroupedActivities[unit] = {};
      if (partitionedActivities[0].length) {
        unitsWithGroupedActivities[unit].complete = _.sortBy(partitionedActivities[0], 'unit_activity_created_at');
      }
      if (partitionedActivities[1].length) {
        unitsWithGroupedActivities[unit].incomplete = partitionedActivities[1];
      }
    }
    const unitsGroupedByCompletion = _.partition(unitsWithGroupedActivities, unit => (!!unit.incomplete));
    const finalArrangement = (unitsGroupedByCompletion[0].sort((a, b) => a.incomplete[0].unit_created_at - b.incomplete[0].unit_created_at));
    return finalArrangement.concat(unitsGroupedByCompletion[1].sort((a, b) => a.complete[0].unit_created_at - b.complete[0].unit_created_at));
  },

  render() {
    let content = 'LOADING';
    if (!this.props.loading) {
      // give unit unit id key whether it is complete or incomplete
      content = this.groupUnits().map(unit => <StudentProfileUnit key={unit[Object.keys(unit)[0]][0].unit_id} data={unit} />);
    }
    return (
      <div className="container">
        {content}
      </div>
    );
  },
});<commit_msg>changes to make student dashboard display units in order of their most pressing activity due date<commit_after>import React from 'react';
import _ from 'underscore';
import StudentProfileUnit from './student_profile_unit.jsx';

export default React.createClass({

  groupUnits() {
    const groupedUnits = _.groupBy(this.props.data, 'unit_id');
    const unitsWithGroupedActivities = {};
    for (const unit in groupedUnits) {
      const partitionedActivities = _.partition(groupedUnits[unit], activity => (activity.max_percentage != null));
      unitsWithGroupedActivities[unit] = {};
      if (partitionedActivities[0].length) {
        unitsWithGroupedActivities[unit].complete = _.sortBy(partitionedActivities[0], 'unit_activity_created_at');
      }
      if (partitionedActivities[1].length) {
        unitsWithGroupedActivities[unit].incomplete = partitionedActivities[1];
      }
    }
    const unitsGroupedByCompletion = _.partition(unitsWithGroupedActivities, unit => (!!unit.incomplete));
    const finalArrangement = (unitsGroupedByCompletion[0].sort((a, b) => a.incomplete[0].unit_created_at - b.incomplete[0].unit_created_at));
    const resultWithUnsortedUnits = finalArrangement.concat(unitsGroupedByCompletion[1].sort((a, b) => a.complete[0].unit_created_at - b.complete[0].unit_created_at));
    const resultWithSortedUnits = resultWithUnsortedUnits.sort(function(first, second) {
      if (first.incomplete != undefined && second.incomplete != undefined) {
        return new Date(first.incomplete[0].due_date) - new Date(second.incomplete[0].due_date);
      } else {
        return -1
      }
    });
    return resultWithSortedUnits;
  },

  render() {
    let content = 'LOADING';
    if (!this.props.loading) {
      // give unit unit id key whether it is complete or incomplete
      content = this.groupUnits().map(unit => <StudentProfileUnit key={unit[Object.keys(unit)[0]][0].unit_id} data={unit} />);
    }
    return (
      <div className="container">
        {content}
      </div>
    );
  },
});
{'fraction_non_alphanumeric': 0.13216957605985039, 'fraction_numerical': 0.007481296758104738, 'mean_word_length': 4.077355836849508, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '2775350', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1081, 'n_words': 205}