<commit_before>define [
  'underscore'
  'Backbone'
  'i18n!course_logging'
], (_, Backbone, I18n) ->
  class CourseEvent extends Backbone.Model
    present: ->
      json = Backbone.Model::toJSON.call(@)
      data = {}
      iterator = (dataValue, dataKey) =>
        dataKey = @presentLabel(dataKey)
        data[dataKey] = @presentField(dataValue)

      switch json.event_type
        when "created"
          json.event_type_present = I18n.t("event_type.created", "Created")
          iterator = (dataValues, dataKey) =>
            dataKey = @presentLabel(dataKey)
            data[dataKey] = @presentField(_.last(dataValues))
        when "updated"
          json.event_type_present = I18n.t("event_type.updated", "Updated")
          iterator = (dataValues, dataKey) =>
            dataKey = @presentLabel(dataKey)
            data[dataKey] = _.object([ "from", "to" ], @presentField(dataValues))
        when "concluded"
          json.event_type_present = I18n.t("event_type.concluded", "Concluded")
        else
          json.event_type_present = json.event_type

      _.each json.event_data, iterator
      json.event_data = data unless _.isEmpty(data)
      return json

    presentField: (value) ->
      blank = "-"
      return blank if _.isNull(value)
      return value.toString() if _.isBoolean(value)
      if _.isArray(value)
        return _.map value, @presentField, @
      if _.isString(value)
        return blank if !value.length
        if value.match /^\d{4}-\d{2}-\d{2}(T| )\d{2}:\d{2}:\d{2}(.\d+)?Z$/
          return I18n.l("date.formats.medium", value) + " " + I18n.l("time.formats.tiny", value)
      return value

    presentLabel: (label) ->
      switch label.toLowerCase()
        when "name"
            I18n.t("field_label.name", "Name")
        when "account_id"
            I18n.t("field_label.account_id", "Account Id")
        when "group_weighting_scheme"
            I18n.t("field_label.group_weighting_scheme", "Group Weighting Scheme")
        when "old_account_id"
            I18n.t("field_label.old_account_id", "Old Account Id")
        when "workflow_state"
            I18n.t("field_label.workflow_state", "Workflow State")
        when "uuid"
            I18n.t("field_label.uuid", "UUID")
        when "start_at"
            I18n.t("field_label.start_at", "Start At")
        when "conclude_at"
            I18n.t("field_label.conclude_at", "Concluded At")
        when "grading_standard_id"
            I18n.t("field_label.grading_standard_id", "Grading Standard Id")<commit_msg>i18n Course Activity date fields<commit_after>define [
  'underscore'
  'Backbone'
  'i18n!course_logging'
], (_, Backbone, I18n) ->
  class CourseEvent extends Backbone.Model
    present: ->
      json = Backbone.Model::toJSON.call(@)
      data = {}
      iterator = (dataValue, dataKey) =>
        dataKey = @presentLabel(dataKey)
        data[dataKey] = @presentField(dataValue)

      switch json.event_type
        when "created"
          json.event_type_present = I18n.t("event_type.created", "Created")
          iterator = (dataValues, dataKey) =>
            dataKey = @presentLabel(dataKey)
            data[dataKey] = @presentField(_.last(dataValues))
        when "updated"
          json.event_type_present = I18n.t("event_type.updated", "Updated")
          iterator = (dataValues, dataKey) =>
            dataKey = @presentLabel(dataKey)
            data[dataKey] = _.object([ "from", "to" ], @presentField(dataValues))
        when "concluded"
          json.event_type_present = I18n.t("event_type.concluded", "Concluded")
        else
          json.event_type_present = json.event_type

      _.each json.event_data, iterator
      json.event_data = data unless _.isEmpty(data)
      return json

    presentField: (value) ->
      blank = "-"
      return blank if _.isNull(value)
      return value.toString() if _.isBoolean(value)
      if _.isArray(value)
        return _.map value, @presentField, @
      if _.isString(value)
        return blank if !value.length
        if value.match /^\d{4}-\d{2}-\d{2}(T| )\d{2}:\d{2}:\d{2}(.\d+)?Z$/
          return I18n.l("#date.formats.medium", value) + " " + I18n.l("#time.formats.tiny", value)
      return value

    presentLabel: (label) ->
      switch label.toLowerCase()
        when "name"
            I18n.t("field_label.name", "Name")
        when "account_id"
            I18n.t("field_label.account_id", "Account Id")
        when "group_weighting_scheme"
            I18n.t("field_label.group_weighting_scheme", "Group Weighting Scheme")
        when "old_account_id"
            I18n.t("field_label.old_account_id", "Old Account Id")
        when "workflow_state"
            I18n.t("field_label.workflow_state", "Workflow State")
        when "uuid"
            I18n.t("field_label.uuid", "UUID")
        when "start_at"
            I18n.t("field_label.start_at", "Start At")
        when "conclude_at"
            I18n.t("field_label.conclude_at", "Concluded At")
        when "grading_standard_id"
            I18n.t("field_label.grading_standard_id", "Grading Standard Id")
{'fraction_non_alphanumeric': 0.13414394979407726, 'fraction_numerical': 0.01529711708178074, 'mean_word_length': 2.4623217922606924, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '5440092', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1632, 'n_words': 305}