<commit_before><template>

  <div>
    <section class="lesson-details">
      <div>
        <h1 class="title">{{ currentLesson.name }}</h1>
      </div>
      <div v-if="currentLesson.description!==''">
        <h3>{{ $tr('teacherNote') }}</h3>
        <p> {{ currentLesson.description }}</p>
      </div>
    </section>

    <section class="lesson-content-cards">
      <content-card
        v-for="c in contentNodes"
        :key="c.pk"
        class="content-card"
        :isMobile="true"
        :kind="c.kind"
        :link="lessonContentNodeLink(c)"
        :progress="c.progress_fraction"
        :thumbnail="getContentNodeThumbnail(c)"
        :title="c.title"
      />
    </section>
    <!-- <pre>
      {{ JSON.stringify(contentNodes, null, 2) }}
    </pre> -->
  </div>

</template>


<script>

  import ContentCard from '../content-card';

  // TODO Make this utility
  function getContentNodeThumbnail(contentnode) {
    const fileWithThumbnail = contentnode.files.find(file => file.thumbnail && file.available);
    if (fileWithThumbnail) {
      return fileWithThumbnail.storage_url;
    }
    return null;
  }

  function lessonContentNodeLink(contentNode) {
    return {
      name: 'TOPICS_CONTENT',
      params: {
        id: contentNode.pk,
      },
    };
  }

  export default {
    components: {
      ContentCard,
    },
    methods: {
      getContentNodeThumbnail,
      lessonContentNodeLink,
    },
    vuex: {
      getters: {
        contentNodes: state => state.pageState.contentNodes,
        currentLesson: state => state.pageState.currentLesson,
      },
    },
    $trs: {
      teacherNote: 'Teacher note:',
    },
  };

</script>

<commit_msg>Calculate Learner lesson progress<commit_after><template>

  <div>
    <section class="lesson-details">
      <div>
        <h1 class="title">
          {{ currentLesson.name }}
          <progress-icon v-if="lessonHasResources" :progress="lessonProgress" />
        </h1>
      </div>
      <div v-if="currentLesson.description!==''">
        <h3>{{ $tr('teacherNote') }}</h3>
        <p> {{ currentLesson.description }}</p>
      </div>
    </section>

    <section class="lesson-content-cards">
      <content-card
        v-for="c in contentNodes"
        :key="c.pk"
        class="content-card"
        :isMobile="true"
        :kind="c.kind"
        :link="lessonContentNodeLink(c)"
        :progress="c.progress_fraction"
        :thumbnail="getContentNodeThumbnail(c)"
        :title="c.title"
      />
    </section>
    <!-- <pre>
      {{ JSON.stringify(contentNodes, null, 2) }}
    </pre> -->
  </div>

</template>


<script>

  import sumBy from 'lodash/sumBy';
  import ProgressIcon from 'kolibri.coreVue.components.progressIcon';
  import ContentCard from '../content-card';

  // TODO Make this utility
  function getContentNodeThumbnail(contentnode) {
    const fileWithThumbnail = contentnode.files.find(file => file.thumbnail && file.available);
    if (fileWithThumbnail) {
      return fileWithThumbnail.storage_url;
    }
    return null;
  }

  function lessonContentNodeLink(contentNode) {
    return {
      name: 'TOPICS_CONTENT',
      params: {
        id: contentNode.pk,
      },
    };
  }

  export default {
    components: {
      ContentCard,
      ProgressIcon,
    },
    computed: {
      // HACK: Infer the Learner's progress by summing the progress_fractions
      // on all the ContentNodes
      lessonHasResources() {
        return this.contentNodes.length > 0;
      },
      lessonProgress() {
        if (this.lessonHasResources) {
          const total = sumBy(this.contentNodes, cn => cn.progress_fraction || 0);
          return total / this.contentNodes.length;
        }
      },
    },
    methods: {
      getContentNodeThumbnail,
      lessonContentNodeLink,
    },
    vuex: {
      getters: {
        contentNodes: state => state.pageState.contentNodes,
        currentLesson: state => state.pageState.currentLesson,
      },
    },
    $trs: {
      teacherNote: 'Teacher note:',
    },
  };

</script>


{'fraction_non_alphanumeric': 0.14356313318507535, 'fraction_numerical': 0.0029651593773165306, 'mean_word_length': 2.315315315315315, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 60, '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': '2654309', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1285, 'n_words': 229}