<commit_before># == Schema Information
#
# Table name: lessons
#
#  id                        :uuid             not null, primary key
#  name                      :string           default(""), not null
#  topline                   :string           default(""), not null
#  summary                   :string           default(""), not null
#  learning_objectives       :string           is an Array
#  teacher_notes             :string           default(""), not null
#  assessment_criteria       :string           default(""), not null
#  assessment_criteria_files :string           default([]), is an Array
#  further_readings          :string           is an Array
#  standards                 :json
#  outcome_files             :string           default([]), is an Array
#  original_lesson           :uuid
#  state                     :integer          default("draft"), not null
#  published_at              :datetime
#  created_at                :datetime         not null
#  updated_at                :datetime         not null
#  key_concepts              :string           default([]), is an Array
#  key_vocabularies          :string           default([]), is an Array
#  key_formulas              :string           default([]), is an Array
#  fabrication_tools         :string           default([]), is an Array
#

class Lesson < ApplicationRecord
  enum state: [:hidden, :draft, :visible]

  # TODO - validate publishing only when all content is set

  # TODO - api view sections for content loading

  # TODO - top right buttons..
  # TODO - activity feed == history of lesson_tags

  # TODO - assessment criteria - input field and file format... ( assessment_criteria_docs :: JSON )

  before_create do # lessons initial state
    self.state = 0
  end


  #   validates :organization_exists
  def organization_exists # TODO - validate existece of organization from lesson_tags
    # not saved yet... so checking against query doesn't work *
  end


  has_many :steps, dependent: :destroy
  has_many :lesson_tags, dependent: :destroy

  has_many :lessons_standards
  has_many :standards, through: :lessons_standards



  # TODO - search for filter on lesson_tags


  def addAuthor(user_uuid)
    u = User.find(user_uuid)
    self.lesson_tags << LessonTag.new(taggable: u)
  end

  def getAuthors_id
    self.lesson_tags.where(taggable_type: "User").map {|x| y = x.taggable; y.id}
  end

  def authors
    self.lesson_tags.where(taggable_type: "User").map {|x| y = x.taggable; y}
  end

  def removeAuthor(user_uuid)
    self.lesson_tags.where(taggable_type: "User", taggable_id: user_uuid).destroy_all
  end

  def hasAuthor?(u_obj)
    self.lesson_tags.where(taggable_type: "User", taggable_id: u_obj.id).map {|x| y = x.taggable; y if u_obj.id == y.id}.compact.count > 0 ? true : false
  end


  def addOrg(organization_uuid)
    x = Organization.find(organization_uuid)
    self.lesson_tags << LessonTag.new(taggable: x)
  end

  def getOrgs_id
    self.lesson_tags.where(taggable_type: "Organization").map {|x| y = x.taggable; y.id}
  end

  def getOrgs
    self.lesson_tags.where(taggable_type: "Organization").map {|x| y = x.taggable; y}
  end

  def removeOrg(organization_uuid)
    self.lesson_tags.where(taggable_type: "Organization", taggable_id: organization_uuid).destroy_all
  end


  def teaching_range(start_range, end_range)
    if start_range.present? & end_range.present?
      self.lesson_tags.where(taggable_type: "TeachingRange").map {|x| x.destroy} #sanitize
      TeachingRange.setRangesForLesson(self.id, start_range, end_range)
    end
    range = self.lesson_tags.where(taggable_type: "TeachingRange").first
    {range_start: range.taggable.range_start, range_end: range.taggable.range_end} if range.present? && range.taggable.present?
  end
  def removeTeachingRange
    self.lesson_tags.where(taggable_type: "TeachingRange").destroy_all<commit_msg>default parameters on teaching range<commit_after># == Schema Information
#
# Table name: lessons
#
#  id                        :uuid             not null, primary key
#  name                      :string           default(""), not null
#  topline                   :string           default(""), not null
#  summary                   :string           default(""), not null
#  learning_objectives       :string           is an Array
#  teacher_notes             :string           default(""), not null
#  assessment_criteria       :string           default(""), not null
#  assessment_criteria_files :string           default([]), is an Array
#  further_readings          :string           is an Array
#  standards                 :json
#  outcome_files             :string           default([]), is an Array
#  original_lesson           :uuid
#  state                     :integer          default("draft"), not null
#  published_at              :datetime
#  created_at                :datetime         not null
#  updated_at                :datetime         not null
#  key_concepts              :string           default([]), is an Array
#  key_vocabularies          :string           default([]), is an Array
#  key_formulas              :string           default([]), is an Array
#  fabrication_tools         :string           default([]), is an Array
#

class Lesson < ApplicationRecord
  enum state: [:hidden, :draft, :visible]

  # TODO - validate publishing only when all content is set

  # TODO - api view sections for content loading

  # TODO - top right buttons..
  # TODO - activity feed == history of lesson_tags

  # TODO - assessment criteria - input field and file format... ( assessment_criteria_docs :: JSON )

  before_create do # lessons initial state
    self.state = 0
  end


  #   validates :organization_exists
  def organization_exists # TODO - validate existece of organization from lesson_tags
    # not saved yet... so checking against query doesn't work *
  end


  has_many :steps, dependent: :destroy
  has_many :lesson_tags, dependent: :destroy

  has_many :lessons_standards
  has_many :standards, through: :lessons_standards



  # TODO - search for filter on lesson_tags


  def addAuthor(user_uuid)
    u = User.find(user_uuid)
    self.lesson_tags << LessonTag.new(taggable: u)
  end

  def getAuthors_id
    self.lesson_tags.where(taggable_type: "User").map {|x| y = x.taggable; y.id}
  end

  def authors
    self.lesson_tags.where(taggable_type: "User").map {|x| y = x.taggable; y}
  end

  def removeAuthor(user_uuid)
    self.lesson_tags.where(taggable_type: "User", taggable_id: user_uuid).destroy_all
  end

  def hasAuthor?(u_obj)
    self.lesson_tags.where(taggable_type: "User", taggable_id: u_obj.id).map {|x| y = x.taggable; y if u_obj.id == y.id}.compact.count > 0 ? true : false
  end


  def addOrg(organization_uuid)
    x = Organization.find(organization_uuid)
    self.lesson_tags << LessonTag.new(taggable: x)
  end

  def getOrgs_id
    self.lesson_tags.where(taggable_type: "Organization").map {|x| y = x.taggable; y.id}
  end

  def getOrgs
    self.lesson_tags.where(taggable_type: "Organization").map {|x| y = x.taggable; y}
  end

  def removeOrg(organization_uuid)
    self.lesson_tags.where(taggable_type: "Organization", taggable_id: organization_uuid).destroy_all
  end


  def teaching_range(start_range = nil, end_range = nil)
    if start_range.present? & end_range.present?
      self.lesson_tags.where(taggable_type: "TeachingRange").map {|x| x.destroy} #sanitize
      TeachingRange.setRangesForLesson(self.id, start_range, end_range)
    end
    range = self.lesson_tags.where(taggable_type: "TeachingRange").first
    {range_start: range.taggable.range_start, range_end: range.taggable.range_end} if range.present? && range.taggable.present?
  end
  def removeTeachingRange
    self.lesson_tags.where(taggable_type: "TeachingRange").destroy_all
{'fraction_non_alphanumeric': 0.09599385639319083, 'fraction_numerical': 0.0005119672340970178, 'mean_word_length': 2.599263012436665, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, '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': '469715', 'n_tokens_mistral': 2461, 'n_tokens_neox': 2374, 'n_words': 621}