eco-helpers 3.0.20 → 3.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.idea/.gitignore +10 -0
- data/CHANGELOG.md +55 -5
- data/eco-helpers.gemspec +3 -3
- data/lib/eco/api/common/class_hierarchy.rb +6 -9
- data/lib/eco/api/common/loaders/case_base.rb +12 -4
- data/lib/eco/api/common/loaders/config/cli.rb +9 -0
- data/lib/eco/api/common/loaders/config/workflow/cases_extension.rb +53 -0
- data/lib/eco/api/common/loaders/config/workflow/mailer.rb +2 -14
- data/lib/eco/api/common/loaders/config/workflow.rb +4 -0
- data/lib/eco/api/common/loaders/config.rb +1 -0
- data/lib/eco/api/common/loaders/error_handler.rb +3 -2
- data/lib/eco/api/common/loaders/policy.rb +3 -2
- data/lib/eco/api/common/loaders/use_case/cli_identify.rb +28 -0
- data/lib/eco/api/common/loaders/use_case/target_model.rb +25 -0
- data/lib/eco/api/common/loaders/use_case/type.rb +37 -0
- data/lib/eco/api/common/loaders/use_case.rb +16 -43
- data/lib/eco/api/common/people/default_parsers/xls_parser.rb +1 -1
- data/lib/eco/api/common/session/logger/cache.rb +10 -4
- data/lib/eco/api/common/session/logger/channels.rb +41 -0
- data/lib/eco/api/common/session/logger.rb +9 -0
- data/lib/eco/api/error/handler.rb +6 -4
- data/lib/eco/api/error/handlers.rb +12 -5
- data/lib/eco/api/microcases/people/apply_changes/set_account/account_excluded.rb +34 -0
- data/lib/eco/api/microcases/people/apply_changes/set_account.rb +28 -0
- data/lib/eco/api/microcases/people/apply_changes/set_core/core_excluded.rb +28 -0
- data/lib/eco/api/microcases/people/apply_changes/set_core.rb +27 -0
- data/lib/eco/api/microcases/people/apply_changes/set_core_with_supervisor.rb +38 -0
- data/lib/eco/api/microcases/people/apply_changes/set_supervisor.rb +69 -0
- data/lib/eco/api/microcases/people/apply_changes.rb +19 -0
- data/lib/eco/api/microcases/people/fetch/with_each.rb +109 -0
- data/lib/eco/api/microcases/people/fetch/with_each_leaver.rb +33 -0
- data/lib/eco/api/microcases/people/fetch/with_each_present.rb +42 -0
- data/lib/eco/api/microcases/people/fetch/with_each_starter.rb +43 -0
- data/lib/eco/api/microcases/people/fetch/with_each_subordinate.rb +41 -0
- data/lib/eco/api/microcases/people/fetch/with_supervisor.rb +46 -0
- data/lib/eco/api/microcases/people/fetch.rb +23 -0
- data/lib/eco/api/microcases/people/integrity/fix_default_group.rb +39 -0
- data/lib/eco/api/microcases/people/integrity/fix_filter_tags.rb +55 -0
- data/lib/eco/api/microcases/people/integrity/refresh_default_tag.rb +32 -0
- data/lib/eco/api/microcases/people/integrity.rb +17 -0
- data/lib/eco/api/microcases/people/macro/take_email.rb +141 -0
- data/lib/eco/api/microcases/people/macro.rb +13 -0
- data/lib/eco/api/microcases/people/manage/cache.rb +36 -0
- data/lib/eco/api/microcases/people/manage/load.rb +90 -0
- data/lib/eco/api/microcases/people/manage/refresh.rb +59 -0
- data/lib/eco/api/microcases/people/manage/search.rb +118 -0
- data/lib/eco/api/microcases/people/manage.rb +19 -0
- data/lib/eco/api/microcases/people/preserve/default_tag.rb +29 -0
- data/lib/eco/api/microcases/people/preserve/filter_tags.rb +34 -0
- data/lib/eco/api/microcases/people/preserve/policy_groups.rb +36 -0
- data/lib/eco/api/microcases/people/preserve.rb +17 -0
- data/lib/eco/api/microcases/people.rb +21 -0
- data/lib/eco/api/microcases/person_update.rb +1 -1
- data/lib/eco/api/microcases/s3upload_targets.rb +1 -1
- data/lib/eco/api/microcases/with_each_contractor_present.rb +40 -0
- data/lib/eco/api/microcases.rb +3 -23
- data/lib/eco/api/organization/people/multiple_search_results.rb +48 -0
- data/lib/eco/api/organization/{people_similarity.rb → people/similarity.rb} +89 -72
- data/lib/eco/api/organization/people.rb +40 -66
- data/lib/eco/api/organization.rb +0 -1
- data/lib/eco/api/policies/policy.rb +7 -5
- data/lib/eco/api/policies.rb +9 -4
- data/lib/eco/api/session/batch/feedback/generate.rb +60 -0
- data/lib/eco/api/session/batch/feedback/getters.rb +28 -0
- data/lib/eco/api/session/batch/feedback/identifiers.rb +20 -0
- data/lib/eco/api/session/batch/feedback/job_dependencies.rb +45 -0
- data/lib/eco/api/session/batch/feedback/request_stat.rb +27 -0
- data/lib/eco/api/session/batch/feedback/request_stats.rb +270 -0
- data/lib/eco/api/session/batch/feedback.rb +45 -119
- data/lib/eco/api/session/batch/job/sets.rb +23 -0
- data/lib/eco/api/session/batch/job/type.rb +22 -0
- data/lib/eco/api/session/batch/job.rb +19 -18
- data/lib/eco/api/session/batch/jobs.rb +6 -2
- data/lib/eco/api/session/batch/launcher/mode_size.rb +1 -1
- data/lib/eco/api/session/batch/launcher/retry.rb +4 -4
- data/lib/eco/api/session/batch/launcher.rb +2 -2
- data/lib/eco/api/session/batch/policies.rb +4 -4
- data/lib/eco/api/session/batch/searcher.rb +2 -1
- data/lib/eco/api/session/batch.rb +0 -1
- data/lib/eco/api/session/config/workflow.rb +19 -9
- data/lib/eco/api/usecases/base_case/model.rb +54 -0
- data/lib/eco/api/usecases/base_case/type.rb +52 -0
- data/lib/eco/api/usecases/base_case.rb +5 -29
- data/lib/eco/api/usecases/base_io/chaining.rb +48 -0
- data/lib/eco/api/usecases/base_io/validations.rb +114 -0
- data/lib/eco/api/usecases/base_io.rb +65 -115
- data/lib/eco/api/usecases/cli/dsl.rb +3 -1
- data/lib/eco/api/usecases/default/people/treat/analyse_people_case.rb +7 -4
- data/lib/eco/api/usecases/default/people/treat/supers_cyclic_identify_case.rb +1 -3
- data/lib/eco/api/usecases/default/people/treat/supers_hierarchy_case.rb +1 -5
- data/lib/eco/api/usecases/default_cases/entries_to_csv_case.rb +2 -2
- data/lib/eco/api/usecases/default_cases/hris_case.rb +0 -2
- data/lib/eco/api/usecases/default_cases/to_csv_case.rb +3 -6
- data/lib/eco/api/usecases/graphql/base.rb +3 -2
- data/lib/eco/api/usecases/graphql/helpers/base/case_env.rb +1 -1
- data/lib/eco/api/usecases/graphql/helpers/base/error_handling.rb +3 -3
- data/lib/eco/api/usecases/graphql/helpers/contractors/base/load.rb +17 -0
- data/lib/eco/api/usecases/graphql/helpers/contractors/base.rb +8 -0
- data/lib/eco/api/usecases/graphql/helpers/contractors.rb +6 -0
- data/lib/eco/api/usecases/graphql/helpers/location/base.rb +5 -4
- data/lib/eco/api/usecases/graphql/helpers/location/command.rb +2 -2
- data/lib/eco/api/usecases/graphql/helpers.rb +1 -0
- data/lib/eco/api/usecases/graphql/samples/contractors/dsl.rb +5 -0
- data/lib/eco/api/usecases/graphql/samples/contractors.rb +17 -0
- data/lib/eco/api/usecases/graphql/samples/location/service/base.rb +1 -1
- data/lib/eco/api/usecases/graphql/samples/location.rb +1 -1
- data/lib/eco/api/usecases/graphql/samples.rb +1 -0
- data/lib/eco/api/usecases/ooze_samples/ooze_base_case.rb +0 -1
- data/lib/eco/api/usecases/ooze_samples/ooze_run_base_case.rb +8 -8
- data/lib/eco/api/usecases/use_case/chainer.rb +12 -0
- data/lib/eco/api/usecases/use_case.rb +32 -23
- data/lib/eco/api/usecases/use_case_chain/chaining.rb +88 -0
- data/lib/eco/api/usecases/use_case_chain.rb +17 -62
- data/lib/eco/api/usecases/use_case_io/chain.rb +24 -0
- data/lib/eco/api/usecases/use_case_io.rb +17 -22
- data/lib/eco/api/usecases.rb +12 -4
- data/lib/eco/assets.rb +1 -1
- data/lib/eco/cli/config/filters/people_filters.rb +6 -5
- data/lib/eco/cli/config/input.rb +6 -2
- data/lib/eco/cli/config/use_cases.rb +4 -2
- data/lib/eco/cli_default/input.rb +49 -29
- data/lib/eco/cli_default/options.rb +4 -1
- data/lib/eco/cli_default/people.rb +102 -47
- data/lib/eco/cli_default/people_filters.rb +5 -1
- data/lib/eco/cli_default/workflow.rb +149 -138
- data/lib/eco/data/mapper.rb +51 -19
- data/lib/eco/language/auxiliar_logger.rb +16 -3
- data/lib/eco/language/basic_logger.rb +1 -0
- data/lib/eco/language/methods/dsl_able.rb +3 -0
- data/lib/eco/version.rb +1 -1
- metadata +68 -33
- data/lib/eco/api/microcases/account_excluded.rb +0 -26
- data/lib/eco/api/microcases/core_excluded.rb +0 -20
- data/lib/eco/api/microcases/fix_default_group.rb +0 -33
- data/lib/eco/api/microcases/fix_filter_tags.rb +0 -49
- data/lib/eco/api/microcases/people_cache.rb +0 -30
- data/lib/eco/api/microcases/people_load.rb +0 -84
- data/lib/eco/api/microcases/people_refresh.rb +0 -53
- data/lib/eco/api/microcases/people_search.rb +0 -112
- data/lib/eco/api/microcases/preserve_default_tag.rb +0 -23
- data/lib/eco/api/microcases/preserve_filter_tags.rb +0 -28
- data/lib/eco/api/microcases/preserve_policy_groups.rb +0 -30
- data/lib/eco/api/microcases/refresh_default_tag.rb +0 -26
- data/lib/eco/api/microcases/set_account.rb +0 -18
- data/lib/eco/api/microcases/set_core.rb +0 -17
- data/lib/eco/api/microcases/set_core_with_supervisor.rb +0 -32
- data/lib/eco/api/microcases/set_supervisor.rb +0 -63
- data/lib/eco/api/microcases/take_email_from_account.rb +0 -129
- data/lib/eco/api/microcases/with_each.rb +0 -103
- data/lib/eco/api/microcases/with_each_leaver.rb +0 -27
- data/lib/eco/api/microcases/with_each_present.rb +0 -36
- data/lib/eco/api/microcases/with_each_starter.rb +0 -37
- data/lib/eco/api/microcases/with_each_subordinate.rb +0 -33
- data/lib/eco/api/microcases/with_supervisor.rb +0 -35
- data/lib/eco/api/session/batch/request_stats.rb +0 -266
@@ -0,0 +1,36 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
module People
|
5
|
+
module Preserve
|
6
|
+
module PolicyGroups
|
7
|
+
# Helper to preserve the original `policy_group_ids`.
|
8
|
+
# @note
|
9
|
+
# 1. It only works if the original value of `policy_group_ids` was **not** empty
|
10
|
+
# @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
|
11
|
+
# @param options [Hash] the options.
|
12
|
+
# @param keep_new [Boolean] tells if it should keep the new policy groups or get rid of them.
|
13
|
+
# @return [String] the final value of `policy_group_ids`.
|
14
|
+
def preserve_policy_groups(person, _options, keep_new: false)
|
15
|
+
return unless (account = person.account)
|
16
|
+
|
17
|
+
account.policy_group_ids.tap do
|
18
|
+
next unless account.as_update.key?('policy_group_ids')
|
19
|
+
next unless (original = person.original_doc.dig('account', 'policy_group_ids'))
|
20
|
+
next if original.empty?
|
21
|
+
|
22
|
+
if keep_new
|
23
|
+
person.account.policy_group_ids += original
|
24
|
+
else
|
25
|
+
person.account.policy_group_ids = original
|
26
|
+
end
|
27
|
+
|
28
|
+
return account.policy_group_ids
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative 'preserve/filter_tags'
|
2
|
+
require_relative 'preserve/default_tag'
|
3
|
+
require_relative 'preserve/policy_groups'
|
4
|
+
|
5
|
+
module Eco
|
6
|
+
module API
|
7
|
+
class MicroCases
|
8
|
+
module People
|
9
|
+
module Preserve
|
10
|
+
include FilterTags
|
11
|
+
include DefaultTag
|
12
|
+
include PolicyGroups
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative 'people/manage'
|
2
|
+
require_relative 'people/fetch'
|
3
|
+
require_relative 'people/apply_changes'
|
4
|
+
require_relative 'people/preserve'
|
5
|
+
require_relative 'people/integrity'
|
6
|
+
require_relative 'people/macro'
|
7
|
+
|
8
|
+
module Eco
|
9
|
+
module API
|
10
|
+
class MicroCases
|
11
|
+
module People
|
12
|
+
include Manage
|
13
|
+
include Fetch
|
14
|
+
include ApplyChanges
|
15
|
+
include Preserve
|
16
|
+
include Integrity
|
17
|
+
include Macro
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -7,7 +7,7 @@ module Eco
|
|
7
7
|
# @param context [String] main part of the message.
|
8
8
|
# @param reason [String] why are we updating now.
|
9
9
|
# @return [Boolean] `true` if it succeded to update, and `false` otherwise
|
10
|
-
def person_update!(person, context:
|
10
|
+
def person_update!(person, context: 'Session', reason: '')
|
11
11
|
log(:debug) {
|
12
12
|
"#{context}, going to \"#{reason}\".\nPerson: #{person_ref(person)}"
|
13
13
|
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Eco
|
2
|
+
module API
|
3
|
+
class MicroCases
|
4
|
+
# Finds those in `entries` that already exist in the organization (`people`)
|
5
|
+
# and `yield` s them one by one to the given block.
|
6
|
+
|
7
|
+
# @param entries [Eco::API::Common::ContractorEntities::Entries]: the input entries with the data.
|
8
|
+
# @param contractors [Eco::API::Organization::Contractors]: target existing _Contractors_ of the current update.
|
9
|
+
# @param options [Hash]: the options.
|
10
|
+
# @param log_new_record [Boolean]: log error message if an `entry` does not have match in `contractors`.
|
11
|
+
# @yield [entry, contractor]: yields the existing `contractor` elements from `entries`
|
12
|
+
# that are not included on the `contractors` list.
|
13
|
+
# @yield[:entry] [ContractorEntry]: the input entry with the data that should be used to update the contractor with.
|
14
|
+
# @yield[:contractor] [Ecoportal::API::V1::Contractor]: individual element from the collection of found `contractors`
|
15
|
+
|
16
|
+
# @return [Eco::API::Organization::Contractors]: the contractor collection found by the query.
|
17
|
+
|
18
|
+
|
19
|
+
def with_each_contractor_present(entries, contractors, options, log_new_record: false)
|
20
|
+
found = []
|
21
|
+
micro.with_each(entries, contractors, options) do |entry, contractor|
|
22
|
+
if contractor.new?
|
23
|
+
if log_new_record
|
24
|
+
log(:error) {
|
25
|
+
"This contractor does not exist: #{entry.to_s(:identify)}"
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
next
|
30
|
+
end
|
31
|
+
|
32
|
+
found << contractor
|
33
|
+
yield(entry, contractor) if block_given?
|
34
|
+
end
|
35
|
+
|
36
|
+
contractors.newFrom found
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/eco/api/microcases.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
module Eco
|
2
2
|
module API
|
3
3
|
class MicroCases < Eco::API::Common::Session::BaseSession
|
4
|
+
require_relative 'microcases/people'
|
5
|
+
include People
|
6
|
+
|
4
7
|
def micro
|
5
8
|
self
|
6
9
|
end
|
@@ -8,30 +11,7 @@ module Eco
|
|
8
11
|
end
|
9
12
|
end
|
10
13
|
|
11
|
-
require_relative 'microcases/account_excluded'
|
12
14
|
require_relative 'microcases/append_usergroups'
|
13
|
-
require_relative 'microcases/core_excluded'
|
14
|
-
require_relative 'microcases/fix_default_group'
|
15
|
-
require_relative 'microcases/fix_filter_tags'
|
16
|
-
require_relative 'microcases/people_cache'
|
17
|
-
require_relative 'microcases/people_load'
|
18
|
-
require_relative 'microcases/people_refresh'
|
19
|
-
require_relative 'microcases/people_search'
|
20
15
|
require_relative 'microcases/person_update'
|
21
|
-
require_relative 'microcases/preserve_filter_tags'
|
22
|
-
require_relative 'microcases/preserve_default_tag'
|
23
|
-
require_relative 'microcases/preserve_policy_groups'
|
24
|
-
require_relative 'microcases/set_account'
|
25
|
-
require_relative 'microcases/set_core_with_supervisor'
|
26
|
-
require_relative 'microcases/set_core'
|
27
|
-
require_relative 'microcases/refresh_default_tag'
|
28
16
|
require_relative 'microcases/s3upload_targets'
|
29
|
-
require_relative 'microcases/set_supervisor'
|
30
17
|
require_relative 'microcases/strict_search'
|
31
|
-
require_relative 'microcases/take_email_from_account'
|
32
|
-
require_relative 'microcases/with_each'
|
33
|
-
require_relative 'microcases/with_each_leaver'
|
34
|
-
require_relative 'microcases/with_each_present'
|
35
|
-
require_relative 'microcases/with_each_starter'
|
36
|
-
require_relative 'microcases/with_each_subordinate'
|
37
|
-
require_relative 'microcases/with_supervisor'
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module API
|
2
|
+
module Organization
|
3
|
+
class People
|
4
|
+
# Error class that allows to handle cases where multiple people were found for the same criterion.
|
5
|
+
# @note its main purpose to prevent the creation of duplicates or override information between different people.
|
6
|
+
class MultipleSearchResults < StandardError
|
7
|
+
attr_reader :candidates, :property
|
8
|
+
|
9
|
+
# @param msg [String] the basic message error.
|
10
|
+
# @param candiates [Array<Person>] the people that match the same search criterion.
|
11
|
+
# @param property [String] the property of the person model that triggered the error (base of the search criterion).
|
12
|
+
def initialize(msg, candidates: [], property: 'email')
|
13
|
+
@candidates = candidates
|
14
|
+
@property = property
|
15
|
+
super("#{msg} #{candidates_summary}")
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param with_index [Boolean] to add an index to each candidate description.
|
19
|
+
# @return [Array<String>] the `candidates` identified
|
20
|
+
def identify_candidates(with_index: false)
|
21
|
+
candidates.map.each_with_index do |person, i|
|
22
|
+
index = with_index ? "#{i}. " : ''
|
23
|
+
|
24
|
+
msg = '(no account)'
|
25
|
+
if person.account
|
26
|
+
msg = '(user)'
|
27
|
+
msg = '(new user)' if person.account_added?
|
28
|
+
end
|
29
|
+
|
30
|
+
"#{index}#{msg} #{person.identify}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Person] the `candidate` in the `index` position
|
35
|
+
def candidate(index)
|
36
|
+
candidates[index]
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def candidates_summary
|
42
|
+
lines = ["The following people have the same '#{property}':"]
|
43
|
+
lines.concat(identify_candidates(with_index: true)).join("\n ")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,20 +1,15 @@
|
|
1
|
-
module
|
2
|
-
module
|
3
|
-
|
4
|
-
|
1
|
+
module API
|
2
|
+
module Organization
|
3
|
+
class People
|
5
4
|
# Class to find out duplicates in the People Manager
|
6
5
|
#
|
7
6
|
# @attr_writer attribute [String, Proc, nil] the target attribute to be read.
|
8
|
-
class
|
7
|
+
class Similarity < Eco::API::Organization::People
|
9
8
|
include Eco::Data::FuzzyMatch
|
10
9
|
|
11
|
-
attr_accessor :attribute
|
12
|
-
|
13
10
|
# @!group Config
|
14
11
|
# @return [String, Proc, nil] the target attribute to be read.
|
15
|
-
|
16
|
-
@attribute = attr
|
17
|
-
end
|
12
|
+
attr_writer :attribute
|
18
13
|
|
19
14
|
def attribute
|
20
15
|
@attribute ||= :name
|
@@ -22,36 +17,35 @@ module Eco
|
|
22
17
|
|
23
18
|
# Returns the target value to analyse
|
24
19
|
# @param person [Ecoportal::API::V1::Person]
|
25
|
-
def item_value(
|
26
|
-
return
|
20
|
+
def item_value(item)
|
21
|
+
return attribute.call(item) if attribute.is_a?(Proc)
|
22
|
+
|
27
23
|
attr = attribute.to_sym
|
28
|
-
|
24
|
+
item.send(attr) if item.respond_to?(attr)
|
29
25
|
end
|
30
26
|
|
31
27
|
# Define the order or relevant of per user matches
|
32
|
-
# @param values[Array<Symbol>] the algorithms' results it should
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
28
|
+
# @param values[Array<Symbol>] the algorithms' results it should
|
29
|
+
# be ordered by:
|
30
|
+
# * Possible values: `:dice`, `:levenshtein`, `:jaro_winkler`,
|
31
|
+
# `:ngrams`, `:words_ngrams`, `:chars_position`
|
32
|
+
attr_writer :order
|
37
33
|
|
38
34
|
def order
|
39
|
-
@order ||= [
|
35
|
+
@order ||= %i[words_ngrams dice]
|
40
36
|
end
|
41
37
|
|
42
38
|
# Define the order or relevant of per user matches
|
43
39
|
# @param value [Float] the threshold that all of the algorithms should comply with
|
44
|
-
|
45
|
-
@threshold = value
|
46
|
-
end
|
40
|
+
attr_writer :threshold
|
47
41
|
|
48
42
|
def threshold
|
49
43
|
@threshold ||= 0.15
|
50
44
|
end
|
51
45
|
|
52
46
|
# Generates a new object with same config but different base `data`.
|
53
|
-
# @return [Eco::API::Organization::
|
54
|
-
def newFrom(data)
|
47
|
+
# @return [Eco::API::Organization::People::Similarity]
|
48
|
+
def newFrom(data) # rubocop:disable Naming/MethodName
|
55
49
|
super(data).tap do |simil|
|
56
50
|
simil.threshold = threshold
|
57
51
|
simil.order = order
|
@@ -67,47 +61,47 @@ module Eco
|
|
67
61
|
# @return [Hash] where `keys` are `email`s and `values` an `Array<Person>`
|
68
62
|
def repeated_emails
|
69
63
|
init_caches
|
70
|
-
@by_email.select do |
|
64
|
+
@by_email.select do |_email, people|
|
71
65
|
people.count > 1
|
72
66
|
end
|
73
67
|
end
|
74
68
|
|
75
69
|
# It returns all people with no name
|
76
|
-
# @return [Eco::API::Organization::
|
70
|
+
# @return [Eco::API::Organization::People::Similarity]
|
77
71
|
def unnamed
|
78
72
|
select do |person|
|
79
73
|
person.name.to_s.strip.length < 2
|
80
|
-
end.
|
74
|
+
end.then do |results|
|
81
75
|
newFrom(results)
|
82
76
|
end
|
83
77
|
end
|
84
78
|
|
85
79
|
# It returns all people with no name
|
86
|
-
# @return [Eco::API::Organization::
|
80
|
+
# @return [Eco::API::Organization::People::Similarity]
|
87
81
|
def named
|
88
82
|
reject do |person|
|
89
83
|
person.name.to_s.strip.length < 2
|
90
|
-
end.
|
84
|
+
end.then do |results|
|
91
85
|
newFrom(results)
|
92
86
|
end
|
93
87
|
end
|
94
88
|
|
95
89
|
# It returns all the entries with `attribute` empty
|
96
|
-
# @return [Eco::API::Organization::
|
90
|
+
# @return [Eco::API::Organization::People::Similarity]
|
97
91
|
def blank_attribute
|
98
92
|
select do |person|
|
99
93
|
item_value(person).to_s.strip.length < 2
|
100
|
-
end.
|
94
|
+
end.then do |results|
|
101
95
|
newFrom(results)
|
102
96
|
end
|
103
97
|
end
|
104
98
|
|
105
99
|
# It returns all the entries with `attribute` **n0t** empty
|
106
|
-
# @return [Eco::API::Organization::
|
100
|
+
# @return [Eco::API::Organization::People::Similarity]
|
107
101
|
def attribute_present
|
108
102
|
reject do |person|
|
109
103
|
item_value(person).to_s.strip.length < 2
|
110
|
-
end.
|
104
|
+
end.then do |results|
|
111
105
|
newFrom(results)
|
112
106
|
end
|
113
107
|
end
|
@@ -117,19 +111,26 @@ module Eco
|
|
117
111
|
# @!group Analisys starters
|
118
112
|
|
119
113
|
# Analyses People bases on `options`
|
120
|
-
# @param needle_read [Proc, Symbol] when the value to
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
114
|
+
# @param needle_read [Proc, Symbol] when the value to
|
115
|
+
# read from `needle` object is different to the `:read` (`attribute`).
|
116
|
+
# This allows to for example, facet `needle.name` (needle_read)
|
117
|
+
# against `haystack_item.details[alt_id]` (read).
|
118
|
+
# @param keep_empty [Boolean] to indicate if it should get
|
119
|
+
# rid of people with no results (based on threshold)
|
120
|
+
# @return [Hash] where the _keys_ are the people `id`s and
|
121
|
+
# the _values_ the `Eco::Data::FuzzyMatch::Results`
|
124
122
|
def analyse(needle_read: nil, keep_empty: false, **options)
|
125
|
-
options = { read:
|
126
|
-
total
|
123
|
+
options = { read: attribute }.merge(options)
|
124
|
+
total = count
|
125
|
+
i = 1
|
126
|
+
|
127
127
|
each_with_object({}) do |person, results|
|
128
128
|
needle_str = needle_read ? item_string(person, needle_read) : nil
|
129
129
|
results[person.id] = find_all_with_score(person, needle_str: needle_str, **options)
|
130
|
-
|
130
|
+
|
131
|
+
print_progress('Analysed', total, i)
|
131
132
|
i += 1
|
132
|
-
end.
|
133
|
+
end.then do |analysed|
|
133
134
|
analysed = clean_empty(analysed) unless keep_empty
|
134
135
|
#puts "... #{analysed.count} results after cleaning empty"
|
135
136
|
analysed
|
@@ -142,24 +143,28 @@ module Eco
|
|
142
143
|
|
143
144
|
# Gets a new instance object of this class, with only people in results
|
144
145
|
# @param analysed [Hash] where the _keys_ are the people `id`s and _values_ the `Eco::Data::FuzzyMatch::Results`
|
145
|
-
# @return [Eco::API::Organization::
|
146
|
-
def newSimilarity(analysed)
|
146
|
+
# @return [Eco::API::Organization::People::Similarity]
|
147
|
+
def newSimilarity(analysed) # rubocop:disable Naming/MethodName
|
147
148
|
newFrom(people_in_results(analysed))
|
148
149
|
end
|
149
150
|
|
150
151
|
def people_in_results(analysed)
|
151
152
|
analysed.each_with_object([]) do |(id, results), people|
|
152
|
-
|
153
|
+
# spot related
|
154
|
+
results.each_with_object([self[id]]) do |result, related|
|
153
155
|
related << result.match
|
156
|
+
end.each do |person|
|
157
|
+
next if people.include?(person)
|
158
|
+
|
159
|
+
people << person
|
154
160
|
end
|
155
|
-
related.each {|person| people << person unless people.include?(person)}
|
156
161
|
end
|
157
162
|
end
|
158
163
|
|
159
164
|
# Removes from results those that do not have similar entries
|
160
165
|
def clean_empty(analysed)
|
161
|
-
analysed.
|
162
|
-
|
166
|
+
analysed.reject do |_id, results|
|
167
|
+
results.empty?
|
163
168
|
end
|
164
169
|
end
|
165
170
|
|
@@ -169,10 +174,12 @@ module Eco
|
|
169
174
|
def with_analysed(analysed, keep_empty: false)
|
170
175
|
analysed.each_with_object({}) do |(id, results), reanalysed|
|
171
176
|
reanalysed[id] = yield(self[id], results)
|
172
|
-
end.
|
177
|
+
end.then do |reanalysed|
|
173
178
|
reanalysed = clean_empty(reanalysed) unless keep_empty
|
174
179
|
reanalysed
|
175
|
-
end.tap
|
180
|
+
end.tap do |out|
|
181
|
+
puts "with_analysed... returns #{out.count} records"
|
182
|
+
end
|
176
183
|
end
|
177
184
|
|
178
185
|
# Launches a reanalyis on `analysed` based on `options`
|
@@ -184,10 +191,12 @@ module Eco
|
|
184
191
|
end
|
185
192
|
|
186
193
|
# Reanalyses by using a block to treat the needle and item values
|
187
|
-
def reanalyse(analysed, msg:
|
188
|
-
options = { read:
|
189
|
-
total
|
190
|
-
|
194
|
+
def reanalyse(analysed, msg: 'Reanalysing', **options, &block)
|
195
|
+
options = { read: attribute }.merge(options)
|
196
|
+
total = analysed.count
|
197
|
+
i = 1
|
198
|
+
|
199
|
+
with_analysed(analysed) do |_person, results|
|
191
200
|
print_progress(msg, total, i)
|
192
201
|
i += 1
|
193
202
|
recalculate_results(results, &block)
|
@@ -196,18 +205,21 @@ module Eco
|
|
196
205
|
|
197
206
|
# Renalyses by ignoring matching words between the `needle` and those found in `results`
|
198
207
|
def ignore_matching_words(analysed, **options)
|
199
|
-
prompt =
|
200
|
-
|
208
|
+
prompt = 'Reanalysing by ignoring matching words'
|
209
|
+
|
210
|
+
reanalyse(analysed, msg: prompt, **options) do |needle_str, item_str, _needle, _item|
|
201
211
|
self.class.remove_matching_words(needle_str, item_str)
|
202
212
|
end
|
203
213
|
end
|
204
214
|
|
205
215
|
# Renalyses by ignoring matching words between the `needle` and those found in `results`
|
206
216
|
def ignore_matching_words_old(analysed, **options)
|
207
|
-
options = { read:
|
208
|
-
total
|
217
|
+
options = { read: attribute }.merge(options)
|
218
|
+
total = analysed.count
|
219
|
+
i = 1
|
220
|
+
|
209
221
|
with_analysed(analysed) do |person, results|
|
210
|
-
print_progress(
|
222
|
+
print_progress('Reanalysing by ignoring matching words', total, i)
|
211
223
|
i += 1
|
212
224
|
ignore_same_words_score(results, **options)
|
213
225
|
end
|
@@ -219,11 +231,12 @@ module Eco
|
|
219
231
|
|
220
232
|
# @return [String] well structured text
|
221
233
|
def report(analysed, format: :txt)
|
222
|
-
case
|
223
|
-
when
|
224
|
-
analysed.each_with_object(
|
225
|
-
|
226
|
-
out <<
|
234
|
+
case format
|
235
|
+
when :txt
|
236
|
+
analysed.each_with_object('') do |(id, results), out|
|
237
|
+
out << "#{self[id].identify}:\n "
|
238
|
+
out << results.results.map(&:print).join("\n ")
|
239
|
+
out << "\n"
|
227
240
|
end
|
228
241
|
end
|
229
242
|
end
|
@@ -233,7 +246,9 @@ module Eco
|
|
233
246
|
# 2. It then re-sorts and cuts based on `options`
|
234
247
|
# @return [Hash] where the _keys_ are the people `id`s and the _values_ the `Eco::Data::FuzzyMatch::Results`
|
235
248
|
def print_analysis(**options)
|
236
|
-
analysed
|
249
|
+
analysed = options[:analysed]
|
250
|
+
analysed ||= results_with_false_positives.analyse(**options)
|
251
|
+
|
237
252
|
analysed.each_with_object({}) do |(id, results), out|
|
238
253
|
puts report(analysed)
|
239
254
|
end
|
@@ -250,22 +265,24 @@ module Eco
|
|
250
265
|
private
|
251
266
|
|
252
267
|
def print_progress(msg, total, num)
|
253
|
-
return
|
254
|
-
puts
|
268
|
+
return unless total > 10
|
269
|
+
puts '' unless num > 1
|
270
|
+
|
255
271
|
@print_msg_len ||= 0
|
256
272
|
percent = (100 * num.to_f / total).round(1)
|
257
273
|
msg = " #{msg}: #{percent}% (#{num} of #{total})\r"
|
258
274
|
@print_msg_len = msg.length unless @print_msg_len > msg.length
|
275
|
+
|
259
276
|
print msg
|
260
277
|
$stdout.flush
|
261
|
-
if percent > 99.9
|
262
|
-
sleep(0.2)
|
263
|
-
print "#{" " * @print_msg_len}\r"
|
264
|
-
$stdout.flush
|
265
|
-
end
|
266
|
-
end
|
267
278
|
|
279
|
+
return unless percent > 99.9
|
268
280
|
|
281
|
+
sleep(0.2)
|
282
|
+
print "#{' ' * @print_msg_len}\r"
|
283
|
+
$stdout.flush
|
284
|
+
nil
|
285
|
+
end
|
269
286
|
end
|
270
287
|
end
|
271
288
|
end
|