Code coverage report for src/components/plan-stats/performances.cjsx

Statements: 22.22% (8 / 36)      Branches: 0% (0 / 14)      Functions: 0% (0 / 5)      Lines: 22.22% (8 / 36)      Ignored: none     

All files » src/components/plan-stats/ » performances.cjsx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89                                                                                                                                                                  
var BS, ChaptersPerformance, PracticesPerformance, Progress, React, _;
 
React = require('react');
 
_ = require('underscore');
 
BS = require('react-bootstrap');
 
Progress = require('./progress');
 
ChaptersPerformance = React.createClass({
  displayName: 'ChaptersPerformance',
  propTypes: {
    currentPages: React.PropTypes.array.isRequired,
    activeSection: React.PropTypes.string
  },
  render: function() {
    var activeSection, chapters, currentPages, ref;
    ref = this.props, currentPages = ref.currentPages, activeSection = ref.activeSection;
    if (!_.isEmpty(currentPages)) {
      chapters = _.map(currentPages, function(data, i) {
        return React.createElement(Progress, {
          "key": "chapter-performance-" + data.id + "-" + i,
          "data": data,
          "type": 'chapter',
          "index": i,
          "activeSection": activeSection
        });
      });
      chapters = React.createElement("section", null, React.createElement("label", null, "Current Topics Performance"), chapters);
    }
    return chapters || null;
  }
});
 
PracticesPerformance = React.createClass({
  displayName: 'PracticesPerformance',
  propTypes: {
    spacedPages: React.PropTypes.array.isRequired,
    activeSection: React.PropTypes.string
  },
  calculatePercentDelta: function(a, b) {
    var change, op;
    if (a > b) {
      change = a - b;
      op = '+';
    } else if (a === b) {
      change = 0;
      op = '';
    } else {
      change = b - a;
      op = '-';
    }
    return op + ' ' + Math.round((change / b) * 100);
  },
  renderPracticeBars: function(data, i) {
    var activeSection, previous;
    activeSection = this.props.activeSection;
    if (data.previous_attempt) {
      previous = React.createElement("div", {
        "className": 'reading-progress-delta'
      }, this.calculatePercentDelta(data.correct_count, data.previous_attempt.correct_count), "% change");
    }
    return React.createElement(Progress, {
      "key": "practice-performance-" + data.id + "-" + i,
      "data": data,
      "type": 'practice',
      "index": i,
      "previous": previous,
      "activeSection": activeSection
    });
  },
  render: function() {
    var practices, spacedPages;
    spacedPages = this.props.spacedPages;
    if (!_.isEmpty(spacedPages)) {
      practices = _.map(spacedPages, this.renderPracticeBars);
      practices = React.createElement("section", null, React.createElement("label", null, "Spaced Practice Performance"), practices);
    }
    return practices || null;
  }
});
 
module.exports = {
  ChaptersPerformance: ChaptersPerformance,
  PracticesPerformance: PracticesPerformance
};