<commit_before># frozen_string_literal: true

class V2::ChangeSerializer < V2::BaseSerializer
  set_type :change

  attributes :created_at
  attributes :whodunnit
  attributes :author
  attributes :item_type
  attributes :item_id
  attributes :event
  attributes :diffs do |object, record_serialization_params|
    object.diffs.map do |diff|
      { field: diff[0], before: diff[1].changes[0], after: diff[1].changes[1] }
    end
  end
end<commit_msg>passes path for formulas<commit_after># frozen_string_literal: true

class V2::ChangeSerializer < V2::BaseSerializer
  set_type :change

  FORMULA_TYPES = {
    "activity" => "topic",
    "zone" => "zone",
    "payment" => "compound",
    "zone_activity" => "zone_topic",
    "package" => "set",
    "multi-entities" => "children"
  }

  attributes :created_at
  attributes :whodunnit
  attributes :author
  attributes :item_type
  attributes :item_id
  attributes :event
  
  attributes :diffs do |object, record_serialization_params|
    object.diffs.map do |diff|
      { field: diff[0], before: diff[1].changes[0], after: diff[1].changes[1] }
    end
  end

  attributes :path do |object, record_serialization_params|
    version = object
    object = instance_eval(version.item_type).find_by_id(version.item_id)
    if object && version.item_type == "Formula"
      formula = object
      kind = FORMULA_TYPES[formula.rule.kind]
      path = {
        parentId: formula.rule.package_id ? formula.rule.package_id : formula.rule.payment_rule_id,
        parentKind:  formula.rule.package_id ? "sets": "compounds",
        kind: kind + "_formulas",
        formulaId: object.id
      }
      path
    end 
  end
end
{'fraction_non_alphanumeric': 0.11330935251798561, 'fraction_numerical': 0.008393285371702638, 'mean_word_length': 3.636111111111111, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 9, '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': '6632025', 'n_tokens_mistral': 545, 'n_tokens_neox': 541, 'n_words': 123}