class Eco::API::UseCases::DefaultCases::AnalysePeople < Eco::API::Common::Loaders::UseCase name "analyse-people" type :export attr_reader :session, :people, :options def main(people, session, options, usecase) @session = session; @options = options; @people = people save!(analysis) end private def analysis analytics.attribute = :name analysed = analytics.analyse({ threshold: 0.20, order: [:average, :dice] }) analytics.re_analyse(analysed, threshold: 0.5, order: [:average]) end def analytics @analytics ||= people.analytics end def file @file ||= options.dig(:output, :file) || "analytics.txt" end def save!(analysed) if analysed.empty? session.logger.info("There were results identified!!") return end ext = File.extname(file).downcase.delete(".") File.open(file, "w") do |fd| if ext == "txt" fd << analytics.analysis(analysed, format: :txt) elsif ext == "html" puts "html is still not supported" exit(1) elsif ext == "json" puts "json is still not supported" exit(1) end end end end