<commit_before>require 'sinatra/base'
require 'magickly'
require 'image_size'

# thanks to http://therantsandraves.com/?p=602 for the 'staches
MUSTACHE_FILENAME = File.expand_path(File.join('public', 'images', 'mustache_03.png'))
MUSTACHE_WIDTH, MUSTACHE_HEIGHT = ImageSize.new(File.new(MUSTACHE_FILENAME)).get_size

FACE_POS_ATTRS = ['center', 'eye_left', 'eye_right', 'mouth_left', 'mouth_center', 'mouth_right', 'nose']

Magickly.dragonfly.configure do |c|
  c.analyser.add :face_data do |temp_object|
    Mustachio.face_client.faces_detect(:file => temp_object.file)['photos'].first
  end
  
  c.analyser.add :face_data_as_px do |temp_object|
    data = Mustachio.face_client.faces_detect(:file => temp_object.file)['photos'].first # TODO use #face_data
    FACE_POS_ATTRS.each do |pos_attr|
      data['tags'].map! do |face|
        face[pos_attr]['x'] *= (data['width'] / 100.0)
        face[pos_attr]['y'] *= (data['height'] / 100.0)
        face
      end
    end
    
    data
  end
  
  c.job :mustachify do
    photo_data = @job.face_data_as_px<commit_msg>ignore attributes to hopefully make detection faster<commit_after>require 'sinatra/base'
require 'magickly'
require 'image_size'

# thanks to http://therantsandraves.com/?p=602 for the 'staches
MUSTACHE_FILENAME = File.expand_path(File.join('public', 'images', 'mustache_03.png'))
MUSTACHE_WIDTH, MUSTACHE_HEIGHT = ImageSize.new(File.new(MUSTACHE_FILENAME)).get_size

FACE_POS_ATTRS = ['center', 'eye_left', 'eye_right', 'mouth_left', 'mouth_center', 'mouth_right', 'nose']

Magickly.dragonfly.configure do |c|
  c.analyser.add :face_data do |temp_object|
    Mustachio.face_client.faces_detect(:file => temp_object.file, :attributes => 'none')['photos'].first
  end
  
  c.analyser.add :face_data_as_px do |temp_object|
    data = Mustachio.face_client.faces_detect(:file => temp_object.file, :attributes => 'none')['photos'].first # TODO use #face_data
    FACE_POS_ATTRS.each do |pos_attr|
      data['tags'].map! do |face|
        face[pos_attr]['x'] *= (data['width'] / 100.0)
        face[pos_attr]['y'] *= (data['height'] / 100.0)
        face
      end
    end
    
    data
  end
  
  c.job :mustachify do
    photo_data = @job.face_data_as_px
{'fraction_non_alphanumeric': 0.14781433077963047, 'fraction_numerical': 0.011716989634970707, 'mean_word_length': 4.427872860635697, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2790892', 'n_tokens_mistral': 839, 'n_tokens_neox': 810, 'n_words': 147}