<commit_before><template>

  <div>
    <h1>Reports</h1>

    <!--USER BREADCRUMBS-->
    <breadcrumbs :list="userBreadcrumbs"></breadcrumbs>

    <!--TABS-->
    <all-recent-tabs
      :recentviewlink="recentViewLink"
      :allviewlink="allViewLink"
      :isrecentview="isRecentView"
    ></all-recent-tabs>


    <div class="tabcontents">
      <!--CONTENT BREADCRUMBS-->
      <breadcrumbs :list="contentBreadcrumbs"></breadcrumbs>

      <!--HEADER SECTION-->
      <report-header
        :contentkind="pageState.content_scope_summary.kind"
        :contenttitle="pageState.content_scope_summary.title"
        :userfullname="pageState.user_scope_summary.full_name"
      ></report-header>

      <!--SUMMARY SECTION-->
      <summary-section
        :kind="pageState.content_scope_summary.kind"
        :exercisecount="exerciseCount"
        :exerciseprogress="exerciseProgress"
        :contentcount="contentCount"
        :contentprogress="contentProgress"
        :lastactive="pageState.content_scope_summary.last_active"
        :singleuser="isSingleUser"
      ></summary-section>

      <!--VIEW-BY SWITCH-->
      <view-by-switch
        v-if="!isRecentView"
        :iscontent="isViewByContent"
        :vlink="viewByLink"
      ></view-by-switch>

      <!--LIST SECTION-->
      <list-section></list-section>
    </div>
  </div>

</template>


