atlas_engine 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +123 -0
- data/Rakefile +20 -0
- data/app/assets/config/atlas_engine_manifest.js +3 -0
- data/app/assets/stylesheets/atlas_engine/application.css +15 -0
- data/app/concerns/atlas_engine/handles_blob.rb +26 -0
- data/app/concerns/atlas_engine/handles_interruption.rb +22 -0
- data/app/controllers/atlas_engine/application_controller.rb +7 -0
- data/app/controllers/atlas_engine/connectivity_controller.rb +21 -0
- data/app/controllers/atlas_engine/country_imports_controller.rb +73 -0
- data/app/controllers/atlas_engine/graphql_controller.rb +59 -0
- data/app/countries/atlas_engine/ar/country_profile.yml +9 -0
- data/app/countries/atlas_engine/at/address_importer/corrections/open_address/city_corrector.rb +23 -0
- data/app/countries/atlas_engine/at/country_profile.yml +24 -0
- data/app/countries/atlas_engine/at/index_configuration.yml +63 -0
- data/app/countries/atlas_engine/at/synonyms.yml +6 -0
- data/app/countries/atlas_engine/at/validation_transcriber/address_parser.rb +58 -0
- data/app/countries/atlas_engine/au/address_importer/open_address/filter.rb +26 -0
- data/app/countries/atlas_engine/au/address_importer/open_address/mapper.rb +41 -0
- data/app/countries/atlas_engine/au/country_profile.yml +13 -0
- data/app/countries/atlas_engine/au/synonyms.yml +209 -0
- data/app/countries/atlas_engine/au/validation_transcriber/address_parser.rb +121 -0
- data/app/countries/atlas_engine/be/country_profile.yml +12 -0
- data/app/countries/atlas_engine/bm/address_importer/corrections/open_address/city_alias_corrector.rb +38 -0
- data/app/countries/atlas_engine/bm/address_importer/open_address/mapper.rb +40 -0
- data/app/countries/atlas_engine/bm/country_profile.yml +12 -0
- data/app/countries/atlas_engine/br/country_profile.yml +4 -0
- data/app/countries/atlas_engine/ca/country_profile.yml +7 -0
- data/app/countries/atlas_engine/ca/synonyms.yml +1615 -0
- data/app/countries/atlas_engine/ch/address_importer/corrections/open_address/city_corrector.rb +29 -0
- data/app/countries/atlas_engine/ch/address_importer/corrections/open_address/locale_corrector.rb +74 -0
- data/app/countries/atlas_engine/ch/address_importer/open_address/mapper.rb +40 -0
- data/app/countries/atlas_engine/ch/country_profile.yml +15 -0
- data/app/countries/atlas_engine/ch/locales/de/country_profile.yml +15 -0
- data/app/countries/atlas_engine/ch/locales/de/index_configuration.yml +63 -0
- data/app/countries/atlas_engine/ch/locales/de/synonyms.yml +7 -0
- data/app/countries/atlas_engine/ch/locales/fr/synonyms.yml +21 -0
- data/app/countries/atlas_engine/cz/country_profile.yml +6 -0
- data/app/countries/atlas_engine/de/country_profile.yml +19 -0
- data/app/countries/atlas_engine/de/index_configuration.yml +64 -0
- data/app/countries/atlas_engine/de/synonyms.yml +2 -0
- data/app/countries/atlas_engine/de/validation_transcriber/address_parser.rb +19 -0
- data/app/countries/atlas_engine/dk/country_profile.yml +6 -0
- data/app/countries/atlas_engine/dk/synonyms.yml +3 -0
- data/app/countries/atlas_engine/dk/validation_transcriber/address_parser.rb +21 -0
- data/app/countries/atlas_engine/fo/country_profile.yml +5 -0
- data/app/countries/atlas_engine/fr/address_importer/corrections/open_address/city_corrector.rb +28 -0
- data/app/countries/atlas_engine/fr/country_profile.yml +13 -0
- data/app/countries/atlas_engine/fr/synonyms.yml +21 -0
- data/app/countries/atlas_engine/fr/validation_transcriber/address_parser.rb +34 -0
- data/app/countries/atlas_engine/gb/address_validation/es/query_builder.rb +98 -0
- data/app/countries/atlas_engine/gb/country_profile.yml +10 -0
- data/app/countries/atlas_engine/gb/validation_transcriber/full_address_parser.rb +164 -0
- data/app/countries/atlas_engine/gb/validation_transcriber/parsed_address.rb +120 -0
- data/app/countries/atlas_engine/gg/address_validation/validators/full_address/restrictions/unsupported_city.rb +39 -0
- data/app/countries/atlas_engine/gg/country_profile.yml +7 -0
- data/app/countries/atlas_engine/ie/country_profile.yml +3 -0
- data/app/countries/atlas_engine/it/address_importer/corrections/open_address/city_corrector.rb +27 -0
- data/app/countries/atlas_engine/it/address_importer/corrections/open_address/province_corrector.rb +29 -0
- data/app/countries/atlas_engine/it/address_importer/open_address/mapper.rb +42 -0
- data/app/countries/atlas_engine/it/country_profile.yml +11 -0
- data/app/countries/atlas_engine/jp/address_validation/es/data_mapper.rb +63 -0
- data/app/countries/atlas_engine/jp/country_profile.yml +6 -0
- data/app/countries/atlas_engine/kr/address_importer/open_address/mapper.rb +41 -0
- data/app/countries/atlas_engine/kr/country_profile.yml +11 -0
- data/app/countries/atlas_engine/li/address_importer/corrections/open_address/city_corrector.rb +25 -0
- data/app/countries/atlas_engine/li/country_profile.yml +21 -0
- data/app/countries/atlas_engine/li/index_configuration.yml +63 -0
- data/app/countries/atlas_engine/li/synonyms.yml +6 -0
- data/app/countries/atlas_engine/lt/country_profile.yml +6 -0
- data/app/countries/atlas_engine/lt/synonyms.yml +7 -0
- data/app/countries/atlas_engine/lt/validation_transcriber/address_parser.rb +24 -0
- data/app/countries/atlas_engine/lu/address_importer/corrections/open_address/locale_corrector.rb +54 -0
- data/app/countries/atlas_engine/lu/country_profile.yml +12 -0
- data/app/countries/atlas_engine/nl/address_importer/corrections/open_address/city_corrector.rb +25 -0
- data/app/countries/atlas_engine/nl/country_profile.yml +18 -0
- data/app/countries/atlas_engine/nl/index_configuration.yml +52 -0
- data/app/countries/atlas_engine/nl/synonyms.yml +92 -0
- data/app/countries/atlas_engine/nl/validation_transcriber/address_parser.rb +85 -0
- data/app/countries/atlas_engine/no/country_profile.yml +5 -0
- data/app/countries/atlas_engine/nz/country_profile.yml +3 -0
- data/app/countries/atlas_engine/pl/country_profile.yml +5 -0
- data/app/countries/atlas_engine/pl/validation_transcriber/address_parser.rb +19 -0
- data/app/countries/atlas_engine/pt/address_importer/corrections/open_address/city_corrector.rb +32 -0
- data/app/countries/atlas_engine/pt/address_importer/open_address/mapper.rb +39 -0
- data/app/countries/atlas_engine/pt/country_profile.yml +10 -0
- data/app/countries/atlas_engine/pt/synonyms.yml +7 -0
- data/app/countries/atlas_engine/sa/country_profile.yml +10 -0
- data/app/countries/atlas_engine/se/country_profile.yml +5 -0
- data/app/countries/atlas_engine/tt/address_importer/open_address/mapper.rb +38 -0
- data/app/countries/atlas_engine/tt/country_profile.yml +7 -0
- data/app/countries/atlas_engine/us/country_profile.yml +12 -0
- data/app/countries/atlas_engine/us/synonyms.yml +350 -0
- data/app/graphql/atlas_engine/errors/locale_unsupported_error.rb +17 -0
- data/app/graphql/atlas_engine/schema.graphql +1293 -0
- data/app/graphql/atlas_engine/schema.rb +23 -0
- data/app/graphql/atlas_engine/types/address_validation/address_input.rb +51 -0
- data/app/graphql/atlas_engine/types/address_validation/concern_type.rb +20 -0
- data/app/graphql/atlas_engine/types/address_validation/enums/concern_enum.rb +15 -0
- data/app/graphql/atlas_engine/types/address_validation/field_type.rb +15 -0
- data/app/graphql/atlas_engine/types/address_validation/suggestion_type.rb +21 -0
- data/app/graphql/atlas_engine/types/base_argument.rb +9 -0
- data/app/graphql/atlas_engine/types/base_enum.rb +9 -0
- data/app/graphql/atlas_engine/types/base_field.rb +10 -0
- data/app/graphql/atlas_engine/types/base_input_object.rb +9 -0
- data/app/graphql/atlas_engine/types/base_interface.rb +10 -0
- data/app/graphql/atlas_engine/types/base_object.rb +9 -0
- data/app/graphql/atlas_engine/types/base_scalar.rb +9 -0
- data/app/graphql/atlas_engine/types/base_union.rb +9 -0
- data/app/graphql/atlas_engine/types/matching_strategy_type.rb +12 -0
- data/app/graphql/atlas_engine/types/mutation_type.rb +9 -0
- data/app/graphql/atlas_engine/types/query_type.rb +61 -0
- data/app/graphql/atlas_engine/types/validation_supported_country.rb +12 -0
- data/app/graphql/atlas_engine/types/validation_type.rb +22 -0
- data/app/helpers/atlas_engine/address_importer/import_log_helper.rb +66 -0
- data/app/helpers/atlas_engine/application_helper.rb +7 -0
- data/app/helpers/atlas_engine/locale_format_helper.rb +40 -0
- data/app/helpers/atlas_engine/log_base.rb +32 -0
- data/app/helpers/atlas_engine/log_helper.rb +24 -0
- data/app/helpers/atlas_engine/metrics_helper.rb +25 -0
- data/app/jobs/atlas_engine/address_importer/clear_records_job.rb +39 -0
- data/app/jobs/atlas_engine/address_importer/open_address/geo_json_import_job.rb +212 -0
- data/app/jobs/atlas_engine/address_importer/open_address/geo_json_import_launcher_job.rb +67 -0
- data/app/jobs/atlas_engine/address_importer/open_address/prepares_geo_json_file.rb +41 -0
- data/app/jobs/atlas_engine/address_importer/resumable_import_job.rb +49 -0
- data/app/jobs/atlas_engine/address_importer/street_backfill_job.rb +63 -0
- data/app/jobs/atlas_engine/application_job.rb +10 -0
- data/app/jobs/atlas_engine/concerns/address_importer/handles_errors.rb +43 -0
- data/app/lib/atlas_engine/concern_formatter.rb +40 -0
- data/app/lib/atlas_engine/restrictions/base.rb +20 -0
- data/app/lib/atlas_engine/restrictions/unsupported_script.rb +31 -0
- data/app/lib/atlas_engine/validation_transcriber/address_parser_base.rb +201 -0
- data/app/lib/atlas_engine/validation_transcriber/address_parser_factory.rb +27 -0
- data/app/lib/atlas_engine/validation_transcriber/address_parser_north_america.rb +39 -0
- data/app/lib/atlas_engine/validation_transcriber/address_parser_oceanic.rb +17 -0
- data/app/lib/atlas_engine/validation_transcriber/address_parser_preprocessor.rb +132 -0
- data/app/lib/atlas_engine/validation_transcriber/address_parsing_helper.rb +38 -0
- data/app/lib/atlas_engine/validation_transcriber/address_parsings.rb +54 -0
- data/app/lib/atlas_engine/validation_transcriber/constants.rb +50 -0
- data/app/lib/atlas_engine/validation_transcriber/english_street_parser.rb +59 -0
- data/app/lib/atlas_engine/validation_transcriber/formatter.rb +46 -0
- data/app/lib/atlas_engine/validation_transcriber/french_street_parser.rb +50 -0
- data/app/lib/atlas_engine/validation_transcriber/province_code_normalizer.rb +45 -0
- data/app/lib/atlas_engine/validation_transcriber/street_parser.rb +18 -0
- data/app/lib/atlas_engine/validation_transcriber/zip_normalizer.rb +23 -0
- data/app/mailers/atlas_engine/application_mailer.rb +9 -0
- data/app/models/atlas_engine/address_importer/corrections/corrector.rb +33 -0
- data/app/models/atlas_engine/address_importer/import_events_notifier/base.rb +35 -0
- data/app/models/atlas_engine/address_importer/import_events_notifier/notifier.rb +26 -0
- data/app/models/atlas_engine/address_importer/open_address/default_mapper.rb +46 -0
- data/app/models/atlas_engine/address_importer/open_address/feature_helper.rb +110 -0
- data/app/models/atlas_engine/address_importer/open_address/filter.rb +17 -0
- data/app/models/atlas_engine/address_importer/open_address/loader.rb +27 -0
- data/app/models/atlas_engine/address_importer/open_address/transformer.rb +39 -0
- data/app/models/atlas_engine/address_importer/open_address.rb +10 -0
- data/app/models/atlas_engine/address_importer/validation/base_validator.rb +86 -0
- data/app/models/atlas_engine/address_importer/validation/default_validator.rb +27 -0
- data/app/models/atlas_engine/address_importer/validation/field_validations/city.rb +47 -0
- data/app/models/atlas_engine/address_importer/validation/field_validations/interface.rb +29 -0
- data/app/models/atlas_engine/address_importer/validation/field_validations/province.rb +73 -0
- data/app/models/atlas_engine/address_importer/validation/field_validations/zip.rb +84 -0
- data/app/models/atlas_engine/address_importer/validation/validator.rb +17 -0
- data/app/models/atlas_engine/address_importer/validation/wrapper.rb +70 -0
- data/app/models/atlas_engine/address_number.rb +36 -0
- data/app/models/atlas_engine/address_number_range.rb +200 -0
- data/app/models/atlas_engine/address_validation/abstract_address.rb +49 -0
- data/app/models/atlas_engine/address_validation/address.rb +47 -0
- data/app/models/atlas_engine/address_validation/candidate.rb +109 -0
- data/app/models/atlas_engine/address_validation/candidate_tuple.rb +15 -0
- data/app/models/atlas_engine/address_validation/concern.rb +74 -0
- data/app/models/atlas_engine/address_validation/concern_producer.rb +19 -0
- data/app/models/atlas_engine/address_validation/concern_queue.rb +20 -0
- data/app/models/atlas_engine/address_validation/concern_record.rb +122 -0
- data/app/models/atlas_engine/address_validation/datastore_base.rb +27 -0
- data/app/models/atlas_engine/address_validation/errors.rb +13 -0
- data/app/models/atlas_engine/address_validation/es/candidate_selector.rb +70 -0
- data/app/models/atlas_engine/address_validation/es/data_mappers/decompounding_data_mapper.rb +39 -0
- data/app/models/atlas_engine/address_validation/es/data_mappers/default_data_mapper.rb +110 -0
- data/app/models/atlas_engine/address_validation/es/datastore.rb +229 -0
- data/app/models/atlas_engine/address_validation/es/default_query_builder.rb +30 -0
- data/app/models/atlas_engine/address_validation/es/query_builder.rb +160 -0
- data/app/models/atlas_engine/address_validation/es/term_vectors.rb +78 -0
- data/app/models/atlas_engine/address_validation/es/validators/full_address.rb +123 -0
- data/app/models/atlas_engine/address_validation/es/validators/full_address_street.rb +18 -0
- data/app/models/atlas_engine/address_validation/es/validators/restriction_evaluator.rb +37 -0
- data/app/models/atlas_engine/address_validation/field.rb +30 -0
- data/app/models/atlas_engine/address_validation/full_address_validator_base.rb +27 -0
- data/app/models/atlas_engine/address_validation/log_emitter.rb +66 -0
- data/app/models/atlas_engine/address_validation/matching_strategies.rb +16 -0
- data/app/models/atlas_engine/address_validation/normalizer.rb +38 -0
- data/app/models/atlas_engine/address_validation/predicate_pipeline.rb +80 -0
- data/app/models/atlas_engine/address_validation/request.rb +12 -0
- data/app/models/atlas_engine/address_validation/result.rb +154 -0
- data/app/models/atlas_engine/address_validation/runs_validation.rb +16 -0
- data/app/models/atlas_engine/address_validation/session.rb +47 -0
- data/app/models/atlas_engine/address_validation/statsd_emitter.rb +72 -0
- data/app/models/atlas_engine/address_validation/strategies.rb +10 -0
- data/app/models/atlas_engine/address_validation/suggestion.rb +97 -0
- data/app/models/atlas_engine/address_validation/token/comparator.rb +44 -0
- data/app/models/atlas_engine/address_validation/token/comparison.rb +76 -0
- data/app/models/atlas_engine/address_validation/token/sequence/comparator.rb +158 -0
- data/app/models/atlas_engine/address_validation/token/sequence/comparison.rb +166 -0
- data/app/models/atlas_engine/address_validation/token/sequence.rb +147 -0
- data/app/models/atlas_engine/address_validation/token/synonyms.rb +77 -0
- data/app/models/atlas_engine/address_validation/token.rb +113 -0
- data/app/models/atlas_engine/address_validation/validator.rb +147 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/address_comparison.rb +97 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/candidate_result.rb +164 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/candidate_result_base.rb +46 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/comparison_helper.rb +135 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/components_to_validate.rb +88 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/concern_builder.rb +127 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/exclusions/exclusion_base.rb +23 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/invalid_zip_concern_builder.rb +42 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/invalid_zip_for_country_concern.rb +37 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/invalid_zip_for_province_concern.rb +37 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/no_candidate_result.rb +26 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/number_comparison.rb +31 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/postal_code_matcher.rb +60 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/result_updater.rb +42 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/suggestion_builder.rb +140 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/unknown_address_concern.rb +30 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/unknown_province_concern.rb +38 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/unknown_zip_for_address_concern.rb +32 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/unmatched_field_concern.rb +84 -0
- data/app/models/atlas_engine/address_validation/validators/full_address/unsupported_script_result.rb +22 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/cache.rb +38 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/city/present.rb +36 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/country/exists.rb +34 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/country/valid_for_zip.rb +60 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/no_emojis.rb +38 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/no_html_tags.rb +39 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/no_url.rb +38 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/not_exceed_max_length.rb +34 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/not_exceed_max_token_count.rb +63 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/phone/valid.rb +41 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/predicate.rb +37 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/province/exists.rb +43 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/province/valid_for_country.rb +48 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/street/building_number_in_address1.rb +45 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/street/building_number_in_address1_or_address2.rb +43 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/street/present.rb +35 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/zip/present.rb +58 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/zip/valid_for_country.rb +45 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/zip/valid_for_province.rb +55 -0
- data/app/models/atlas_engine/address_validation/validators/predicates/zip/zip_base.rb +25 -0
- data/app/models/atlas_engine/address_validation/zip_truncator.rb +32 -0
- data/app/models/atlas_engine/application_record.rb +8 -0
- data/app/models/atlas_engine/coded_error.rb +18 -0
- data/app/models/atlas_engine/coded_errors.rb +17 -0
- data/app/models/atlas_engine/country_import.rb +44 -0
- data/app/models/atlas_engine/country_profile.rb +270 -0
- data/app/models/atlas_engine/country_profile_ingestion_subset.rb +42 -0
- data/app/models/atlas_engine/country_profile_subset_base.rb +22 -0
- data/app/models/atlas_engine/country_profile_validation_subset.rb +48 -0
- data/app/models/atlas_engine/country_repository.rb +110 -0
- data/app/models/atlas_engine/elasticsearch/client.rb +116 -0
- data/app/models/atlas_engine/elasticsearch/client_interface.rb +89 -0
- data/app/models/atlas_engine/elasticsearch/repository.rb +246 -0
- data/app/models/atlas_engine/elasticsearch/repository_interface.rb +82 -0
- data/app/models/atlas_engine/elasticsearch/response.rb +20 -0
- data/app/models/atlas_engine/event.rb +12 -0
- data/app/models/atlas_engine/field_decompounder.rb +36 -0
- data/app/models/atlas_engine/index_configuration_factory.rb +188 -0
- data/app/models/atlas_engine/post_address.rb +114 -0
- data/app/models/atlas_engine/post_address_importer.rb +34 -0
- data/app/models/atlas_engine/services/service_helper.rb +21 -0
- data/app/models/atlas_engine/services/validation.rb +65 -0
- data/app/models/atlas_engine/services/validation_eligibility.rb +18 -0
- data/app/models/atlas_engine/street.rb +34 -0
- data/app/tasks/maintenance/atlas_engine/elasticsearch_index_create_task.rb +106 -0
- data/app/tasks/maintenance/atlas_engine/geo_json_import_task.rb +29 -0
- data/app/views/atlas_engine/connectivity/index.html.erb +50 -0
- data/app/views/atlas_engine/country_imports/index.html.erb +49 -0
- data/app/views/atlas_engine/country_imports/show.html.erb +73 -0
- data/app/views/layouts/atlas_engine/application.html.erb +15 -0
- data/config/initializers/1.ruby_patches.rb +18 -0
- data/config/initializers/sorbet.rb +5 -0
- data/config/initializers/worldwide.rb +5 -0
- data/config/locales/internal/en.yml +14 -0
- data/config/routes.rb +17 -0
- data/db/data/address_synonyms/index_configurations/default.yml +141 -0
- data/db/data/country_profiles/default.yml +23 -0
- data/db/data/transcriber.yml +760 -0
- data/db/data/validation_pipelines/es.yml +58 -0
- data/db/data/validation_pipelines/es_street.yml +58 -0
- data/db/data/validation_pipelines/local.yml +60 -0
- data/db/migrate/20230919173037_create_atlas_engine_post_addresses.rb +25 -0
- data/db/migrate/20231117142735_add_building_and_unit_ranges_column.rb +7 -0
- data/db/migrate/20231117143536_create_atlas_engine_country_imports.rb +11 -0
- data/db/migrate/20231117145844_create_atlas_engine_events_table.rb +13 -0
- data/db/migrate/20231123153554_add_unique_index_to_atlas_engine_post_addresses.rb +14 -0
- data/db/migrate/20231123154658_add_index_to_post_addresses_on_source_id_locale_country_code.rb +12 -0
- data/lib/atlas_engine/engine.rb +10 -0
- data/lib/atlas_engine/version.rb +6 -0
- data/lib/atlas_engine.rb +66 -0
- data/lib/tasks/atlas_engine/address_importer.rake +20 -0
- metadata +553 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
# typed: false
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
class Schema < GraphQL::Schema
|
6
|
+
extend LogHelper
|
7
|
+
query(Types::QueryType)
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def dump
|
11
|
+
schema_path = Pathname.new(__dir__).join("schema.graphql")
|
12
|
+
schema_path.write(to_definition)
|
13
|
+
log_info("Updated GraphQL schema dump: #{schema_path}")
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def refresh
|
18
|
+
log_info("Refreshed GraphQL schema types.")
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module Types
|
6
|
+
module AddressValidation
|
7
|
+
class AddressInput < GraphQL::Schema::InputObject
|
8
|
+
extend T::Sig
|
9
|
+
include LogHelper
|
10
|
+
include AtlasEngine::AddressValidation::AbstractAddress
|
11
|
+
|
12
|
+
description "Address fields used to fulfill a validation request"
|
13
|
+
|
14
|
+
argument :address1, String, required: false
|
15
|
+
argument :address2, String, required: false
|
16
|
+
argument :city, String, required: false
|
17
|
+
argument :country_code, ValidationSupportedCountry, required: false
|
18
|
+
argument :province_code, String, required: false
|
19
|
+
argument :zip, String, required: false
|
20
|
+
argument :phone, String, required: false
|
21
|
+
|
22
|
+
sig { returns(T::Hash[T.untyped, T.untyped]) }
|
23
|
+
def marshal_dump
|
24
|
+
to_kwargs
|
25
|
+
end
|
26
|
+
|
27
|
+
sig { params(hash: T::Hash[T.untyped, T.untyped]).void }
|
28
|
+
def marshal_load(hash)
|
29
|
+
@ruby_style_hash = T.let(hash, T.nilable(T::Hash[T.untyped, T.untyped]))
|
30
|
+
end
|
31
|
+
|
32
|
+
class << self
|
33
|
+
extend T::Sig
|
34
|
+
|
35
|
+
sig do
|
36
|
+
params(hash: T::Hash[Symbol, T.untyped])
|
37
|
+
.returns(AddressInput)
|
38
|
+
end
|
39
|
+
def from_hash(hash)
|
40
|
+
new(
|
41
|
+
nil,
|
42
|
+
ruby_kwargs: hash,
|
43
|
+
context: nil,
|
44
|
+
defaults_used: nil,
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# typed: false
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module Types
|
6
|
+
module AddressValidation
|
7
|
+
class ConcernType < BaseObject
|
8
|
+
description "A piece of relevant information regarding the address validation result." \
|
9
|
+
"They can be categorized as either a Warning or Error."
|
10
|
+
|
11
|
+
field :field_names, [String], null: false
|
12
|
+
field :message, String, null: false
|
13
|
+
field :code, String, null: false
|
14
|
+
field :type, Enums::ConcernEnum, null: false
|
15
|
+
field :type_level, Int, null: false
|
16
|
+
field :suggestion_ids, [String], null: false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# typed: false
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module Types
|
6
|
+
module AddressValidation
|
7
|
+
module Enums
|
8
|
+
class ConcernEnum < BaseEnum
|
9
|
+
value :WARNING, value: "warning"
|
10
|
+
value :ERROR, value: "error"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# typed: false
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module Types
|
6
|
+
module AddressValidation
|
7
|
+
class FieldType < BaseObject
|
8
|
+
description "An individual field which in conjunction with others compose an address"
|
9
|
+
|
10
|
+
field :name, String, null: false
|
11
|
+
field :value, String, null: false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# typed: false
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module Types
|
6
|
+
module AddressValidation
|
7
|
+
class SuggestionType < BaseObject
|
8
|
+
description "An address-like object containing some value corrections derived during address validation"
|
9
|
+
|
10
|
+
field :id, String, null: false
|
11
|
+
field :address1, String, null: true
|
12
|
+
field :address2, String, null: true
|
13
|
+
field :city, String, null: true
|
14
|
+
field :zip, String, null: true
|
15
|
+
field :province_code, String, null: true
|
16
|
+
field :province, String, null: true
|
17
|
+
field :country_code, ValidationSupportedCountry, null: true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# typed: false
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module Types
|
6
|
+
class QueryType < Types::BaseObject
|
7
|
+
include LogHelper
|
8
|
+
|
9
|
+
field :validation, ValidationType, null: false do
|
10
|
+
argument :address, AddressValidation::AddressInput, required: true
|
11
|
+
argument :locale, String, required: true
|
12
|
+
argument :matching_strategy, MatchingStrategyType, required: false
|
13
|
+
end
|
14
|
+
|
15
|
+
def validation(address:, locale: "en", matching_strategy: nil)
|
16
|
+
raise build_graphql_error(AtlasEngine::AddressValidation::Errors::MISSING_PARAMETER) if address.blank?
|
17
|
+
|
18
|
+
locale = LocaleFormatHelper.format_locale(locale)
|
19
|
+
|
20
|
+
country_code = address.country_code
|
21
|
+
tags = ["country:#{country_code}", "matching_strategy:#{matching_strategy}"]
|
22
|
+
measure("validation", tags) do
|
23
|
+
I18n.with_locale(locale) do
|
24
|
+
Services::Validation.validate_address(
|
25
|
+
AtlasEngine::AddressValidation::Request.new(
|
26
|
+
address: address,
|
27
|
+
locale: locale,
|
28
|
+
matching_strategy: matching_strategy,
|
29
|
+
),
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def measure(method, tags = [], value = nil, &block)
|
38
|
+
if block
|
39
|
+
StatsD.distribution(
|
40
|
+
"#{method}.request_time",
|
41
|
+
tags: tags,
|
42
|
+
&block
|
43
|
+
)
|
44
|
+
else
|
45
|
+
StatsD.distribution(
|
46
|
+
"#{method}.request_time",
|
47
|
+
value,
|
48
|
+
tags: tags,
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def build_graphql_error(error)
|
54
|
+
GraphQL::ExecutionError.new(
|
55
|
+
error.message,
|
56
|
+
extensions: { "error_code" => error.code },
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module Types
|
6
|
+
class ValidationSupportedCountry < BaseEnum
|
7
|
+
Worldwide::Regions.all.select(&:country?).reject(&:deprecated?).map do |country|
|
8
|
+
value country.iso_code, description: country.full_name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# typed: false
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module Types
|
6
|
+
class ValidationType < BaseObject
|
7
|
+
description "An address validation result object"
|
8
|
+
|
9
|
+
field :id, String, null: false
|
10
|
+
field :fields, [AddressValidation::FieldType], null: false
|
11
|
+
field :validation_scope, [String], null: false
|
12
|
+
field :concerns, [AddressValidation::ConcernType], null: false
|
13
|
+
field :suggestions, [AddressValidation::SuggestionType], null: false
|
14
|
+
field :locale, String, null: false
|
15
|
+
field :candidate,
|
16
|
+
String,
|
17
|
+
null: true,
|
18
|
+
deprecation_reason: "Temporary field meant for internal use only."
|
19
|
+
field :matching_strategy, Types::MatchingStrategyType, null: false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module AddressImporter
|
6
|
+
module ImportLogHelper
|
7
|
+
extend T::Sig
|
8
|
+
include LogHelper
|
9
|
+
|
10
|
+
TEST_TIMESTAMP = "timestamp"
|
11
|
+
|
12
|
+
sig do
|
13
|
+
params(
|
14
|
+
country_import: CountryImport,
|
15
|
+
message: String,
|
16
|
+
category: T.nilable(Symbol),
|
17
|
+
additional_params: T::Hash[T.untyped, T.untyped],
|
18
|
+
notify: T::Boolean,
|
19
|
+
).void
|
20
|
+
end
|
21
|
+
def import_log_info(country_import:, message:, category: :progress, additional_params: {}, notify: false)
|
22
|
+
log_info(message, additional_params)
|
23
|
+
event = create_event(country_import, message, category, additional_params)
|
24
|
+
send_notification(event) if event && notify
|
25
|
+
end
|
26
|
+
|
27
|
+
sig do
|
28
|
+
params(
|
29
|
+
country_import: CountryImport,
|
30
|
+
message: String,
|
31
|
+
additional_params: T.nilable(T::Hash[T.untyped, T.untyped]),
|
32
|
+
).void
|
33
|
+
end
|
34
|
+
def import_log_error(country_import:, message:, additional_params: {})
|
35
|
+
log_error(message, T.must(additional_params))
|
36
|
+
event = create_event(country_import, message, :error, additional_params)
|
37
|
+
send_notification(event) if event
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
sig do
|
43
|
+
params(
|
44
|
+
country_import: CountryImport,
|
45
|
+
message: String,
|
46
|
+
category: T.nilable(Symbol),
|
47
|
+
additional_params: T.nilable(T::Hash[T.untyped, T.untyped]),
|
48
|
+
)
|
49
|
+
.returns(T.nilable(Event))
|
50
|
+
end
|
51
|
+
def create_event(country_import, message, category, additional_params = nil)
|
52
|
+
Event.create(
|
53
|
+
country_import_id: country_import.id,
|
54
|
+
message: message,
|
55
|
+
category: category,
|
56
|
+
additional_params: additional_params.presence,
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
sig { params(event: Event).void }
|
61
|
+
def send_notification(event)
|
62
|
+
AtlasEngine.address_importer_notifier.constantize.instance.notify(event: event)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module LocaleFormatHelper
|
6
|
+
class << self
|
7
|
+
extend T::Sig
|
8
|
+
|
9
|
+
sig { params(locale: T.nilable(String)).returns(T.nilable(String)) }
|
10
|
+
def format_locale(locale)
|
11
|
+
return if locale.blank?
|
12
|
+
|
13
|
+
resolve_supported_locale(locale) || locale.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
SUPPORTED_LOCALE_MAP = T.let(
|
19
|
+
{
|
20
|
+
DA: "da",
|
21
|
+
DE: "de",
|
22
|
+
EN: "en",
|
23
|
+
ES: "es",
|
24
|
+
FR: "fr",
|
25
|
+
IT: "it",
|
26
|
+
JA: "ja",
|
27
|
+
NL: "nl",
|
28
|
+
"PT-BR": "pt-BR",
|
29
|
+
PT: "pt",
|
30
|
+
},
|
31
|
+
T::Hash[T.untyped, T.untyped],
|
32
|
+
)
|
33
|
+
|
34
|
+
sig { params(locale: String).returns(T.nilable(String)) }
|
35
|
+
def resolve_supported_locale(locale)
|
36
|
+
SUPPORTED_LOCALE_MAP[locale.to_sym]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module LogBase
|
6
|
+
include Kernel
|
7
|
+
extend T::Sig
|
8
|
+
|
9
|
+
TEST_TIMESTAMP = T.let("timestamp", String)
|
10
|
+
|
11
|
+
sig { params(level: Symbol, message: String, additional_params: T::Hash[Symbol, T.untyped]).void }
|
12
|
+
def log_message(level, message, additional_params = {})
|
13
|
+
params = {
|
14
|
+
messages: [{
|
15
|
+
level: level,
|
16
|
+
source: self.class.name,
|
17
|
+
message: message,
|
18
|
+
timestamp: time,
|
19
|
+
}.merge(additional_params)],
|
20
|
+
}
|
21
|
+
|
22
|
+
Rails.logger.send(level, params)
|
23
|
+
end
|
24
|
+
|
25
|
+
sig { returns(String) }
|
26
|
+
def time
|
27
|
+
return TEST_TIMESTAMP if Rails.env.test?
|
28
|
+
|
29
|
+
Time.current.utc.to_fs
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module LogHelper
|
6
|
+
T.unsafe(self).include(AtlasEngine.log_base.constantize)
|
7
|
+
extend T::Sig
|
8
|
+
|
9
|
+
sig { params(message: String, additional_params: T::Hash[Symbol, T.untyped]).void }
|
10
|
+
def log_info(message, additional_params = {})
|
11
|
+
log_message(:info, message, additional_params)
|
12
|
+
end
|
13
|
+
|
14
|
+
sig { params(message: String, additional_params: T::Hash[Symbol, T.untyped]).void }
|
15
|
+
def log_warn(message, additional_params = {})
|
16
|
+
log_message(:warn, message, additional_params)
|
17
|
+
end
|
18
|
+
|
19
|
+
sig { params(message: String, additional_params: T::Hash[Symbol, T.untyped]).void }
|
20
|
+
def log_error(message, additional_params = {})
|
21
|
+
log_message(:error, message, additional_params)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# typed: true
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module MetricsHelper
|
6
|
+
extend T::Sig
|
7
|
+
|
8
|
+
sig do
|
9
|
+
params(
|
10
|
+
name: String,
|
11
|
+
sample_rate: Float,
|
12
|
+
tags: T::Array[String],
|
13
|
+
block: T.proc.returns(T.untyped),
|
14
|
+
).returns(T.untyped)
|
15
|
+
end
|
16
|
+
def measure_distribution(name:, sample_rate: 1.0, tags: [], &block)
|
17
|
+
StatsD.distribution(
|
18
|
+
name,
|
19
|
+
sample_rate: sample_rate,
|
20
|
+
tags: tags,
|
21
|
+
&block
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# typed: false
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module AtlasEngine
|
5
|
+
module AddressImporter
|
6
|
+
class ClearRecordsJob < AddressImporter::ResumableImportJob
|
7
|
+
include ImportLogHelper
|
8
|
+
include LogHelper
|
9
|
+
DELETION_BATCH_SIZE = 2000
|
10
|
+
|
11
|
+
def build_enumerator(params, cursor:)
|
12
|
+
enumerator_builder.build_times_enumerator(1, cursor: cursor)
|
13
|
+
end
|
14
|
+
|
15
|
+
def each_iteration(batch, params)
|
16
|
+
@country_code = params[:country_code]
|
17
|
+
clear_records
|
18
|
+
end
|
19
|
+
|
20
|
+
def clear_records
|
21
|
+
import_log_info(
|
22
|
+
country_import: country_import,
|
23
|
+
message: "Clearing all records from PostAddress where country_code: #{@country_code}...",
|
24
|
+
)
|
25
|
+
rows_deleted = delete_rows
|
26
|
+
rows_deleted = delete_rows until rows_deleted != DELETION_BATCH_SIZE
|
27
|
+
import_log_info(country_import: country_import, message: "PostAddress records cleared.")
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete_rows
|
31
|
+
PostAddress.connection.exec_delete(
|
32
|
+
"DELETE FROM #{PostAddress.table_name} where country_code = '#{@country_code}' LIMIT #{DELETION_BATCH_SIZE}",
|
33
|
+
"DELETE",
|
34
|
+
[],
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|