<commit_before>require 'solar_integration/progress.rb'

class DataCollector
  attr_writer :current_point
  
  def initialize(grid)
    # implement this
  end
  
  def put(sun_state, irradiance)
    # implement this
  end
  
  def wrapup
    # implement this
  end
end

class TotalIrradianceSquares < DataCollector
  def initialize(grid)
    @group = Sketchup.active_model.entities.add_group
    
    progress = Progress.new(grid.points.length, 'Creating squares...')
    @squares = Hash.new
    grid.points.each do |p|
      # lift by 1cm so not to intersect with original face
      @squares[p] = Square.new(@group, p + grid.normal, grid.side1, grid.side2)
      progress.work
    end
  end
  
  def put(sun_state, irradiance)
    return if not irradiance
    @squares[@current_point].irradiance += irradiance
  end
  
  def wrapup
    minmax = @squares.values.collect{|s| s.irradiance}.minmax
    color_bar = ColorBar.new(*minmax)
    progress = Progress.new(@squares.length, 'Coloring squares...')
    @squares.values.each do |s|
      s.face.material=color_bar.to_color(s.irradiance)
      progress.work
    end
  end
end

# a square has a @center, @irradiance information and the reference
# to its visual representation @face
class Square
  attr_accessor :irradiance, :face
  
  def initialize(group, center, side1, side2)
    @irradiance = 0
    @center = center
    corner = center + Geom::Vector3d.linear_combination(-0.5,side1,-0.5,side2)
    @face = group.entities.add_face([corner, corner+side1, corner+side1+side2, corner+side2])
    @face.edges.each{|e|e.hidden=true}
  end
end

class ColorBar
  def initialize(min, max)
    @min = min
    @max = max
  end<commit_msg>use operations for square manipulation<commit_after>require 'solar_integration/progress.rb'

class DataCollector
  attr_writer :current_point
  
  def initialize(grid)
    raise 'need to implement'
  end
  
  def put(sun_state, irradiance)
    raise 'need to implement'
  end
  
  def wrapup
    raise 'need to implement'
  end
end

class TotalIrradianceSquares < DataCollector
  def initialize(grid)
    @group = grid.face.parent.entities.add_group
    
    progress = Progress.new(grid.points.length, 'Creating squares...')
    Sketchup.active_model.start_operation('Creating squares', true)
    @squares = Hash.new
    grid.points.each do |p|
      # lift by 1cm so not to intersect with original face
      @squares[p] = Square.new(@group, p + grid.normal, grid.side1, grid.side2)
      progress.work
    end
    Sketchup.active_model.commit_operation
  end
  
  def put(sun_state, irradiance)
    return if not irradiance
    @squares[@current_point].irradiance += irradiance
  end
  
  def wrapup
    minmax = @squares.values.collect{|s| s.irradiance}.minmax
    color_bar = ColorBar.new(*minmax)
    progress = Progress.new(@squares.length, 'Coloring squares...')
    Sketchup.active_model.start_operation('Coloring squares', true)
    @squares.values.each do |s|
      s.face.material=color_bar.to_color(s.irradiance)
      progress.work
    end
    Sketchup.active_model.commit_operation
  end
end

# a square has a @center, @irradiance information and the reference
# to its visual representation @face
class Square
  attr_accessor :irradiance, :face
  
  def initialize(group, center, side1, side2)
    @irradiance = 0
    @center = center
    corner = center + Geom::Vector3d.linear_combination(-0.5,side1,-0.5,side2)
    @face = group.entities.add_face([corner, corner+side1, corner+side1+side2, corner+side2])
    @face.edges.each{|e|e.hidden=true}
  end
end

class ColorBar
  def initialize(min, max)
    @min = min
    @max = max
  end
{'fraction_non_alphanumeric': 0.10129369666941922, 'fraction_numerical': 0.009358656757500689, 'mean_word_length': 3.4588957055214724, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3345819', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1212, 'n_words': 291}