<script>

  const Constants = require('../../state/constants');
  const genLink = require('./genLink');
  const logging = require('kolibri.lib.logging');


  /* given an array of objects sum the keys on those that pass the filter */
  function sumOfKeys(array, key, filter = () => true) {
    return array
      .filter(filter)
      .reduce((prev, item) => prev + item[key], 0);
  }

  module.exports = {
    components: {
      'breadcrumbs': require('./breadcrumbs'),
      'all-recent-tabs': require('./all-recent-tabs'),
      'report-header': require('./report-header'),
      'summary-section': require('./summary-section'),
      'view-by-switch': require('./view-by-switch'),
      'list-section': require('./list-section'),
    },
    computed: {
      isViewByContent() {
        return this.pageState.view_by_content_or_learners === Constants.ViewBy.CONTENT;
      },
      isRecentView() {
        return this.pageState.all_or_recent === Constants.AllOrRecent.RECENT;
      },
      isSingleUser() {
        return this.pageState.user_scope === Constants.UserScopes.USER;
      },
      userBreadcrumbs() {
        if (this.pageState.user_scope === Constants.UserScopes.FACILITY) {
          return [{ title: 'All Learners' }];
        } else if (this.pageState.user_scope === Constants.UserScopes.USER) {
          const FACILITY_ID = '1'; // TODO - facility ID should not be hard-coded.
          return [
            {
              title: 'All Learners',
              vlink: genLink(this.pageState, {
                user_scope: Constants.UserScopes.FACILITY,
                user_scope_id: FACILITY_ID,
              }),
            },
            { title: this.pageState.user_scope_summary.full_name },
          ];
        }
        logging.error(`Unhandled user_scope: '${this.pageState.user_scope}'`);
        return [];
      },
      contentBreadcrumbs() {
        const list = this.pageState.content_scope_summary.ancestors.map((item, index) => ({
          title: item.title,
          vlink: genLink(this.pageState, {
            content_scope: index ? Constants.ContentScopes.TOPIC : Constants.ContentScopes.ROOT,
            content_scope_id: item.pk,
          }),
        }));
        list.push({ title: this.pageState.content_scope_summary.title });
        return list;
      },
      exerciseCount() {
        return sumOfKeys(
          this.pageState.content_scope_summary.progress,
          'node_count',
          item => item.kind === 'exercise'
        );
      },
      exerciseProgress() {
        const totalProgress = sumOfKeys(
          this.pageState.content_scope_summary.progress,
          'total_progress',
          item => item.kind === 'exercise'
        );
        return totalProgress / this.exerciseCount;
      },
      contentCount() {
        return sumOfKeys(
          this.pageState.content_scope_summary.progress,
          'node_count',
          item => item.kind !== 'exercise'
        );
      },
      contentProgress() {
        const totalProgress = sumOfKeys(
          this.pageState.content_scope_summary.progress,
          'total_progress',
          item => item.kind !== 'exercise'
        );
        return totalProgress / this.contentCount;
      },
      recentViewLink() {
        return genLink(this.pageState, {
          all_or_recent: Constants.AllOrRecent.RECENT,
          content_scope: Constants.ContentScopes.ROOT, // recent view only applies to root
          content_scope_id: 'root_id', // TODO: get root id
          // recent view is only viewable by content
          view_by_content_or_learners: Constants.ViewBy.CONTENT,
          // These are not really taken into account in recent view but it doesn't hurt
          sort_column: Constants.SortCols.DATE,
          sort_order: Constants.SortOrders.DESC,
        });
      },
      allViewLink() {
        return genLink(this.pageState, { all_or_recent: Constants.AllOrRecent.ALL });
      },
      viewByLink() {
        const view = this.isViewByContent ? Constants.ViewBy.LEARNERS : Constants.ViewBy.CONTENT;
        return genLink(this.pageState, { view_by_content_or_learners: view });
      },<commit_msg>temporary work-arounds<commit_after><template>

  <div>
    <h1>Reports</h1>

    <!--USER BREADCRUMBS-->
    <breadcrumbs :list="userBreadcrumbs"></breadcrumbs>

    <!--TABS-->
    <all-recent-tabs
      :recentviewlink="recentViewLink"
      :allviewlink="allViewLink"
      :isrecentview="isRecentView"
    ></all-recent-tabs>


    <div class="tabcontents">
      <!--CONTENT BREADCRUMBS-->
      <breadcrumbs :list="contentBreadcrumbs"></breadcrumbs>

      <!--HEADER SECTION-->
      <report-header
        :contentkind="pageState.content_scope_summary.kind"
        :contenttitle="pageState.content_scope_summary.title"
        :userfullname="pageState.user_scope_summary.full_name"
      ></report-header>

      <!--SUMMARY SECTION-->
      <!--
      <summary-section
        :kind="pageState.content_scope_summary.kind"
        :exercisecount="exerciseCount"
        :exerciseprogress="exerciseProgress"
        :contentcount="contentCount"
        :contentprogress="contentProgress"
        :lastactive="pageState.content_scope_summary.last_active"
        :singleuser="isSingleUser"
      ></summary-section>
      -->

      <!--VIEW-BY SWITCH-->
      <view-by-switch
        v-if="!isRecentView"
        :iscontent="isViewByContent"
        :vlink="viewByLink"
      ></view-by-switch>

      <!--LIST SECTION-->
      <list-section></list-section>
    </div>
  </div>

</template>


<script>

  const Constants = require('../../state/constants');
  const genLink = require('./genLink');
  const logging = require('kolibri.lib.logging');


  /* given an array of objects sum the keys on those that pass the filter */
  function sumOfKeys(array, key, filter = () => true) {
    return array
      .filter(filter)
      .reduce((prev, item) => prev + item[key], 0);
  }

  module.exports = {
    components: {
      'breadcrumbs': require('./breadcrumbs'),
      'all-recent-tabs': require('./all-recent-tabs'),
      'report-header': require('./report-header'),
      'summary-section': require('./summary-section'),
      'view-by-switch': require('./view-by-switch'),
      'list-section': require('./list-section'),
    },
    computed: {
      isViewByContent() {
        return this.pageState.view_by_content_or_learners === Constants.ViewBy.CONTENT;
      },
      isRecentView() {
        return this.pageState.all_or_recent === Constants.AllOrRecent.RECENT;
      },
      isSingleUser() {
        return this.pageState.user_scope === Constants.UserScopes.USER;
      },
      userBreadcrumbs() {
        if (this.pageState.user_scope === Constants.UserScopes.FACILITY) {
          return [{ title: 'All Learners' }];
        } else if (this.pageState.user_scope === Constants.UserScopes.USER) {
          const FACILITY_ID = '1'; // TODO - facility ID should not be hard-coded.
          return [
            {
              title: 'All Learners',
              vlink: genLink(this.pageState, {
                user_scope: Constants.UserScopes.FACILITY,
                user_scope_id: FACILITY_ID,
              }),
            },
            { title: this.pageState.user_scope_summary.full_name },
          ];
        }
        logging.error(`Unhandled user_scope: '${this.pageState.user_scope}'`);
        return [];
      },
      contentBreadcrumbs() {
        const list = this.pageState.content_scope_summary.ancestors.map((item, index) => ({
          title: item.title,
          vlink: genLink(this.pageState, {
            content_scope: index ? Constants.ContentScopes.TOPIC : Constants.ContentScopes.ROOT,
            content_scope_id: item.pk,
          }),
        }));
        list.push({ title: this.pageState.content_scope_summary.title });
        return list;
      },
      exerciseCount() {
        return sumOfKeys(
          this.pageState.content_scope_summary.progress,
          'node_count',
          item => item.kind === 'exercise'
        );
      },
      exerciseProgress() {
        const totalProgress = sumOfKeys(
          this.pageState.content_scope_summary.progress,
          'total_progress',
          item => item.kind === 'exercise'
        );
        return totalProgress / this.exerciseCount;
      },
      contentCount() {
        return sumOfKeys(
          this.pageState.content_scope_summary.progress,
          'node_count',
          item => item.kind !== 'exercise'
        );
      },
      contentProgress() {
        const totalProgress = sumOfKeys(
          this.pageState.content_scope_summary.progress,
          'total_progress',
          item => item.kind !== 'exercise'
        );
        return totalProgress / this.contentCount;
      },
      recentViewLink() {
        return genLink(this.pageState, {
          all_or_recent: Constants.AllOrRecent.RECENT,
          content_scope: Constants.ContentScopes.ROOT, // recent view only applies to root
          content_scope_id: '4c8abbdb27f94d568d32c402f0dd0fc2', // TODO: get root id
          // recent view is only viewable by content
          view_by_content_or_learners: Constants.ViewBy.CONTENT,
          // These are not really taken into account in recent view but it doesn't hurt
          sort_column: Constants.SortCols.DATE,
          sort_order: Constants.SortOrders.DESC,
        });
      },
      allViewLink() {
        return genLink(this.pageState, { all_or_recent: Constants.AllOrRecent.ALL });
      },
      viewByLink() {
        const view = this.isViewByContent ? Constants.ViewBy.LEARNERS : Constants.ViewBy.CONTENT;
        return genLink(this.pageState, { view_by_content_or_learners: view });
      },
{'fraction_non_alphanumeric': 0.13079902711467437, 'fraction_numerical': 0.002252049364922079, 'mean_word_length': 2.2992570579494798, 'pattern_counts': {'":': 0, '<': 64, '<?xml version=': 0, '>': 78, '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': '5934456', 'n_tokens_mistral': 3348, 'n_tokens_neox': 3264, 'n_words': 547}