<commit_before>class @TimesheetView extends Backbone.View

  initialize: (options) ->
    @users = options.users
    @end = new Date()
    @start = 1.month().ago()
    @requests = []
    @data = []
    @components = [
      "itsm",
      "exception",
      "support",
      "chore",

      "ix-design",
      "development",

      "project-maintenance",

      "planning",
      "ux-research"
    ]
    @colors = [
      'rgba(220, 81, 27, 0.75)',
      'rgba(232, 113, 48, 0.75)',
      'rgba(239, 146, 59, 0.75)',
      'rgba(251, 195, 84, 0.75)',

      'rgba(122, 194, 197, 0.5)',
      'rgba(91, 195, 199, 0.5)',

      'rgba(26, 123, 105, 0.5)',

      'rgba(28, 28, 28, 0.5)',
      'rgba(140, 135, 134, 0.5)',
    ]

    view = @
    $("#reports_timeframes [role=tab]").click (e) ->
      switch $(@).attr("href")
        when "#week" then view.start = 1.week().ago()
        when "#month" then view.start = 1.month().ago()
        when "#3months" then view.start = 3.months().ago()
        when "#6months" then view.start = 6.months().ago()
      view.fetch()

  fetch: ->
    @abortAll()
    params =
      start: App.serverDateFormat(@start)
      end: App.serverDateFormat(@end)
      subject_type: "User"
      name: ["daily.hours.worked", "daily.hours.charged.{#{@components.join(",")}}"]
    jqXHR = $.getJSON "/api/v1/measurements", params, (measurements, response, jqXHR) =>
      i = @requests.indexOf(jqXHR)
      @requests.splice(i, 1)
      @setTimesheets measurements
      @render()
    @requests.push jqXHR

  abortAll: ->
    for request in @requests
      request.abort()
    @requests = []

  setTimesheets: (measurements) ->
    bySubjectId = {}
    for measurement in measurements.reverse()
      n = bySubjectId[measurement.subject.id] ||= { subject: measurement.subject, measurements: [] }
      n.measurements.push measurement
    @timesheets = _.values(bySubjectId)

  render: ->
    # for each subject, render a new stacked bar graph
    @$el.empty()
    for timesheet in @timesheets
      @$el.append """
<li class="timesheet" id="timesheet_#{timesheet.subject.id}">
  <div class="timesheet-employee">#{@users[timesheet.subject.id]}</div>
  <div class="timesheet-graph"></div>
</li>
"""
      @drawGraph(timesheet)

  drawGraph: (timesheet) ->
    stacksByDate = {}
    ceilsByDate = {}
    emptyStack = Array(@components.length).fill(0)
    domain = []
    date = @start<commit_msg>[skip] Skipped timesheets for retired users (4m)<commit_after>class @TimesheetView extends Backbone.View

  initialize: (options) ->
    @users = options.users
    @end = new Date()
    @start = 1.month().ago()
    @requests = []
    @data = []
    @components = [
      "itsm",
      "exception",
      "support",
      "chore",

      "ix-design",
      "development",

      "project-maintenance",

      "planning",
      "ux-research"
    ]
    @colors = [
      'rgba(220, 81, 27, 0.75)',
      'rgba(232, 113, 48, 0.75)',
      'rgba(239, 146, 59, 0.75)',
      'rgba(251, 195, 84, 0.75)',

      'rgba(122, 194, 197, 0.5)',
      'rgba(91, 195, 199, 0.5)',

      'rgba(26, 123, 105, 0.5)',

      'rgba(28, 28, 28, 0.5)',
      'rgba(140, 135, 134, 0.5)',
    ]

    view = @
    $("#reports_timeframes [role=tab]").click (e) ->
      switch $(@).attr("href")
        when "#week" then view.start = 1.week().ago()
        when "#month" then view.start = 1.month().ago()
        when "#3months" then view.start = 3.months().ago()
        when "#6months" then view.start = 6.months().ago()
      view.fetch()

  fetch: ->
    @abortAll()
    params =
      start: App.serverDateFormat(@start)
      end: App.serverDateFormat(@end)
      subject_type: "User"
      name: ["daily.hours.worked", "daily.hours.charged.{#{@components.join(",")}}"]
    jqXHR = $.getJSON "/api/v1/measurements", params, (measurements, response, jqXHR) =>
      i = @requests.indexOf(jqXHR)
      @requests.splice(i, 1)
      @setTimesheets measurements
      @render()
    @requests.push jqXHR

  abortAll: ->
    for request in @requests
      request.abort()
    @requests = []

  setTimesheets: (measurements) ->
    bySubjectId = {}
    for measurement in measurements.reverse()
      n = bySubjectId[measurement.subject.id] ||= { subject: measurement.subject, measurements: [] }
      n.measurements.push measurement
    @timesheets = _.values(bySubjectId)

  render: ->
    # for each subject, render a new stacked bar graph
    @$el.empty()
    for timesheet in @timesheets when @users[timesheet.subject.id]
      @$el.append """
<li class="timesheet" id="timesheet_#{timesheet.subject.id}">
  <div class="timesheet-employee">#{@users[timesheet.subject.id]}</div>
  <div class="timesheet-graph"></div>
</li>
"""
      @drawGraph(timesheet)

  drawGraph: (timesheet) ->
    stacksByDate = {}
    ceilsByDate = {}
    emptyStack = Array(@components.length).fill(0)
    domain = []
    date = @start
{'fraction_non_alphanumeric': 0.17879714576962283, 'fraction_numerical': 0.04220183486238532, 'mean_word_length': 2.636767976278725, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 31, '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': '6539142', 'n_tokens_mistral': 1892, 'n_tokens_neox': 1672, 'n_words': 355}