Sync of the branch

This commit is contained in:
Senad Uka
2020-06-01 18:59:15 +02:00
parent 858fafc3c5
commit 3690268f83
11 changed files with 199 additions and 52 deletions

View File

@@ -3,6 +3,7 @@ require_relative "./brayniac_ai/aws_request_signing"
require_relative "./brayniac_ai/aws_signed_connection"
require_relative "./brayniac_ai/base"
require_relative "./brayniac_ai/appearance_release_matching"
require_relative "./brayniac_ai/audio_recognition"
require_relative "./brayniac_ai/collection"
require_relative "./brayniac_ai/document_analysis"

View File

@@ -0,0 +1,64 @@
# frozen_string_literal: true
module BrayniacAI
class AppearanceReleaseMatching
class << self
def match_attachments(request_data)
# TODO: Send request with request_data and receive real response
mock_response request_data
end
private
def mock_response(request_data)
attachments = request_data[:files]
pdfs = []
images = []
matches = []
errors = []
# Use first file for the error entry
first_attachment = attachments.shift
unless first_attachment.nil?
errors << { file: first_attachment, error_code: 1 }
end
attachments.each do |attachment|
blob = ActiveStorage::Blob.find_signed attachment
next if blob.nil?
if blob.image?
images << attachment
else
pdfs << attachment
end
end
# Create pairs of matches and single headshot/contract after pairs are exhausted
more_pdfs = pdfs.length > images.length
pairs = more_pdfs ? pdfs.zip(images) : images.zip(pdfs)
pairs.each do |pair_element1, pair_element2|
if more_pdfs
pdf = pair_element1
image = pair_element2
else
pdf = pair_element2
image = pair_element1
end
if pdf.nil? || image.nil?
matches << { headshot: image } if pdf.nil?
matches << { contract: pdf } if image.nil?
else
matches << { headshot: image, contract: pdf, identifier: '' }
end
end
{
request_id: request_data[:request_id],
matches: matches,
errors: errors
}
end
end
end
end