<commit_before>{Resource, Model} = require 'json-api-client'
counterpart = require 'counterpart'
tasks = require '../classifier/tasks'

class Annotation extends Model
  toJSON: ->
    result = {}
    result[@task] = @value
    result

module.exports = class extends Resource
  annotations: null

  constructor: ->
    @metadata =
      started_at: (new Date).toISOString()
      user_agent: navigator.userAgent
      user_language: counterpart.getLocale()
    @annotations = []
    super

  annotate: (taskType, taskKey) ->
    annotation = new Annotation task: taskKey, tasks[taskType].getDefaultAnnotation?()
    annotation.listen [@, 'emit']

    @update annotations: =>
      @annotations.push annotation
      annotation.listen 'destroy', [@, 'handleAnnotationDestroy', @annotations.indexOf annotation]
      @annotations

    annotation

  handleAnnotationDestroy: (index) -><commit_msg>Don't serialize annotations specially<commit_after>{Resource, Model} = require 'json-api-client'
counterpart = require 'counterpart'
tasks = require '../classifier/tasks'

module.exports = class extends Resource
  annotations: null

  constructor: ->
    @metadata =
      started_at: (new Date).toISOString()
      user_agent: navigator.userAgent
      user_language: counterpart.getLocale()
    @annotations = []
    super

  annotate: (taskType, taskKey) ->
    annotation = new Model task: taskKey, tasks[taskType].getDefaultAnnotation?()
    annotation.listen [@, 'emit']

    @update annotations: =>
      @annotations.push annotation
      annotation.listen 'destroy', [@, 'handleAnnotationDestroy', @annotations.indexOf annotation]
      @annotations

    annotation

  handleAnnotationDestroy: (index) ->
{'fraction_non_alphanumeric': 0.11488862837045721, 'fraction_numerical': 0.0, 'mean_word_length': 3.8356940509915014, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '6788444', 'n_tokens_mistral': 482, 'n_tokens_neox': 446, 'n_words': 114}