terrapop_models 0.1.0
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +34 -0
- data/app/assets/javascripts/terrapop_models/application.js +13 -0
- data/app/assets/stylesheets/terrapop_models/application.css +15 -0
- data/app/controllers/terrapop_models/application_controller.rb +4 -0
- data/app/helpers/terrapop_models/application_helper.rb +4 -0
- data/app/models/api_log.rb +2 -0
- data/app/models/area_data_raster.rb +126 -0
- data/app/models/area_data_raster_variable_mnemonic_lookup.rb +4 -0
- data/app/models/area_data_statistic.rb +6 -0
- data/app/models/area_data_table.rb +25 -0
- data/app/models/area_data_table_group.rb +8 -0
- data/app/models/area_data_table_group_membership.rb +7 -0
- data/app/models/area_data_value.rb +37 -0
- data/app/models/area_data_variable.rb +140 -0
- data/app/models/area_data_variable_construction.rb +6 -0
- data/app/models/attached_variable_pointer.rb +5 -0
- data/app/models/bare_user.rb +7 -0
- data/app/models/boundary.rb +6 -0
- data/app/models/build_status.rb +2 -0
- data/app/models/category.rb +17 -0
- data/app/models/codebook.rb +242 -0
- data/app/models/common_variable.rb +2 -0
- data/app/models/country.rb +45 -0
- data/app/models/country_comparability.rb +6 -0
- data/app/models/country_level.rb +8 -0
- data/app/models/ddi2_codebook.rb +541 -0
- data/app/models/error_event.rb +2 -0
- data/app/models/extract_data_artifact.rb +4 -0
- data/app/models/extract_request.rb +817 -0
- data/app/models/extract_request_area_data_raster_variable_mnemonic_lookup.rb +4 -0
- data/app/models/extract_request_error_event.rb +4 -0
- data/app/models/extract_request_submission.rb +19 -0
- data/app/models/extract_status.rb +55 -0
- data/app/models/extract_type.rb +2 -0
- data/app/models/extract_variable_stub.rb +17 -0
- data/app/models/frequency.rb +7 -0
- data/app/models/geog_instance.rb +18 -0
- data/app/models/geog_unit.rb +5 -0
- data/app/models/global_region.rb +6 -0
- data/app/models/global_region_type.rb +5 -0
- data/app/models/heartbeat.rb +8 -0
- data/app/models/heartbeat_pulse.rb +3 -0
- data/app/models/insert_html_fragment.rb +3 -0
- data/app/models/ipums_academic_status.rb +9 -0
- data/app/models/ipums_anticipated_result.rb +9 -0
- data/app/models/ipums_department.rb +9 -0
- data/app/models/ipums_registration.rb +72 -0
- data/app/models/ipums_user.rb +15 -0
- data/app/models/label.rb +7 -0
- data/app/models/link.rb +21 -0
- data/app/models/map.rb +255 -0
- data/app/models/map_unit.rb +4 -0
- data/app/models/map_unit_raster_dataset.rb +4 -0
- data/app/models/markup_transform.rb +240 -0
- data/app/models/measurement_type.rb +5 -0
- data/app/models/nhgis/agg_data_var.rb +120 -0
- data/app/models/nhgis/breakdown_combo.rb +84 -0
- data/app/models/nhgis/breakdown_var.rb +8 -0
- data/app/models/nhgis/data_file.rb +43 -0
- data/app/models/nhgis/data_file_type.rb +17 -0
- data/app/models/nhgis/data_group.rb +125 -0
- data/app/models/nhgis/data_record_range.rb +22 -0
- data/app/models/nhgis/data_table.rb +8 -0
- data/app/models/nhgis/dataset.rb +76 -0
- data/app/models/nhgis/dataset_group.rb +6 -0
- data/app/models/nhgis/geog_level.rb +14 -0
- data/app/models/nhgis/geog_level_collection.rb +15 -0
- data/app/models/nhgis/geog_level_geog_level_group.rb +10 -0
- data/app/models/nhgis/geog_level_group.rb +87 -0
- data/app/models/nhgis/geog_name.rb +12 -0
- data/app/models/nhgis/geog_unit.rb +11 -0
- data/app/models/nhgis/geog_var 2.rb +10 -0
- data/app/models/nhgis/geog_var.rb +6 -0
- data/app/models/nhgis/geog_var_geog_level.rb +8 -0
- data/app/models/nhgis/geotime.rb +21 -0
- data/app/models/nhgis/integ_geog_instance.rb +6 -0
- data/app/models/nhgis/integ_geog_instance_source_geog_instance.rb +9 -0
- data/app/models/nhgis/integ_geog_level.rb +9 -0
- data/app/models/nhgis/integ_geog_name.rb +12 -0
- data/app/models/nhgis/shape_file.rb +203 -0
- data/app/models/nhgis/shape_file_x_dataset.rb +8 -0
- data/app/models/nhgis/tabulation_type.rb +8 -0
- data/app/models/nhgis/time_instance.rb +6 -0
- data/app/models/nhgis/time_instance_integ_geog_level.rb +9 -0
- data/app/models/nhgis/time_series.rb +12 -0
- data/app/models/nhgis/time_series_component.rb +9 -0
- data/app/models/nhgis/time_series_release.rb +6 -0
- data/app/models/nhgis/time_series_table.rb +13 -0
- data/app/models/nhgis/time_series_table_dataset.rb +9 -0
- data/app/models/nhgis/time_series_table_geog_level.rb +9 -0
- data/app/models/nhgis/time_series_table_time_instance.rb +9 -0
- data/app/models/nhgis/time_series_table_time_series_release.rb +7 -0
- data/app/models/nhgis/time_series_table_topic.rb +9 -0
- data/app/models/nhgis/time_series_table_x_time_series.rb +9 -0
- data/app/models/nhgis_metadata_store.rb +2 -0
- data/app/models/raster.rb +5 -0
- data/app/models/raster_category.rb +6 -0
- data/app/models/raster_category_statistic.rb +7 -0
- data/app/models/raster_data_type.rb +6 -0
- data/app/models/raster_dataset.rb +130 -0
- data/app/models/raster_dataset_group.rb +3 -0
- data/app/models/raster_dataset_raster_data_type.rb +4 -0
- data/app/models/raster_dataset_raster_dataset_unit.rb +4 -0
- data/app/models/raster_dataset_raster_variable.rb +4 -0
- data/app/models/raster_dataset_unit.rb +4 -0
- data/app/models/raster_group.rb +87 -0
- data/app/models/raster_metadata.rb +6 -0
- data/app/models/raster_operation.rb +10 -0
- data/app/models/raster_raster_variable.rb +2 -0
- data/app/models/raster_statistic.rb +6 -0
- data/app/models/raster_value.rb +83 -0
- data/app/models/raster_variable.rb +440 -0
- data/app/models/raster_variable_classification.rb +4 -0
- data/app/models/raster_variable_group_membership.rb +4 -0
- data/app/models/request_area_data_variable.rb +57 -0
- data/app/models/request_geog_unit.rb +6 -0
- data/app/models/request_raster_dataset.rb +4 -0
- data/app/models/request_raster_variable.rb +147 -0
- data/app/models/request_sample.rb +34 -0
- data/app/models/request_sample_geog_level.rb +4 -0
- data/app/models/request_terrapop_sample.rb +6 -0
- data/app/models/request_variable.rb +104 -0
- data/app/models/resolution.rb +5 -0
- data/app/models/sample.rb +81 -0
- data/app/models/sample_design.rb +300 -0
- data/app/models/sample_detail_field.rb +7 -0
- data/app/models/sample_detail_group.rb +3 -0
- data/app/models/sample_detail_value.rb +11 -0
- data/app/models/sample_details.rb +90 -0
- data/app/models/sample_geog_level.rb +150 -0
- data/app/models/sample_level_area_data_variable.rb +13 -0
- data/app/models/sample_variable.rb +11 -0
- data/app/models/status_definition.rb +2 -0
- data/app/models/system_statistic.rb +5 -0
- data/app/models/tag.rb +7 -0
- data/app/models/terrapop_configuration.rb +75 -0
- data/app/models/terrapop_extract_information.rb +64 -0
- data/app/models/terrapop_raster_summary_cache.rb +6 -0
- data/app/models/terrapop_sample.rb +313 -0
- data/app/models/terrapop_setting.rb +11 -0
- data/app/models/topic.rb +7 -0
- data/app/models/ui_text_snippet.rb +2 -0
- data/app/models/universe.rb +5 -0
- data/app/models/user.rb +262 -0
- data/app/models/user_role.rb +5 -0
- data/app/models/variable.rb +127 -0
- data/app/models/variable_availability_cach.rb +3 -0
- data/app/models/variable_group.rb +14 -0
- data/app/models/variable_source.rb +8 -0
- data/app/views/layouts/terrapop_models/application.html.erb +14 -0
- data/config/routes.rb +2 -0
- data/db/migrate/00000000000100_create_countries.rb +15 -0
- data/db/migrate/00000000000200_create_universes.rb +11 -0
- data/db/migrate/00000000000300_create_geog_units.rb +9 -0
- data/db/migrate/00000000000400_create_measurement_types.rb +9 -0
- data/db/migrate/00000000000500_create_area_data_table_groups.rb +13 -0
- data/db/migrate/00000000000600_create_area_data_tables.rb +14 -0
- data/db/migrate/00000000000700_create_area_data_table_group_memberships.rb +12 -0
- data/db/migrate/00000000000800_create_tags.rb +9 -0
- data/db/migrate/00000000000900_create_topics.rb +9 -0
- data/db/migrate/00000000001000_create_variable_groups.rb +18 -0
- data/db/migrate/00000000001100_create_samples.rb +32 -0
- data/db/migrate/00000000001200_create_terrapop_samples.rb +12 -0
- data/db/migrate/00000000001300_create_variables.rb +52 -0
- data/db/migrate/00000000001400_create_country_levels.rb +17 -0
- data/db/migrate/00000000001450_variable_topics.rb +19 -0
- data/db/migrate/00000000001500_create_sample_geog_levels.rb +20 -0
- data/db/migrate/00000000002000_create_area_data_variables.rb +19 -0
- data/db/migrate/00000000002050_area_data_variable_topics.rb +22 -0
- data/db/migrate/00000000002100_create_sample_level_area_data_variables.rb +16 -0
- data/db/migrate/00000000002200_create_sample_level_area_variable_constructions.rb +12 -0
- data/db/migrate/00000000003000_create_maps.rb +22 -0
- data/db/migrate/00000000003100_create_boundaries.rb +14 -0
- data/db/migrate/00000000004000_create_geog_instances.rb +20 -0
- data/db/migrate/00000000004100_create_area_data_values.rb +18 -0
- data/db/migrate/00000000005000_create_sample_variables.rb +21 -0
- data/db/migrate/00000000005100_create_categories.rb +20 -0
- data/db/migrate/00000000005200_create_frequencies.rb +16 -0
- data/db/migrate/00000000005300_create_variable_sources.rb +16 -0
- data/db/migrate/00000000006000_create_user_roles.rb +8 -0
- data/db/migrate/00000000006100_create_users.rb +43 -0
- data/db/migrate/00000000006300_create_samples_tags.rb +15 -0
- data/db/migrate/00000000006400_create_terrapop_samples_tags.rb +15 -0
- data/db/migrate/00000000007000_create_raster_data_types.rb +9 -0
- data/db/migrate/00000000007050_create_resolutions.rb +8 -0
- data/db/migrate/00000000007100_create_raster_datasets.rb +26 -0
- data/db/migrate/00000000007200_create_raster_groups.rb +20 -0
- data/db/migrate/00000000007250_create_raster_groups_tags.rb +19 -0
- data/db/migrate/00000000007300_create_raster_variables.rb +28 -0
- data/db/migrate/00000000007325_create_raster_variable_group_memberships.rb +12 -0
- data/db/migrate/00000000007350_raster_variable_topics.rb +22 -0
- data/db/migrate/00000000007400_create_rasters.rb +22 -0
- data/db/migrate/00000000007500_create_raster_operations.rb +11 -0
- data/db/migrate/00000000010000_create_status_definitions.rb +8 -0
- data/db/migrate/00000000010050_create_extract_types.rb +10 -0
- data/db/migrate/00000000010100_create_build_statuses.rb +10 -0
- data/db/migrate/00000000010200_create_extract_requests.rb +14 -0
- data/db/migrate/00000000010300_create_extract_requests_labels_join_table.rb +20 -0
- data/db/migrate/00000000010400_create_extract_statuses.rb +13 -0
- data/db/migrate/00000000010500_create_request_geog_units.rb +13 -0
- data/db/migrate/00000000010600_create_request_terrapop_samples.rb +15 -0
- data/db/migrate/00000000011000_create_request_variable.rb +16 -0
- data/db/migrate/00000000011100_create_request_area_data_variables.rb +18 -0
- data/db/migrate/00000000011200_create_request_raster_variables.rb +20 -0
- data/db/migrate/00000000012000_create_raster_summary_functions.rb +130 -0
- data/db/migrate/00000000013000_create_terrapop_settings.rb +24 -0
- data/db/migrate/20121218190647_create_attached_variable_pointer.rb +18 -0
- data/db/migrate/20121218191609_add_attached_variable_pointer_id.rb +9 -0
- data/db/migrate/20121218205322_add_wants_attached.rb +9 -0
- data/db/migrate/20121219145142_add_attributes_to_terrapop_sample.rb +68 -0
- data/db/migrate/20130125155216_add_default_order_index_to_variables.rb +5 -0
- data/db/migrate/20130129204515_create_request_samples.rb +14 -0
- data/db/migrate/20130129204718_create_request_raster_datasets.rb +13 -0
- data/db/migrate/20130205195304_create_error_events.rb +10 -0
- data/db/migrate/20130206202006_add_country_index_for_continent.rb +8 -0
- data/db/migrate/20130207202628_create_raster_metadata.rb +13 -0
- data/db/migrate/20130208192415_add_extents_to_raster_dataset.rb +6 -0
- data/db/migrate/20130209182800_create_global_regions.rb +11 -0
- data/db/migrate/20130209182858_add_global_region_id_country.rb +13 -0
- data/db/migrate/20130211183221_add_type_to_global_regions.rb +5 -0
- data/db/migrate/20130212190940_create_global_region_types.rb +8 -0
- data/db/migrate/20130212192357_remove_classification_add_global_region_type_id_to_global_region.rb +13 -0
- data/db/migrate/20130304181054_add_code_to_boundaries.rb +5 -0
- data/db/migrate/20130305223407_add_ipumsi_user_flagto_users.rb +15 -0
- data/db/migrate/20130305224906_add_ipumsi_user_date_flagto_users.rb +11 -0
- data/db/migrate/20130308214537_create_request_sample_geog_levels.rb +14 -0
- data/db/migrate/20130312191726_create_raster_statistics.rb +23 -0
- data/db/migrate/20130312192100_create_raster_categories.rb +14 -0
- data/db/migrate/20130312192158_create_raster_category_statistics.rb +22 -0
- data/db/migrate/20130312203045_create_area_data_statistics.rb +15 -0
- data/db/migrate/20130401161222_add_summary_to_raster_variable.rb +11 -0
- data/db/migrate/20130402203508_add_global_region_sort_order_column.rb +8 -0
- data/db/migrate/20130402211553_add_weighted_to_terrapop_samples.rb +5 -0
- data/db/migrate/20130408022218_add_period_to_raster_datasets.rb +5 -0
- data/db/migrate/20130409161950_create_area_data_variable_constructions.rb +17 -0
- data/db/migrate/20130409162731_add_opcode_to_raster_operations.rb +5 -0
- data/db/migrate/20130412141109_update_raster_summary_functions.rb +39 -0
- data/db/migrate/20130415174823_create_insert_html_fragments.rb +13 -0
- data/db/migrate/20130415185523_create_common_variables.rb +13 -0
- data/db/migrate/20130416144840_add_columns_to_request_samples.rb +6 -0
- data/db/migrate/20130416150151_add_revision_of_column_to_extract_request.rb +8 -0
- data/db/migrate/20130416151200_add_file_type_to_extract_request.rb +5 -0
- data/db/migrate/20130416161440_add_column_general_detailed_selection_to_request_variables.rb +5 -0
- data/db/migrate/20130416170551_add_wants_case_selection_to_request_variable.rb +5 -0
- data/db/migrate/20130613185642_add_indexes_to_tables.rb +7 -0
- data/db/migrate/20130614193857_add_more_column_indexes.rb +11 -0
- data/db/migrate/20130618141508_create_raster_dataset_raster_data_types.rb +17 -0
- data/db/migrate/20130618185528_add_circa_to_raster_dataset.rb +5 -0
- data/db/migrate/20130619160555_create_raster_dataset_units.rb +9 -0
- data/db/migrate/20130619161934_create_raster_dataset_raster_dataset_units.rb +17 -0
- data/db/migrate/20130621184015_add_raster_dataset_process_summary.rb +8 -0
- data/db/migrate/20130621203809_add_source_information_column_to_raster_dataset.rb +5 -0
- data/db/migrate/20130624144333_add_temporal_extent_description_to_raster_dataset.rb +5 -0
- data/db/migrate/20130624154952_add_provider_to_raster_dataset.rb +5 -0
- data/db/migrate/20130624175342_add_use_constraints_column_to_raster_dataset.rb +5 -0
- data/db/migrate/20130624175632_drop_use_constraints_column_from_raster_dataset.rb +8 -0
- data/db/migrate/20130624192654_add_north_south_east_west_columns_to_raster_dataset.rb +8 -0
- data/db/migrate/20130625193303_add_sort_operation_identifier_to_raster_group.rb +5 -0
- data/db/migrate/20130702190659_add_raster_group_id_to_raster_variable.rb +9 -0
- data/db/migrate/20130708184410_create_country_comparabilities.rb +14 -0
- data/db/migrate/20130711191704_add_ipumsi_user_id_to_user.rb +8 -0
- data/db/migrate/20130712150252_add_data_settings_column_to_user.rb +8 -0
- data/db/migrate/20130719183620_add_visible_and_map_to_columns_to_raster_operations.rb +13 -0
- data/db/migrate/20130812194537_create_extract_request_submissions.rb +12 -0
- data/db/migrate/20130813165221_remove_ipums_user_id_from_user.rb +8 -0
- data/db/migrate/20130814161802_add_uuid_field_to_extract_request.rb +6 -0
- data/db/migrate/20130816204002_add_country_id_to_terrapop_sample.rb +8 -0
- data/db/migrate/20130816204214_add_year_to_terrapop_sample.rb +8 -0
- data/db/migrate/20130816205324_add_indexes_to_country.rb +9 -0
- data/db/migrate/20130819145802_add_foreign_key_to_terrapop_sample.rb +5 -0
- data/db/migrate/20130819155712_add_indexes_to_sample_level_area_data_variable.rb +5 -0
- data/db/migrate/20130819163013_add_short_country_name_to_terrapop_sample.rb +8 -0
- data/db/migrate/20130820195420_add_is_erf_to_country.rb +7 -0
- data/db/migrate/20130821221743_fix_raster_summary_function_num_classes.rb +39 -0
- data/db/migrate/20130830192340_add_more_user_registration_columns.rb +51 -0
- data/db/migrate/20130904205306_add_raster_variable_sort_order_weight.rb +8 -0
- data/db/migrate/20130912145522_add_localized_label_to_country_levels.rb +5 -0
- data/db/migrate/20130913194351_create_terrapop_raster_summary_caches.rb +27 -0
- data/db/migrate/20130916212710_add_year_range_to_map.rb +11 -0
- data/db/migrate/20130917154553_create_sample_designs.rb +14 -0
- data/db/migrate/20130924210303_add_raster_only_to_extract_request.rb +5 -0
- data/db/migrate/20131001220437_add_mnemonic_and_codebook_description_to_area_data_value.rb +11 -0
- data/db/migrate/20131002213443_add_ipums_email_sent_at_column.rb +8 -0
- data/db/migrate/20131020154130_remove_index_if_exists.rb +9 -0
- data/db/migrate/20131020170642_remove_ui_snippet_table_if_exists.rb +8 -0
- data/db/migrate/20131021204227_create_ui_text_snippet.rb +11 -0
- data/db/migrate/20131022190227_rename_table_fix_ui_text_snippets.rb +9 -0
- data/db/migrate/20131119154817_add_unique_index_on_uuid_on.rb +9 -0
- data/db/migrate/20131202161911_add_send_toi_rods_flag_to_extract_request.rb +13 -0
- data/db/migrate/20140122150020_add_geographic_levelto_geog_instance.rb +11 -0
- data/db/migrate/20140124184809_add_zip_file_location.rb +8 -0
- data/db/migrate/20140205205539_add_api_related_fields_to_user.rb +5 -0
- data/db/migrate/20140206213258_create_extract_request_error_events.rb +14 -0
- data/db/migrate/20140206222630_add_requesting_url_to_extract_request.rb +5 -0
- data/db/migrate/20140207153005_create_api_logs.rb +14 -0
- data/db/migrate/20140228182300_change_user_institutional_affiliation_to_bool.rb +50 -0
- data/db/migrate/20140312143201_add_start_and_end_time_and_total_time_to_extract_request.rb +7 -0
- data/db/migrate/20140318212913_remove_add_index_to_area_data_value.rb +12 -0
- data/db/migrate/20140319155819_add_long_mnemonic_to_area_data_value.rb +7 -0
- data/db/migrate/20140319200718_drop_mnemonic_column_area_data_value.rb +10 -0
- data/db/migrate/20140320184210_add_show_in_ui_column_in_raster_variable.rb +8 -0
- data/db/migrate/20140328150435_rename_revision_of_column_to_rabl_usable_column_name.rb +8 -0
- data/db/migrate/20140331142153_add_revision_of_column.rb +8 -0
- data/db/migrate/20140402181324_add_new_raster_summary_functions.rb +191 -0
- data/db/migrate/20140403185242_add_raster_variable_area_reference_id.rb +12 -0
- data/db/migrate/20140410145305_add_raster_area_column_to_terrapop_raster_summary_cache.rb +6 -0
- data/db/migrate/20140414170802_add_new_raster_summarization.rb +85 -0
- data/db/migrate/20140421150330_add_second_reference_column_to_raster_variable.rb +9 -0
- data/db/migrate/20140506165634_add_deactivated_at_and_deleted_at_to_user.rb +6 -0
- data/db/migrate/20140507142843_add_column_to_frequencies.rb +5 -0
- data/db/migrate/20140513143055_add_sample_geog_level_id_to_request_models.rb +11 -0
- data/db/migrate/20140521160554_create_links.rb +9 -0
- data/db/migrate/20140522214508_add_ipumsi_salt_and_ipumsi_crypted_password_to_user.rb +13 -0
- data/db/migrate/20140604192953_add_name_to_terrapop_setting.rb +47 -0
- data/db/migrate/20140609163907_create_variable_availability_caches.rb +9 -0
- data/db/migrate/20140609210447_add_foreign_index_to_variable_availability_cache.rb +8 -0
- data/db/migrate/20140609213300_create_area_data_variable_availability_caches.rb +13 -0
- data/db/migrate/20140610135849_create_nhgis_metadata_stores.rb +30 -0
- data/db/migrate/20140610211138_add_dataset_id_to_nhgis_metadata.rb +5 -0
- data/db/migrate/20140611181543_add_replicate_weight_variable_id_to_variables.rb +5 -0
- data/db/migrate/20140618200741_add_key_column_toraster_variable_group_memberships.rb +7 -0
- data/db/migrate/20140618202053_add_key_column_toraster_variable_group_memberships2.rb +8 -0
- data/db/migrate/20140701134952_create_system_statistics.rb +12 -0
- data/db/migrate/20140804161242_add_fields_to_terrapop_sample.rb +7 -0
- data/db/migrate/20140806173750_add_geometry_column_to_boundaries.rb +5 -0
- data/db/migrate/20140821205836_add_git_hash_field_to_extract_request.rb +5 -0
- data/db/migrate/20140822140106_create_map_units.rb +9 -0
- data/db/migrate/20140822140358_create_map_unit_raster_datasets.rb +17 -0
- data/db/migrate/20140822143517_redefine_short_unit_on_map_unit_to_longer_string.rb +5 -0
- data/db/migrate/20140825135403_add_finger_print_hash_to_maps.rb +5 -0
- data/db/migrate/20140826163359_add_source_field_to_terrapop_sample.rb +8 -0
- data/db/migrate/20140827153014_add_microdata_file_size_to_sample.rb +5 -0
- data/db/migrate/20140828161647_add_raster_band_index_to_raster_categories.rb +5 -0
- data/db/migrate/20140828162650_add_post_gis_raster_output_indicator_to_raster_variable.rb +5 -0
- data/db/migrate/20140829150251_create_raster_dataset_raster_variables.rb +17 -0
- data/db/migrate/20140902194529_add_raster_band_to_raster_dataset_model.rb +7 -0
- data/db/migrate/20140903202609_create_heartbeats.rb +9 -0
- data/db/migrate/20140903204113_create_heartbeat_pulse.rb +10 -0
- data/db/migrate/20140904164247_create_raster_raster_variables.rb +16 -0
- data/db/migrate/20140908193007_add_area_level_rasterization_functions.rb +103 -0
- data/db/migrate/20140908194021_create_area_data_rasters.rb +39 -0
- data/db/migrate/20140909143933_rename_valid_column_on_area_data_raster.rb +5 -0
- data/db/migrate/20140911201639_add_columns_to_area_data_raster.rb +11 -0
- data/db/migrate/20140911211923_alter_area_data_raster_indexes.rb +12 -0
- data/db/migrate/20140919144305_create_raster_variable_classifications.rb +29 -0
- data/db/migrate/20140925140810_add_other_raster_variables_to_raster_variable_classification.rb +9 -0
- data/db/migrate/20140925172245_add_grouping_indicator_to_raster_classifications.rb +5 -0
- data/db/migrate/20140925175157_add_classification_indicator_to_raster_variable.rb +5 -0
- data/db/migrate/20140930142006_remove_boundary_id_from_geog_instance.rb +6 -0
- data/db/migrate/20141003164150_add_terrapop_sample_id_to_map_and_geog_instance.rb +11 -0
- data/db/migrate/20141029202813_add_nhgis_dat_file_to_sample_geog_level.rb +5 -0
- data/db/migrate/20141029204521_add_columns_to_sample_level_area_data_variable.rb +6 -0
- data/db/migrate/20141104212652_create_categorical_raster_summarization.rb +39 -0
- data/db/migrate/20141105202744_add_margin_file_to_sample_geog_level.rb +5 -0
- data/db/migrate/20141105205347_add_margin_field_to_area_data_value.rb +5 -0
- data/db/migrate/20141105205607_add_join_fields_to_sample_geog_level.rb +8 -0
- data/db/migrate/20141202180411_add_new_categorical_summarization_function.rb +62 -0
- data/db/migrate/20141212172044_add_continuous_raster_summarization0.rb +51 -0
- data/db/migrate/20141212195611_add_indexes_to_boundaries.rb +10 -0
- data/db/migrate/20141212202521_add_indexes_to_frequencies.rb +7 -0
- data/db/migrate/20141229150743_add_special_value_to_area_data_value.rb +5 -0
- data/db/migrate/20141230153550_add_field_to_global_regions.rb +8 -0
- data/db/migrate/20150107142518_add_restriction_indicated_to_sample.rb +5 -0
- data/db/migrate/20150114161817_add_raster_to_tiff_function.rb +35 -0
- data/db/migrate/20150115204303_add_hide_nhgis_datasets_to_users.rb +11 -0
- data/db/migrate/20150126192918_add_new_gli_post_gis_functions.rb +99 -0
- data/db/migrate/20150126223419_add_short_label_to_terrapop_samples.rb +11 -0
- data/db/migrate/20150127172953_add_another_raster_summarization_function.rb +44 -0
- data/db/migrate/20150130163215_new_glc_summarization_function.rb +40 -0
- data/db/migrate/20150211221354_create_cache_items.rb +23 -0
- data/db/migrate/20150212223011_add_microdata_access_expired_date_to_users.rb +11 -0
- data/db/migrate/20150217221940_add_new_band_aware_categorical_to_binary_summarization.rb +177 -0
- data/db/migrate/20150302145459_removeuse_postgis_procedure_for_geotiff.rb +5 -0
- data/db/migrate/20150313194752_add_color_map_to_tiff_output.rb +34 -0
- data/db/migrate/20150313202158_add_color_map_to_jpeg_output.rb +34 -0
- data/db/migrate/20150318183314_add_non_color_map_cookie_cutter_functions.rb +65 -0
- data/db/migrate/20150324160629_add_categorical_multi_band_summarization.rb +62 -0
- data/db/migrate/20150324161827_add_index_to_rasters_raster_variable_id.rb +5 -0
- data/db/migrate/20150327203257_add_band_to_terrapop_raster_summary_cache.rb +5 -0
- data/db/migrate/20150331142232_add_xml_field_to_map.rb +5 -0
- data/db/migrate/20150331153703_add_new_continous_summarization.rb +38 -0
- data/db/migrate/20150409153145_categorical_to_binary_as_raster.rb +49 -0
- data/db/migrate/20150413204130_generic_categorical_to_binary_raster_output_function.rb +92 -0
- data/db/migrate/20150416133743_ratio_area_level_data_to_raster_function.rb +55 -0
- data/db/migrate/20150416143838_projection_function_for_single_band_rasters.rb +27 -0
- data/db/migrate/20150419203614_add_raster_dataset_to_terrapop_raster_summary_cache.rb +12 -0
- data/db/migrate/20150419232521_add_raster_dataset_to_request_raster_variable.rb +9 -0
- data/db/migrate/20150427163939_create_single_binary_from_categorical_to_tiff_function.rb +51 -0
- data/db/migrate/20150518200435_add_new_binary_cookie_cutter_functions.rb +95 -0
- data/db/migrate/20150520195145_revised_glc_binary_summarization_function.rb +64 -0
- data/db/migrate/20150526205918_new_categorical_to_binary_summarization.rb +72 -0
- data/db/migrate/20150527144243_even_newer_glc_binary_function.rb +79 -0
- data/db/migrate/20150527191853_add_even_newer_glc_category_to_binary_function.rb +74 -0
- data/db/migrate/20150528141915_yancat_to_bin_summarization_function.rb +66 -0
- data/db/migrate/20150529182542_add_indexes_to_geog_instances.rb +9 -0
- data/db/migrate/20150601160855_drop_area_data_variable_availability_caches.rb +5 -0
- data/db/migrate/20150625150152_add_geog_instance_f_key_on_boundaries.rb +5 -0
- data/db/migrate/20150626144305_geog_instance_geog_code_wider.rb +6 -0
- data/db/migrate/20150709161201_glc_summarization_version5.rb +79 -0
- data/db/migrate/20150713165442_glc_summarization_version6.rb +82 -0
- data/db/migrate/20150713185652_tp_jpeg_raster_clip_color_map_v2.rb +34 -0
- data/db/migrate/20150716182438_new_rasters_table.rb +18 -0
- data/db/migrate/20150716184828_new_stored_procedures_for_new_rasters.rb +70 -0
- data/db/migrate/20150721161943_remove_ownership_statement_from_function.rb +69 -0
- data/db/migrate/20150727134942_rename_rasters_new_to_new_rasters.rb +19 -0
- data/db/migrate/20150727135614_update_table_name_in_make_jpeg2.rb +70 -0
- data/db/migrate/20150727143159_jpeg_clip_experiment.rb +36 -0
- data/db/migrate/20150727145556_create_new_tiff_raster_clip_with_buffer.rb +34 -0
- data/db/migrate/20150727161508_update_table_name_in_make_jpeg2_part_deux.rb +77 -0
- data/db/migrate/20150727193403_drop_rasters_new.rb +5 -0
- data/db/migrate/20150728184718_make_jpeg2_part_deux.rb +70 -0
- data/db/migrate/20150728214344_correct_new_rasters_table_in_new_make_jpeg2_function.rb +79 -0
- data/db/migrate/20150729144526_even_more_correct_new_rasters_table_in_new_make_jpeg2_function.rb +78 -0
- data/db/migrate/20150729160936_fixingterrapop_reclassify_categorical_raster_to_binary_summariz_v3.rb +68 -0
- data/db/migrate/20150730141036_adjust_jpeg_clip_for_categorical.rb +67 -0
- data/db/migrate/20150730153216_ststandardize_terrapop_reclassify_categorical_raster_to_binary_summariz_v3.rb +69 -0
- data/db/migrate/20150730163446_add_origin_to_extract_requests.rb +5 -0
- data/db/migrate/20150731151304_consistent_return_fieldsterrapop_gli_yield_areal_summarization.rb +99 -0
- data/db/migrate/20150731192327_add_boundary_only_field_to_terrapop_sample.rb +5 -0
- data/db/migrate/20150803213048_add_function_to_detect_boundaries_that_wrap_globe.rb +50 -0
- data/db/migrate/20150814154127_add_processing_flag_to_extract_request.rb +5 -0
- data/db/migrate/20150814165605_add_colormapped_categorical_to_binary_jpeg_cookie_cutteringizing_function.rb +49 -0
- data/db/migrate/20150814183708_around_the_world_wrap_a_raster_function.rb +157 -0
- data/db/migrate/20150910194333_add_extract_grouping_field_to_extract_request.rb +5 -0
- data/db/migrate/20150915194808_drop_sessions_table.rb +5 -0
- data/db/migrate/20150915215426_add_sessions_table.rb +12 -0
- data/db/migrate/20151009203606_create_sample_detail_groups.rb +8 -0
- data/db/migrate/20151009203855_create_sample_detail_fields.rb +13 -0
- data/db/migrate/20151009204052_create_sample_detail_values.rb +12 -0
- data/db/migrate/20151016152953_add_indexes_to_area_data_values.rb +7 -0
- data/db/migrate/20151023160555_add_data_to_extract_requests.rb +8 -0
- data/db/migrate/20151026155953_rename_description_add_title_to_extract_requests.rb +8 -0
- data/db/migrate/20151029144017_create_raster_dataset_groups.rb +9 -0
- data/db/migrate/20151029144147_add_raster_dataset_group_to_raster_dataset.rb +9 -0
- data/db/migrate/20151029182802_add_mnemonic_to_raster_dataset_group.rb +5 -0
- data/db/migrate/20151029184642_change_field_type_on_raster_dataset_group.rb +5 -0
- data/db/migrate/20151029210539_remove_unnecessary_fields_from_terrapop_sample.rb +60 -0
- data/db/migrate/20151102205254_create_data_artifacts.rb +17 -0
- data/db/migrate/20151102211601_add_json_field_to_extract_data_artifacts.rb +8 -0
- data/db/migrate/20151103152754_add_file_name_field_to_extract_request.rb +5 -0
- data/db/migrate/20151106155249_add_submitted_at_to_extract_request.rb +5 -0
- data/db/migrate/20151110204826_add_terra_pop_build_number_to_extract_request.rb +12 -0
- data/db/migrate/20151119213428_create_area_data_raster_variable_mnemonic_lookups.rb +18 -0
- data/db/migrate/20151120140757_create_extract_request_area_data_raster_variable_mnemonic_lookups.rb +16 -0
- data/db/migrate/20151130212011_add_new_raster_summarization_v7.rb +90 -0
- data/lib/tasks/terrapop_models_tasks.rake +4 -0
- data/lib/terrapop_models.rb +4 -0
- data/lib/terrapop_models/engine.rb +13 -0
- data/lib/terrapop_models/version.rb +3 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +68 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +78 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/assets.rb +8 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/log/development.log +62 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/terrapop_models_test.rb +7 -0
- data/test/test_helper.rb +19 -0
- metadata +597 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
require 'csv'
|
|
2
|
+
|
|
3
|
+
####
|
|
4
|
+
#
|
|
5
|
+
# To get the _geog_setup.yml files, run things like this:
|
|
6
|
+
#
|
|
7
|
+
# Country.where({}).each{|country| SampleDesign.to_geog_setup(country) }
|
|
8
|
+
#
|
|
9
|
+
|
|
10
|
+
class SampleDesign < ActiveRecord::Base
|
|
11
|
+
|
|
12
|
+
belongs_to :country
|
|
13
|
+
|
|
14
|
+
# Parses a sample design file (which is tab-delimited CSV) for a specified sample, returning
|
|
15
|
+
# the metadata in a hashtable. We use the CSV library as the parsed files use some of the
|
|
16
|
+
# more obscure features of CSVs, such as multiline values.
|
|
17
|
+
|
|
18
|
+
@@has_startup = false
|
|
19
|
+
|
|
20
|
+
def self.startup
|
|
21
|
+
|
|
22
|
+
unless @@has_startup
|
|
23
|
+
@tag_mapping = {
|
|
24
|
+
'sample_id' => [''.upcase],
|
|
25
|
+
'label' => ['custom:label'.upcase],
|
|
26
|
+
'description' => ['census characteristics:title'.upcase],
|
|
27
|
+
'local_title' => [''.upcase],
|
|
28
|
+
'is_weighted' => [''.upcase],
|
|
29
|
+
'census_agency' => ['census characteristics:census agency'.upcase],
|
|
30
|
+
'population_universe' => ['census characteristics:population universe'.upcase],
|
|
31
|
+
'de_jure_or_de_facto' => ['census characteristics:de jure or de facto'.upcase],
|
|
32
|
+
'enumeration_unit' => ['census characteristics:enumeration unit'.upcase],
|
|
33
|
+
'census_start_date' => ['census characteristics:census day'.upcase],
|
|
34
|
+
'census_end_date' => [''.upcase],
|
|
35
|
+
'fieldwork_start_period' => ['census characteristics:census day'.upcase],
|
|
36
|
+
'fieldwork_end_period' => [''.upcase],
|
|
37
|
+
'enumeration_forms' => ['census characteristics:enumeration forms'.upcase],
|
|
38
|
+
'type_of_fieldwork' => ['census characteristics:type of fieldwork'.upcase],
|
|
39
|
+
'respondent' => ['census characteristics:respondent'.upcase],
|
|
40
|
+
'coverage' => ['census characteristics:coverage'.upcase],
|
|
41
|
+
'undercount' => ['census characteristics:undercount'.upcase],
|
|
42
|
+
'undercount_notes' => [''.upcase],
|
|
43
|
+
|
|
44
|
+
'microdata_source' => ['microdata sample characteristics:microdata source'.upcase],
|
|
45
|
+
'long_form_sample_design' => [''.upcase],
|
|
46
|
+
'mpc_sample_design' => [''.upcase],
|
|
47
|
+
'sample_unit' => ['microdata sample characteristics:sample unit'.upcase],
|
|
48
|
+
'sample_fraction' => ['microdata sample characteristics:sample fraction'.upcase],
|
|
49
|
+
'sample_fraction_notes' => [''.upcase],
|
|
50
|
+
'sample_size' => ['microdata sample characteristics:sample size (person records)'.upcase],
|
|
51
|
+
'sample_weights' => ['microdata sample characteristics:sample weights'.upcase],
|
|
52
|
+
'sample_characteristics_notes' => [''.upcase],
|
|
53
|
+
'sample_general_notes' => [''.upcase],
|
|
54
|
+
|
|
55
|
+
'has_dwellings' => ['units identified:dwellings'.upcase],
|
|
56
|
+
'has_dwellings_note' => [''.upcase],
|
|
57
|
+
'has_vacant_units' => ['Units identified:Vacant units'.upcase, 'Units identified:Vacant dwellings'.upcase],
|
|
58
|
+
'has_vacant_units_note' => [''.upcase],
|
|
59
|
+
'has_closed_units' => [''.upcase],
|
|
60
|
+
'has_closed_units_note' => [''.upcase],
|
|
61
|
+
'smallest_geography' => ['units identified:smallest geography'.upcase],
|
|
62
|
+
|
|
63
|
+
'has_households' => ['units identified:households'.upcase],
|
|
64
|
+
'has_households_note' => [''.upcase],
|
|
65
|
+
'has_families' => ['units identified:families'.upcase],
|
|
66
|
+
'has_families_note' => [''.upcase],
|
|
67
|
+
'has_individuals' => ['units identified:individuals'.upcase],
|
|
68
|
+
'has_individuals_note' => [''.upcase],
|
|
69
|
+
'has_group_quarters' => ['Units identified:Group quarters'.upcase, 'Units identified:Group quarters (Collective households)'.upcase],
|
|
70
|
+
'has_group_quarters_note' => [''.upcase],
|
|
71
|
+
'has_indigenous_pop' => ['units identified:indigenous population'.upcase],
|
|
72
|
+
'has_indigenous_pop_note' => [''.upcase],
|
|
73
|
+
'has_special_pop' => ['units identified:special populations'.upcase],
|
|
74
|
+
'has_special_pop_note' => [''.upcase],
|
|
75
|
+
'units_notes' => [''.upcase],
|
|
76
|
+
'identification_general_notes' => [''.upcase],
|
|
77
|
+
|
|
78
|
+
'unit_definition_household' => ['Unit definitions:Households'.upcase, 'Unit definitions:Private Household'.upcase],
|
|
79
|
+
'unit_definition_family' => ['unit definitions:families'.upcase],
|
|
80
|
+
'unit_definition_group_quarters' => ['Unit definitions:Group quarters'.upcase, 'Unit definitions:Group Quarters (Collective households)'.upcase],
|
|
81
|
+
'unit_definition_dwelling' => ['unit definitions:dwellings'.upcase],
|
|
82
|
+
'unit_definition_homeless_population' => [''.upcase],
|
|
83
|
+
'unit_definition_institution' => [''.upcase],
|
|
84
|
+
'unit_definition_institutional_population' => [''.upcase],
|
|
85
|
+
'unit_definition_notes' => [''.upcase],
|
|
86
|
+
'unit_definition_general_notes' => [''.upcase]
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@country_abbrev_lookup = Hash[Country.where({}).order(:short_name).map{|country| [country.short_name, country.full_name]}]
|
|
90
|
+
|
|
91
|
+
@@has_startup = true
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def self.parse(string)
|
|
97
|
+
if string =~ /\A[Yy]es\Z/
|
|
98
|
+
# is it a 'yes'?
|
|
99
|
+
true
|
|
100
|
+
elsif string =~ /\A[Nn]o\Z/ or string =~ /Not available in microdata sample/ or string =~ /---/
|
|
101
|
+
#is it a 'no'?
|
|
102
|
+
false
|
|
103
|
+
elsif string =~ /\A\d+(.\d+)?%\Z/
|
|
104
|
+
# is it a percentage? (which could look like 100% or like 10.5%)
|
|
105
|
+
numeric_portion = string.chop
|
|
106
|
+
(numeric_portion.to_i) / 100.0
|
|
107
|
+
elsif string =~ /\A\d+\Z/ or string =~ /\A(\d{1,3},?)+\Z/
|
|
108
|
+
# is it an int with or without commas?
|
|
109
|
+
numeric_portion = string.gsub(',', '')
|
|
110
|
+
numeric_portion.to_i
|
|
111
|
+
else
|
|
112
|
+
# just return the argument itself.
|
|
113
|
+
string
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# country code is in the form <2-char country id><4-digit year><sample_id>
|
|
118
|
+
# such as us1990a for the US 1990 census.
|
|
119
|
+
# returns a hash with keys of :abbrev, :country and :year
|
|
120
|
+
# or nil if the name doesn't match the regex.
|
|
121
|
+
def self.parse_sample_id(name)
|
|
122
|
+
# $stderr.puts name
|
|
123
|
+
code_regex = /(?<abbrev>[a-z]{2})(?<year>\d{4})(?<sample_id>[a-z])/
|
|
124
|
+
match = code_regex.match(name)
|
|
125
|
+
if match.nil?
|
|
126
|
+
nil
|
|
127
|
+
else
|
|
128
|
+
# $stderr.puts "==> #{match[:abbrev]}"
|
|
129
|
+
{:abbrev => match[:abbrev], :year => match[:year], :country => @country_abbrev_lookup[match[:abbrev]]}
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# returns the dataset entry as a hash ready to be converted to YAML.
|
|
134
|
+
def self.construct_sample_entry(possible_tags, name, contents)
|
|
135
|
+
sampledesc_hash = {'sample_id' => name}
|
|
136
|
+
output = {}
|
|
137
|
+
possible_tags.each { |key, value|
|
|
138
|
+
if value.count > 0
|
|
139
|
+
sampledesc_key = value.detect { |sampledesc_key| contents.has_key? (sampledesc_key) }
|
|
140
|
+
unless sampledesc_key.nil?
|
|
141
|
+
unless contents[sampledesc_key].nil?
|
|
142
|
+
sampledesc_hash[key] = parse(contents[sampledesc_key].strip)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
output = {'terrapop_samples' => [sampledesc_hash]}
|
|
148
|
+
}
|
|
149
|
+
output
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Return an array of sample_geog_level instances.
|
|
153
|
+
# For now, just construct national and GEOLEV1 entries here. As more are added, add more.
|
|
154
|
+
#
|
|
155
|
+
def self.construct_sample_geog_levels(sample_id, abbrev, name, year, contents)
|
|
156
|
+
national = {
|
|
157
|
+
'terrapop_sample_id' => "#{name} #{year}",
|
|
158
|
+
'label' => "#{name}: National, #{year}",
|
|
159
|
+
'internal_code' => "#{sample_id}_NAT",
|
|
160
|
+
'geolink_variable_id' => 'CNTRY',
|
|
161
|
+
'country_level_id' => [{'geog_unit_id' => 'NAT'}, {'country_id' => "#{abbrev}"}]
|
|
162
|
+
}
|
|
163
|
+
geolev1 = {
|
|
164
|
+
'terrapop_sample_id' => "#{name} #{year}",
|
|
165
|
+
'label' => "#{name}: First Level (Harmonized), #{year}",
|
|
166
|
+
'internal_code' => "#{sample_id}_HFLAD",
|
|
167
|
+
'geolink_variable_id' => 'GEOLEV1',
|
|
168
|
+
'country_level_id' => [{'geog_unit_id' => 'HFLAD'}, {'country_id' => "#{abbrev}"}]
|
|
169
|
+
}
|
|
170
|
+
[national, geolev1]
|
|
171
|
+
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def self.to_geog_setup(country)
|
|
175
|
+
|
|
176
|
+
unless country.kind_of? Country
|
|
177
|
+
raise "Object passed to SampleDesign::to_geog_setup must be of type Country"
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
sd = self.where({:country_id => country.id}).first
|
|
181
|
+
|
|
182
|
+
if sd.nil?
|
|
183
|
+
$stderr.puts "==> country_id #{country.id} [#{country.full_name}] not found for SampleDesign"
|
|
184
|
+
else
|
|
185
|
+
|
|
186
|
+
startup
|
|
187
|
+
|
|
188
|
+
column = -1
|
|
189
|
+
cat = key = ''
|
|
190
|
+
result = {}
|
|
191
|
+
|
|
192
|
+
contents = nil
|
|
193
|
+
|
|
194
|
+
begin
|
|
195
|
+
contents = CSV.parse(sd.document, {headers: true, col_sep: "\t", encoding: "iso-8859-1:utf-8"}) # CSV.read(path, {headers: true, col_sep: "\t", encoding: "iso-8859-1:utf-8"})
|
|
196
|
+
rescue Exception => e
|
|
197
|
+
throw e
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
unless contents.nil?
|
|
201
|
+
# now flip it over.
|
|
202
|
+
|
|
203
|
+
# first, drop the first two elements from the header to get the dataset names.
|
|
204
|
+
dataset_titles = contents.headers
|
|
205
|
+
dataset_titles.shift
|
|
206
|
+
dataset_titles.shift
|
|
207
|
+
|
|
208
|
+
# make a hash of hashes to hold the flipped table
|
|
209
|
+
datasets = {}
|
|
210
|
+
# and set up the sample label for each entry, initialized with the label field.
|
|
211
|
+
dataset_titles.each { |ds|
|
|
212
|
+
label_info = parse_sample_id(ds)
|
|
213
|
+
unless label_info.nil?
|
|
214
|
+
datasets[ds] = {'CUSTOM:LABEL' => "#{label_info[:country]} #{label_info[:year]}"}
|
|
215
|
+
end
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
# now run through the rows of the CSV and build out the dataset sample descriptions
|
|
219
|
+
category = 'heading'
|
|
220
|
+
contents.each { |row|
|
|
221
|
+
|
|
222
|
+
unless row['item'].nil?
|
|
223
|
+
# puts row.inspect
|
|
224
|
+
this_field = row['item'].strip
|
|
225
|
+
this_category = row['heading']
|
|
226
|
+
category = this_category.strip unless this_category.nil? or this_category.empty?
|
|
227
|
+
|
|
228
|
+
field = "#{category}:#{this_field}".upcase # get the field heading
|
|
229
|
+
|
|
230
|
+
# and then get the value of that field heading for each dataset,
|
|
231
|
+
# and put it into the appropriate subhash in the datasets hash.
|
|
232
|
+
dataset_titles.each { |ds|
|
|
233
|
+
if datasets.has_key? ds
|
|
234
|
+
datasets[ds][field] = row[ds]
|
|
235
|
+
end
|
|
236
|
+
}
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
datasets.each { |name, contents|
|
|
242
|
+
$stderr.puts " +++ Working on dataset[#{name}]...".color(:green)
|
|
243
|
+
File.open(File.join(Rails.root.to_s, "data/geog_setup", "#{name}_geog_setup.yml"), 'w+') {|file|
|
|
244
|
+
$stderr.puts " +++ Writing #{file.path}..."
|
|
245
|
+
sample_info = parse_sample_id(name)
|
|
246
|
+
terrapop_sample = construct_sample_entry(@tag_mapping, name, contents)
|
|
247
|
+
terrapop_sample['terrapop_samples'][0]['short_country_name'] = country.short_name
|
|
248
|
+
terrapop_sample['terrapop_samples'][0]['year'] = terrapop_sample['terrapop_samples'][0]['sample_id'][2,4].to_i
|
|
249
|
+
# $stderr.puts terrapop_sample.to_s
|
|
250
|
+
geog_info = construct_sample_geog_levels(name, sample_info[:abbrev], sample_info[:country],sample_info[:year], contents)
|
|
251
|
+
terrapop_sample['sample_geog_levels'] = geog_info
|
|
252
|
+
file.puts terrapop_sample.to_yaml
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
{status: :OK}
|
|
257
|
+
else
|
|
258
|
+
{status: :FAILED, message: "#{country.full_name} failed to produce geog_setup yaml..."}
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def self.fields(sample)
|
|
264
|
+
|
|
265
|
+
unless sample.kind_of? Sample
|
|
266
|
+
raise "Object passed to SampleDesign::fields must be of type Sample"
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
sd = self.where({:country_id => sample.country_id}).first
|
|
270
|
+
|
|
271
|
+
if sd.nil?
|
|
272
|
+
raise "country_id #{sample.country_id} not found for SampleDesign"
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
column = -1
|
|
276
|
+
cat = key = ''
|
|
277
|
+
result = {}
|
|
278
|
+
|
|
279
|
+
CSV.parse(sd.document, :col_sep => "\t", :row_sep => "\r\n").each_with_index do |record, record_no|
|
|
280
|
+
record.each_with_index do |field, field_no|
|
|
281
|
+
next if field.nil?
|
|
282
|
+
field.strip!
|
|
283
|
+
case record_no
|
|
284
|
+
when 0 then column = field_no if field == sample.name # find the sample's column in the first line
|
|
285
|
+
else # all other lines, build the result hashtable
|
|
286
|
+
case field_no
|
|
287
|
+
when 0 then (cat = field) unless field.empty?
|
|
288
|
+
when 1 then (key = cat + ':' + field) unless field.empty?
|
|
289
|
+
when column then result[key] = field
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
result
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
class SampleDetails
|
|
2
|
+
|
|
3
|
+
class Collection
|
|
4
|
+
def initialize(samples, groups, fields, values)
|
|
5
|
+
@samples = samples.to_a
|
|
6
|
+
@countries = @samples.map { |s| s.country }.uniq.sort { |a, b| a.full_name <=> b.full_name }
|
|
7
|
+
@groups = groups.to_a.sort { |a, b| a.order <=> b.order }
|
|
8
|
+
@fields = fields.to_a
|
|
9
|
+
@values = values.to_a
|
|
10
|
+
|
|
11
|
+
sample_map = Hash[@samples.map { |s| [s.id, s] }]
|
|
12
|
+
@value_sample_map = {}
|
|
13
|
+
@group_sample_map = {}
|
|
14
|
+
|
|
15
|
+
@values.each do |v|
|
|
16
|
+
s = sample_map[v.sample_id]
|
|
17
|
+
g = v.sample_detail_field.sample_detail_group
|
|
18
|
+
(@value_sample_map[s] ||= []) << v
|
|
19
|
+
(@group_sample_map[s] ||= {})[g] = nil
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
@group_sample_map.each { |s, v| @group_sample_map[s] = v.keys }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def countries
|
|
26
|
+
@countries
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def samples(for_country = nil)
|
|
30
|
+
if for_country
|
|
31
|
+
@samples.select { |s| s.country == for_country }
|
|
32
|
+
else
|
|
33
|
+
@samples
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def groups(used_by_sample = nil)
|
|
38
|
+
if used_by_sample
|
|
39
|
+
@group_sample_map[used_by_sample] || []
|
|
40
|
+
else
|
|
41
|
+
@groups
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def fields(for_group = nil, exclude_summary_only = false)
|
|
46
|
+
if for_group
|
|
47
|
+
data = @fields.select { |f| f.sample_detail_group == for_group }
|
|
48
|
+
else
|
|
49
|
+
data = @fields
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
if exclude_summary_only
|
|
53
|
+
data.reject { |f| f.summary_only }
|
|
54
|
+
else
|
|
55
|
+
data
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def value(sample, field)
|
|
60
|
+
field = case field
|
|
61
|
+
when SampleDetailField
|
|
62
|
+
field
|
|
63
|
+
when String
|
|
64
|
+
@fields.detect { |f| f.name == field }
|
|
65
|
+
else
|
|
66
|
+
nil
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
return nil unless sample && field
|
|
70
|
+
|
|
71
|
+
list = @value_sample_map[sample] || []
|
|
72
|
+
list.detect { |v| v.sample_detail_field_id == field.id }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Returns a SampleDetails::Collection object for the given samples (which should be a relation or list of AR Sample objects)
|
|
78
|
+
# optionally, if detail_fields are specified, only those details fields will be returned (expects a list of strings)
|
|
79
|
+
def self.for(samples, detail_fields = [])
|
|
80
|
+
fields = SampleDetailField.eager_load(:sample_detail_group).order(:order)
|
|
81
|
+
values = SampleDetailValue.preload({:sample_detail_field => :sample_detail_group}).where(sample_id: samples)
|
|
82
|
+
|
|
83
|
+
if detail_fields && !detail_fields.empty?
|
|
84
|
+
fields = fields.where(name: detail_fields)
|
|
85
|
+
values = values.where(sample_detail_field_id: fields)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
Collection.new(samples, fields.map { |f| f.sample_detail_group }.uniq, fields, values)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
class SampleGeogLevel < ActiveRecord::Base
|
|
2
|
+
|
|
3
|
+
has_many :geog_instances
|
|
4
|
+
has_many :sample_level_area_data_variables
|
|
5
|
+
has_many :request_raster_variables
|
|
6
|
+
has_many :request_area_data_variables
|
|
7
|
+
has_many :area_data_rasters
|
|
8
|
+
has_many :area_data_variables, through: :sample_level_area_data_variables
|
|
9
|
+
|
|
10
|
+
belongs_to :country_level
|
|
11
|
+
belongs_to :terrapop_sample
|
|
12
|
+
# geolinking_variable is the id of the variable to link with when attaching area-level characteristics to microdata extracts.
|
|
13
|
+
belongs_to :geolink_variable, class_name: 'Variable', foreign_key: 'geolink_variable_id'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def api_attributes
|
|
17
|
+
"TODO"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def geog_unit
|
|
22
|
+
country_level.geog_unit
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def map
|
|
27
|
+
Map.where(country_level_id: country_level_id, terrapop_sample_id: terrapop_sample_id).first
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def self.long_description(sample_geog_levels)
|
|
32
|
+
if sample_geog_levels.count > 0
|
|
33
|
+
level_order = ['NAT', 'HFLAD', 'FLAD', 'HSLAD', 'SLAD']
|
|
34
|
+
levels = {}
|
|
35
|
+
str = []
|
|
36
|
+
sample_geog_levels.each do |sgl|
|
|
37
|
+
levels[sgl.country_level.geog_unit.code] = [] unless levels.has_key?(sgl.country_level.geog_unit.code)
|
|
38
|
+
levels[sgl.country_level.geog_unit.code] << sgl.long_description
|
|
39
|
+
end
|
|
40
|
+
levels.each{ |key, lvls| levels[key] = lvls.sort }
|
|
41
|
+
level_order.each do |lvl|
|
|
42
|
+
if levels.has_key? lvl
|
|
43
|
+
str << GeogUnit.where(code: lvl).first.label + " (" + lvl + ")"
|
|
44
|
+
levels[lvl].each{ |lvl_txt| str << " " + lvl_txt }
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
str.join("\n")
|
|
48
|
+
else
|
|
49
|
+
"No Geographic Levels"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def long_description
|
|
55
|
+
terrapop_sample.country_name_long_year + ": " + (country_level.geog_unit.code == "NAT" ? "National" : country_level.label)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Use the geolinking variable from the microdata to help generate the
|
|
59
|
+
# AreaVariable stubs that are the geography instances
|
|
60
|
+
# on each row of the area data tables. We need four:
|
|
61
|
+
# 1. geog level label (State, county, etc.)
|
|
62
|
+
# 2. geog level code: (STATEBR, STATEUS, etc.)
|
|
63
|
+
# 3. geog instance label ("Alabama","Hennepin", etc.)
|
|
64
|
+
# 4. geog instance code (25,28, whatever codes are used for categories of 3
|
|
65
|
+
def variables_for_area_data_extracts
|
|
66
|
+
geog_instance_variable = "GEOG_CODE"
|
|
67
|
+
geog_instance_variable = geolink_variable.mnemonic || "GEOG_CODE" unless geolink_variable.nil?
|
|
68
|
+
geog_instance_label = "#{geog_instance_variable}_LABEL"
|
|
69
|
+
|
|
70
|
+
adrvml_code = AreaDataRasterVariableMnemonicLookup.where(composite_mnemonic: geog_instance_variable).first
|
|
71
|
+
|
|
72
|
+
if adrvml_code.nil?
|
|
73
|
+
adrvml_code = AreaDataRasterVariableMnemonicLookup.new
|
|
74
|
+
adrvml_code.description = 'GIS match code'
|
|
75
|
+
|
|
76
|
+
unless geolink_variable.nil?
|
|
77
|
+
adrvml_code.description += ' [' + geolink_variable.label + ']'
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
adrvml_code.composite_mnemonic = geog_instance_variable
|
|
81
|
+
adrvml_code.mnemonic = geog_instance_variable
|
|
82
|
+
|
|
83
|
+
adrvml_code.save
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
adrvml_label = AreaDataRasterVariableMnemonicLookup.where(composite_mnemonic: geog_instance_label).first
|
|
87
|
+
|
|
88
|
+
if adrvml_label.nil?
|
|
89
|
+
adrvml_label = AreaDataRasterVariableMnemonicLookup.new
|
|
90
|
+
adrvml_label.description = 'Name of geographic instances'
|
|
91
|
+
adrvml_label.composite_mnemonic = geog_instance_label
|
|
92
|
+
adrvml_label.mnemonic = geog_instance_label
|
|
93
|
+
adrvml_label.save
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
[
|
|
97
|
+
# ExtractVariableStub.new(:mnemonic => "Geog_level_label", :label=>"Geog level label", :len => 32, :data_type => "alphabetical"),
|
|
98
|
+
# ExtractVariableStub.new(:mnemonic => "Geog_level_code", :label=>"Geog level code", :len => 10, :data_type => "alphabetical"),
|
|
99
|
+
ExtractVariableStub.new(mnemonic: geog_instance_label, label: "Geog instance label", len: 32, data_type: "alphabetical"),
|
|
100
|
+
ExtractVariableStub.new(mnemonic: geog_instance_variable, label: "Geog instance code", len: 10, data_type: "integer")
|
|
101
|
+
]
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
#from_nhgis_terrapop_sample presumes that the terrapop sample is associated to an NHGIS dataset; if it is not, return an empty set
|
|
105
|
+
# the number of sample geog levels returned depends upon the number of country levels associated to the terrapop
|
|
106
|
+
# sample; e.g. 3: one for US-NAT (United States), one for US-HFLAD (states), and one for US-HSLAD (counties)
|
|
107
|
+
def self.from_nhgis_terrapop_sample(nhgis_terrapop_sample)
|
|
108
|
+
#return an empty list if the terrapop sample is not linked to an NHGIS dataset
|
|
109
|
+
return [] if nhgis_terrapop_sample.nhgis_dataset_id.nil?
|
|
110
|
+
#TODO create a relation in Terrapop Sample? too drastic
|
|
111
|
+
nhgis_dataset = Nhgis::Dataset.where(id: nhgis_terrapop_sample.nhgis_dataset_id).first
|
|
112
|
+
return [] if nhgis_dataset.nil?
|
|
113
|
+
#identify the country for the TerrapopSample
|
|
114
|
+
country = nhgis_terrapop_sample.country
|
|
115
|
+
raise "expecting the terrapop sample label to include the name of the country '#{country.full_name}'" unless nhgis_terrapop_sample.label.include? country.full_name
|
|
116
|
+
# only those NHGIS datasets having nation-, state-, or county-level data are ever to be considered for terrapop samples. There are some NHGIS datasets that
|
|
117
|
+
# participate in time series tables but do not have any nation-, state-, or county-level data. Since Terrapop only has NAT, *FLAD, *SLAD, those datasets are
|
|
118
|
+
# to be excluded.
|
|
119
|
+
# conversion from NHGIS geog levels/geog units to Terrapop geog units
|
|
120
|
+
nhgis_gl_to_terrapop_gu = {"nation" => "NAT", "state" => "FLAD", "county" => "SLAD"}
|
|
121
|
+
valid_geog_units = nhgis_dataset.data_groups.reject{ |dg| dg.relative_pathname.nil? }.map{ |dg| dg.relative_pathname.nil? ? nil : nhgis_gl_to_terrapop_gu[dg.geog_level.istads_id] }.reject{ |gl_istads_id| gl_istads_id.nil? }
|
|
122
|
+
geog_unit_ids = GeogUnit.where(code: valid_geog_units).pluck(:id)
|
|
123
|
+
#identify all of the country levels for the terrapop sample's country
|
|
124
|
+
country_levels = CountryLevel.where(country_id: nhgis_terrapop_sample.country_id, geog_unit_id: geog_unit_ids).all
|
|
125
|
+
country_levels.map do |country_level|
|
|
126
|
+
sgl = SampleGeogLevel.new
|
|
127
|
+
sgl.country_level = country_level
|
|
128
|
+
sgl.terrapop_sample = nhgis_terrapop_sample
|
|
129
|
+
gu = country_level.geog_unit
|
|
130
|
+
sgl.internal_code = "#{country.short_name}#{nhgis_dataset.code}_#{gu.code}"
|
|
131
|
+
harmonized = ["HFLAD", "HSLAD"].include?(gu.code) ? " (Harmonized)" : "" #National country level need not be harmonized; only states and counties are harmonized
|
|
132
|
+
country_level_label = gu.code == "NAT" ? gu.label : country_level.label #use the geog unit label... which is expected to be 'National' (whereas United States represents extent)
|
|
133
|
+
sgl.label = nhgis_terrapop_sample.label.gsub(country.full_name, "#{country.full_name}: #{country_level_label}#{harmonized},")
|
|
134
|
+
sgl #do not set values for id, created_at, updated_at, code, and geolink_variable
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def self.geography_name(sample_geog_level)
|
|
139
|
+
if sample_geog_level.nil?
|
|
140
|
+
""
|
|
141
|
+
else
|
|
142
|
+
if sample_geog_level.geolink_variable.nil?
|
|
143
|
+
sample_geog_level.terrapop_sample.short_country_name.upcase + "_" + sample_geog_level.country_level.geog_unit.code.upcase
|
|
144
|
+
else
|
|
145
|
+
sample_geog_level.geolink_variable.mnemonic
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
end
|