<commit_before>angular.module('doubtfire.tasks.partials.task-summary-stats', [])

#
# Task summary stats
# - 2d array of status vs task abbr --> counts
#
.directive('taskSummaryStats', ->
  replace: false
  restrict: 'E'
  templateUrl: 'tasks/partials/templates/task-summary-stats.tpl.html'
  scope:
    unit: "=unit"

  controller: ($scope, $modal, Task, taskService, TaskCompletionCSV) ->
    # functions from task service
    $scope.statusClass = taskService.statusClass
    $scope.statusText = taskService.statusText

    $scope.headerRow = taskService.allStatusData()

    $scope.scatterData = []

    taskAbbrs = _.map($scope.unit.task_definitions, (td) -> td.abbr)

    indexOfTask = (abbr) ->
      _.indexOf taskAbbrs, abbr
    indexOfTutorial = (tutorialId) ->
      _.indexOf $scope.unit.tutorials, _.find( $scope.unit.tutorials, (tutorial) -> tutorial.id == tutorialId )

    angular.forEach $scope.unit.tutorials, (tute) ->
      tutorial = { key: tute.abbreviation }

    numStudents = 0
    $scope.countClass = (count) ->
      if numStudents == 0 then ''
      else if count / numStudents > 0.5 then 'warning'
      else if count / numStudents > 0.25 then 'info'
      else ''

    $scope.fetchCSV = () ->
      TaskCompletionCSV.downloadFile($scope.unit)

    $scope.fetchStats = () ->
      numStudents = $scope.unit.students.length
      if numStudents == 0
        return

      # clear tmpScatterData
      tmpScatterData = []

      updateTask = (abbr, status, tutorialId) ->
        tutorialIdx = indexOfTutorial(tutorialId)
        taskIdx = indexOfTask(abbr)
        statusIdx = taskService.indexOf(status)

        tmpScatterData[tutorialIdx][statusIdx][taskIdx] += 1
        tmpScatterData[tutorialIdx][0][taskIdx] -= 1  #remove one from not-started


      angular.forEach $scope.unit.tutorials, (tute) ->
        tutorialData = []

        angular.forEach taskService.statusKeys, (sk) ->
          col = []
          angular.forEach $scope.unit.task_definitions, (td) ->
            if sk == taskService.statusKeys[0]
              col.push tute.num_students #not started has all student initially
            else
              col.push 0

          tutorialData.push col
        tmpScatterData.push tutorialData

      # angular.forEach $scope.stats, (row) ->
      #   angular.forEach row.stats, (rs) ->
      #     rs.count = 0
      Task.query { unit_id: $scope.unit.id }, (tasks) ->
        angular.forEach tasks, (task) ->
          updateTask(task.task_abbr, task.status, task.tutorial_id)

        # generate pcts
        _.each tmpScatterData, (tute, tuteIdx) ->
          _.each tute, (row, colIdx) ->
            _.each row, (val, idx) ->
              tmpScatterData[tuteIdx][colIdx][idx] /= numStudents

        # generate graph data
        scatterData = []
        _.each( $scope.unit.tutorials, (tute, tuteIdx) ->
          tutorial = {
            key: tute.abbreviation
            values: []
          }
          _.each tmpScatterData[tuteIdx], (col, statusIdx) ->
            _.each col, (val, taskIdx) ->
              if val > 0
                data = {
                  x: statusIdx + tuteIdx / ($scope.unit.tutorials.length * 2)
                  y: taskIdx
                  size: val
                }
                tutorial.values.push(data)
          scatterData.push(tutorial)
        ) # end each tutorial

        $scope.scatterData = scatterData

        # data[i].values.push({
        #   x: random()
        #   , y: random()
        #   , size: Math.random()   //Configure the size of each scatter point
        #   , shape: (Math.random() > 0.95) ? shapes[j % 6] : "circle"  //Configure the shape of each scatter point.
        #   });


    $scope.yAxisTickFormatFunction = () ->
      # d3.format('.02f')
      (value) ->
        $scope.unit.task_definitions[value].abbr

    $scope.xAxisTickFormatFunction = () ->
      # d3.format('.02f')
      (value) ->
        idx = Math.floor(value)
        taskService.statusAcronym[taskService.statusKeys[idx]]
<commit_msg>fix issue with task stats y labels<commit_after>angular.module('doubtfire.tasks.partials.task-summary-stats', [])

#
# Task summary stats
# - 2d array of status vs task abbr --> counts
#
.directive('taskSummaryStats', ->
  replace: false
  restrict: 'E'
  templateUrl: 'tasks/partials/templates/task-summary-stats.tpl.html'
  scope:
    unit: "=unit"

  controller: ($scope, $modal, Task, taskService, TaskCompletionCSV) ->
    # functions from task service
    $scope.statusClass = taskService.statusClass
    $scope.statusText = taskService.statusText

    $scope.headerRow = taskService.allStatusData()

    $scope.scatterData = []

    taskAbbrs = _.map($scope.unit.task_definitions, (td) -> td.abbr)

    indexOfTask = (abbr) ->
      _.indexOf taskAbbrs, abbr
    indexOfTutorial = (tutorialId) ->
      _.indexOf $scope.unit.tutorials, _.find( $scope.unit.tutorials, (tutorial) -> tutorial.id == tutorialId )

    angular.forEach $scope.unit.tutorials, (tute) ->
      tutorial = { key: tute.abbreviation }

    numStudents = 0
    $scope.countClass = (count) ->
      if numStudents == 0 then ''
      else if count / numStudents > 0.5 then 'warning'
      else if count / numStudents > 0.25 then 'info'
      else ''

    $scope.fetchCSV = () ->
      TaskCompletionCSV.downloadFile($scope.unit)

    $scope.fetchStats = () ->
      numStudents = $scope.unit.students.length
      if numStudents == 0
        return

      # clear tmpScatterData
      tmpScatterData = []

      updateTask = (abbr, status, tutorialId) ->
        tutorialIdx = indexOfTutorial(tutorialId)
        taskIdx = indexOfTask(abbr)
        statusIdx = taskService.indexOf(status)

        tmpScatterData[tutorialIdx][statusIdx][taskIdx] += 1
        tmpScatterData[tutorialIdx][0][taskIdx] -= 1  #remove one from not-started


      angular.forEach $scope.unit.tutorials, (tute) ->
        tutorialData = []

        angular.forEach taskService.statusKeys, (sk) ->
          col = []
          angular.forEach $scope.unit.task_definitions, (td) ->
            if sk == taskService.statusKeys[0]
              col.push tute.num_students #not started has all student initially
            else
              col.push 0

          tutorialData.push col
        tmpScatterData.push tutorialData

      # angular.forEach $scope.stats, (row) ->
      #   angular.forEach row.stats, (rs) ->
      #     rs.count = 0
      Task.query { unit_id: $scope.unit.id }, (tasks) ->
        angular.forEach tasks, (task) ->
          updateTask(task.task_abbr, task.status, task.tutorial_id)

        # generate pcts
        _.each tmpScatterData, (tute, tuteIdx) ->
          _.each tute, (row, colIdx) ->
            _.each row, (val, idx) ->
              tmpScatterData[tuteIdx][colIdx][idx] /= numStudents

        # generate graph data
        scatterData = []
        _.each( $scope.unit.tutorials, (tute, tuteIdx) ->
          tutorial = {
            key: tute.abbreviation
            values: []
          }
          _.each tmpScatterData[tuteIdx], (col, statusIdx) ->
            _.each col, (val, taskIdx) ->
              if val > 0
                data = {
                  x: statusIdx + tuteIdx / ($scope.unit.tutorials.length * 2)
                  y: taskIdx
                  size: val
                }
                tutorial.values.push(data)
          scatterData.push(tutorial)
        ) # end each tutorial

        $scope.scatterData = scatterData

        # data[i].values.push({
        #   x: random()
        #   , y: random()
        #   , size: Math.random()   //Configure the size of each scatter point
        #   , shape: (Math.random() > 0.95) ? shapes[j % 6] : "circle"  //Configure the shape of each scatter point.
        #   });


    $scope.yAxisTickFormatFunction = () ->
      # d3.format('.02f')
      (value) ->
        if $scope.unit.task_definitions[value]
          $scope.unit.task_definitions[value].abbr
        else
          ''

    $scope.xAxisTickFormatFunction = () ->
      # d3.format('.02f')
      (value) ->
        idx = Math.floor(value)
        taskService.statusAcronym[taskService.statusKeys[idx]]

{'fraction_non_alphanumeric': 0.12616250611845325, 'fraction_numerical': 0.006607929515418502, 'mean_word_length': 2.076025592773805, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '978839', 'n_tokens_mistral': 2616, 'n_tokens_neox': 2485, 'n_words': 521}