<commit_before>require 'rmagick'

module Tilestache
  require "open3"
  extend ActiveSupport::Concern

  def tilestache_seed
    secret = ENV['s3_tiles_secret_access_key'] || APP_CONFIG['s3_tiles_secret_access_key']
    key_id = ENV['s3_tiles_access_key_id'] || APP_CONFIG['s3_tiles_access_key_id']
    bucket_name = ENV['s3_tiles_bucket_name'] || APP_CONFIG['s3_tiles_bucket_name']
    bucket_path = ENV['s3_tiles_bucket_path'] || APP_CONFIG['s3_tiles_bucket_path']
    max_zoom = ENV['s3_tiles_max_zoom'] || APP_CONFIG['s3_tiles_max_zoom'] #i.e. 21

    if max_zoom == "" || max_zoom.to_i > 25
      max_zoom = 21
    end

    # ==============================================================================
    # Code to compute max_zoom
    # uses width of map in pixels, and width of map in degrees
    if self.class.to_s == "Map"
      warped_filename = self.warped_filename
    else
      warped_filename = self.maps.first.warped_filename
    end

    if warped_filename
      tile_width = 256.0
      im = Magick::Image.read(warped_filename).first
      bbox = RGeo::Cartesian::BoundingBox.create_from_geometry(self.bbox_geom)

      pixel_width = im.columns
      degree_width = bbox.x_span

      # TODO: OR FLOOR?!<commit_msg>:space_invader: using first map that is actually a map<commit_after>require 'rmagick'

module Tilestache
  require "open3"
  extend ActiveSupport::Concern

  def tilestache_seed
    secret = ENV['s3_tiles_secret_access_key'] || APP_CONFIG['s3_tiles_secret_access_key']
    key_id = ENV['s3_tiles_access_key_id'] || APP_CONFIG['s3_tiles_access_key_id']
    bucket_name = ENV['s3_tiles_bucket_name'] || APP_CONFIG['s3_tiles_bucket_name']
    bucket_path = ENV['s3_tiles_bucket_path'] || APP_CONFIG['s3_tiles_bucket_path']
    max_zoom = ENV['s3_tiles_max_zoom'] || APP_CONFIG['s3_tiles_max_zoom'] #i.e. 21

    if max_zoom == "" || max_zoom.to_i > 25
      max_zoom = 21
    end

    # ==============================================================================
    # Code to compute max_zoom
    # uses width of map in pixels, and width of map in degrees
    if self.class.to_s == "Map"
      warped_filename = self.warped_filename
    else
      warped_filename = self.maps.select({|m| m.map_type == :is_map}).first.warped_filename
    end

    if warped_filename
      tile_width = 256.0
      im = Magick::Image.read(warped_filename).first
      bbox = RGeo::Cartesian::BoundingBox.create_from_geometry(self.bbox_geom)

      pixel_width = im.columns
      degree_width = bbox.x_span

      # TODO: OR FLOOR?!
{'fraction_non_alphanumeric': 0.15876127009016072, 'fraction_numerical': 0.016464131713053703, 'mean_word_length': 4.165991902834008, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5695451', 'n_tokens_mistral': 937, 'n_tokens_neox': 894, 'n_words': 157}