<commit_before># frozen_string_literal: true

# == Schema Information
#
# Table name: reports
#
#  id                   :integer          not null, primary key
#  author_id            :integer
#  file_name            :string
#  file_description     :text
#  configs              :text
#  sample_settings      :text
#  reaction_settings    :text
#  objects              :text
#  img_format           :string
#  file_path            :string
#  generated_at         :datetime
#  deleted_at           :datetime
#  created_at           :datetime         not null
#  updated_at           :datetime         not null
#  template             :string           default("standard")
#  mol_serials          :text             default([])
#  si_reaction_settings :text             default({"Name"=>true, "CAS"=>true, "Formula"=>true, "Smiles"=>true, "InCHI"=>true, "Molecular Mass"=>true, "Exact Mass"=>true, "EA"=>true})
#  prd_atts             :text             default([])
#  report_templates_id  :integer
#
# Indexes
#
#  index_reports_on_author_id            (author_id)
#  index_reports_on_file_name            (file_name)
#  index_reports_on_report_templates_id  (report_templates_id)
#

class Report < ApplicationRecord
  acts_as_paranoid

  serialize :configs, Hash
  serialize :sample_settings, Hash
  serialize :reaction_settings, Hash
  serialize :si_reaction_settings, Hash
  serialize :objects, Array
  serialize :mol_serials, Array
  serialize :prd_atts, Array

  has_many :reports_users
  has_many :users, through: :reports_users
  has_many :attachments, as: :attachable
  belongs_to :report_templates, optional: true

  default_scope { includes(:reports_users) }

  after_destroy :delete_archive
  after_destroy :delete_job

  def create_docx
    template = self.template

    if report_templates_id
      report_template = ReportTemplate.includes(:attachment).find(report_templates_id)
      template = report_template.report_type
      tpl_path = if report_template.attachment
                   report_template.attachment.store.path<commit_msg>Report: fall back to default template if entry not found<commit_after># frozen_string_literal: true

# == Schema Information
#
# Table name: reports
#
#  id                   :integer          not null, primary key
#  author_id            :integer
#  file_name            :string
#  file_description     :text
#  configs              :text
#  sample_settings      :text
#  reaction_settings    :text
#  objects              :text
#  img_format           :string
#  file_path            :string
#  generated_at         :datetime
#  deleted_at           :datetime
#  created_at           :datetime         not null
#  updated_at           :datetime         not null
#  template             :string           default("standard")
#  mol_serials          :text             default([])
#  si_reaction_settings :text             default({"Name"=>true, "CAS"=>true, "Formula"=>true, "Smiles"=>true, "InCHI"=>true, "Molecular Mass"=>true, "Exact Mass"=>true, "EA"=>true})
#  prd_atts             :text             default([])
#  report_templates_id  :integer
#
# Indexes
#
#  index_reports_on_author_id            (author_id)
#  index_reports_on_file_name            (file_name)
#  index_reports_on_report_templates_id  (report_templates_id)
#

class Report < ApplicationRecord
  acts_as_paranoid

  serialize :configs, Hash
  serialize :sample_settings, Hash
  serialize :reaction_settings, Hash
  serialize :si_reaction_settings, Hash
  serialize :objects, Array
  serialize :mol_serials, Array
  serialize :prd_atts, Array

  has_many :reports_users
  has_many :users, through: :reports_users
  has_many :attachments, as: :attachable
  belongs_to :report_templates, optional: true

  default_scope { includes(:reports_users) }

  after_destroy :delete_archive
  after_destroy :delete_job

  def create_docx
    template = self.template

    if ReportTemplate.where(id: report_templates_id).present?
      report_template = ReportTemplate.includes(:attachment).find(report_templates_id)
      template = report_template.report_type
      tpl_path = if report_template.attachment
                   report_template.attachment.store.path
{'fraction_non_alphanumeric': 0.08305409286740068, 'fraction_numerical': 0.0, 'mean_word_length': 2.7547169811320753, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '2088627', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1206, 'n_words': 275}