Skip to content

Commit 26caf01

Browse files
Merge branch 'datacommonsorg:master' into norwayAuto
2 parents 358ed35 + 67308cf commit 26caf01

46 files changed

Lines changed: 3725 additions & 77 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

import-automation/executor/app/executor/import_executor.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575

7676
AUTO_IMPORT_JOB_STAGE = "auto-import-job-stage"
7777
AUTO_IMPORT_JOB_STATUS = "auto-import-job-status"
78+
IMPORT_SUMMARY_FILE = "import_summary.json"
79+
STAGING_PATH = "staging"
7880

7981

8082
class ImportStatus(Enum):
@@ -129,6 +131,7 @@ class ImportStatusSummary:
129131
latest_version: str = ''
130132
execution_time: int = 0 # seconds
131133
data_volume: int = 0 # bytes
134+
job_id: str = ''
132135
next_refresh: datetime = None
133136
"""Holds a set of monitoring stats for an import."""
134137
import_stats: dict = dataclasses.field(default_factory=dict)
@@ -794,11 +797,9 @@ def _update_import_status_table(
794797
]
795798
values = [
796799
import_summary.import_name, import_summary.status.name,
797-
os.getenv('BATCH_JOB_NAME',
798-
os.getenv('BATCH_JOB_UID', 'local-run')),
799-
import_summary.execution_time, import_summary.data_volume,
800-
spanner.COMMIT_TIMESTAMP, import_summary.next_refresh,
801-
import_summary.latest_version
800+
import_summary.job_id, import_summary.execution_time,
801+
import_summary.data_volume, spanner.COMMIT_TIMESTAMP,
802+
import_summary.next_refresh, import_summary.latest_version
802803
]
803804
# Update import timestamp only if import completed successfully.
804805
if import_summary.status == ImportStatus.READY:
@@ -813,15 +814,22 @@ def _update_import_status_table(
813814

814815
def _update_latest_version(self, version, output_dir, import_spec,
815816
import_summary):
817+
if self.config.skip_gcs_upload:
818+
logging.warning(
819+
"Skipping latest version update as per import config.")
820+
return
816821
logging.info(f'Updating import latest version {version}')
817822
self.uploader.upload_string(
818823
version,
819824
os.path.join(output_dir, self.config.storage_version_filename))
820825
self.uploader.upload_string(
821826
self._import_metadata_mcf_helper(import_spec),
822827
os.path.join(output_dir, self.config.import_metadata_mcf_filename))
828+
self.uploader.upload_string(
829+
json.dumps(dataclasses.asdict(import_summary), default=str),
830+
os.path.join(output_dir, IMPORT_SUMMARY_FILE))
831+
# Add current version to the history of versions if import was successful.
823832
if self.config.storage_version_history_filename:
824-
# Add current version to the history of versions.
825833
history_filename = os.path.join(
826834
output_dir, self.config.storage_version_history_filename)
827835
versions_history = [version]
@@ -847,7 +855,11 @@ def _import_one_helper(
847855
"""
848856
start_time = time.time()
849857
import_name = import_spec['import_name']
850-
import_summary = ImportStatusSummary(import_name=import_name)
858+
job_id = os.getenv('BATCH_JOB_NAME',
859+
os.getenv('BATCH_JOB_UID', 'local-run'))
860+
import_summary = ImportStatusSummary(import_name=import_name,
861+
job_id=job_id)
862+
851863
self.counters.add_counter(f'import-{import_name}', 1)
852864
urls = import_spec.get('data_download_url')
853865
if urls:
@@ -935,19 +947,22 @@ def _import_one_helper(
935947
import_summary.import_stats.get('mcf_data_size', 0) +
936948
import_summary.import_stats.get('validation_data_size', 0))
937949
logging.info(import_summary)
950+
self.uploader.upload_string(
951+
json.dumps(dataclasses.asdict(import_summary), default=str),
952+
os.path.join(output_dir, version, IMPORT_SUMMARY_FILE))
953+
938954
if self.config.ignore_validation_status or validation_status:
939955
import_summary.status = ImportStatus.READY
940-
if not self.config.skip_gcs_upload:
941-
self._update_latest_version(version, output_dir,
942-
import_spec, import_summary)
943-
else:
944-
logging.warning(
945-
"Skipping latest version update as per import config.")
946956
else:
947957
logging.error(
948-
"Skipping latest version update due to validation failure.")
958+
"Staging latest version update due to validation failure.")
949959
import_summary.status = ImportStatus.VALIDATION
950-
self._update_import_status_table(import_summary)
960+
961+
# Update version and metadata files in staging folder for failed imports
962+
version_dir = output_dir if import_summary.status == ImportStatus.READY else os.path.join(
963+
output_dir, STAGING_PATH)
964+
self._update_latest_version(version, version_dir, import_spec,
965+
import_summary)
951966

952967
if self.importer:
953968
self.importer.delete_previous_output(relative_import_dir,

scripts/fbi/hate_crime/aggregations/manifest.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
"source_files": [
2121
"hate_crime_data/*"
2222
],
23-
"cron_schedule": "0 10 21 * *"
23+
"cron_schedule": "0 10 21 * *",
24+
"resource_limits": {
25+
"cpu": 16,
26+
"memory": 256,
27+
"disk": 300
28+
}
2429
}
2530
]
26-
}
31+
}

scripts/us_bts/latch/manifest.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@
3434
"input_files/usbts_tract_household_transportation_2017_input.csv",
3535
"input_files/usbts_tract_household_transportation_2009_input.csv"
3636
],
37-
"cron_schedule": "0 1 6 * *"
37+
"cron_schedule": "0 1 6 * *",
38+
"resource_limits": {
39+
"cpu": 16,
40+
"memory": 128,
41+
"disk": 300
42+
}
3843
}
3944
]
40-
}
45+
}

scripts/us_census/pep/population_estimate_by_race/preprocess.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,12 @@ def _clean_county_2022_csv_file(df: pd.DataFrame,
517517
'2': '2020',
518518
'3': '2021',
519519
'4': '2022',
520-
'5': '2023'
520+
'5': '2023',
521+
'6': '2024',
522+
'7': '2025',
523+
'8': '2026',
524+
'9': '2027',
525+
'10': '2028'
521526
}
522527
df = df.replace({'YEAR': conversion_of_year_to_value})
523528
df.insert(6, 'geo_ID', 'geoId/', True)
@@ -1006,12 +1011,15 @@ def _transform_data(self, df: pd.DataFrame, file_path: str) -> None:
10061011
"Count_Person_AsianOrPacificIslander",\
10071012
"Count_Person_TwoOrMoreRaces","Count_Person_NonWhite"]]
10081013
df_before_2000 = self.df[self.df["Year"] < 2000]
1009-
df_county_after_2000 = self.df[(self.df["Year"] >= 2000) &
1010-
(self.df["geo_ID"] != "country/USA")
1011-
& (self.df["geo_ID"].str.len() > 9)]
1014+
df_county_after_2000 = self.df[
1015+
(self.df["Year"] >= 2000) &
1016+
(self.df["geo_ID"] != "country/USA") &
1017+
(self.df["geo_ID"].str.len() > 9)].drop_duplicates(
1018+
subset=['Year', 'geo_ID'], keep='last')
10121019
df_national_state_2000 = self.df[(self.df["Year"] >= 2000) & (
10131020
(self.df["geo_ID"].str.len() <= 9) |
1014-
(self.df["geo_ID"] == "country/USA"))]
1021+
(self.df["geo_ID"] == "country/USA"))].drop_duplicates(
1022+
subset=['Year', 'geo_ID'], keep='last')
10151023
df_before_2000.to_csv(os.path.join(
10161024
self.cleaned_csv_file_path,
10171025
"USA_Population_Count_by_Race_before_2000.csv"),

scripts/us_census/pep/us_pep_sex/process.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,11 @@ def process(self):
10921092
value_vars=['Count_Person_Male', 'Count_Person_Female'],
10931093
var_name="SV",
10941094
value_name="Observation")
1095-
1095+
subset_cols = ['Year', 'geo_ID', 'Measurement_Method', 'SV']
1096+
# 2. Drop duplicates based on those columns, keeping the first occurrence
1097+
final_df.drop_duplicates(subset=subset_cols,
1098+
keep='first',
1099+
inplace=True)
10961100
final_df.to_csv(self._cleaned_csv_file_path, index=False)
10971101
sv_list = ['Count_Person_Female', 'Count_Person_Male']
10981102
self._generate_mcf(sv_list)
@@ -1117,7 +1121,7 @@ def fetch_skip_urls_from_gcs(GCS_BUCKET_NAME: str,
11171121

11181122
def is_valid_url(url):
11191123
try:
1120-
response = requests.get(url, timeout=10)
1124+
response = requests.get(url, timeout=20)
11211125
if response.status_code != 200:
11221126
return False
11231127
content_type = response.headers.get("Content-Type", "")

scripts/us_nces/demographics/private_school/manifest.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@
2424
"cleaned_csv": "gcs_folder/output_place/us_nces_demographics_private_place.csv"
2525
}
2626
],
27-
"cron_schedule": "30 3 1 3,6,9,12 *"
27+
"cron_schedule": "30 3 1 3,6,9,12 *",
28+
"resource_limits": {
29+
"cpu": 32,
30+
"memory": 512,
31+
"disk": 300
32+
}
2833
}
2934
]
30-
}
35+
}

scripts/us_nces/demographics/private_school/process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def set_generate_statvars_flag(self, flag: bool):
6767

6868
if __name__ == '__main__':
6969
try:
70-
logging.set_verbosity(1)
70+
logging.set_verbosity(logging.INFO)
7171
logging.info("Main Method Starts For Private School District ")
7272
gcs_output_dir_local = os.path.join(
7373
os.path.dirname(os.path.abspath(__file__)), "gcs_folder")

scripts/us_nces/demographics/public_school/manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
],
2727
"cron_schedule": "30 3 2 3,6,9,12 *",
2828
"resource_limits": {
29-
"cpu": 8,
30-
"memory": 128,
31-
"disk": 200
29+
"cpu": 32,
30+
"memory": 512,
31+
"disk": 300
3232
}
3333
}
3434
]

scripts/us_nces/demographics/public_school/process.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class NCESPublicSchool(USEducation):
5353

5454
if __name__ == '__main__':
5555
try:
56-
logging.set_verbosity(1)
56+
logging.set_verbosity(logging.INFO)
5757
logging.info("Main Method Starts For Public School")
5858
gcs_output_dir_local = os.path.join(
5959
os.path.dirname(os.path.abspath(__file__)), "gcs_folder")
@@ -98,4 +98,6 @@ class NCESPublicSchool(USEducation):
9898
logging.info("Main Method Completed For Public School District ")
9999

100100
except Exception as e:
101-
logging.fatal(f"Error While Running Public School Process: {e} ")
101+
# Only log the first 1000 characters of the error message
102+
error_msg = str(e)[:1000]
103+
logging.fatal(f"Error While Running Public School Process: {error_msg}")

scripts/us_nces/demographics/school_district/manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
],
2727
"cron_schedule": "30 3 3 3,6,9,12 *",
2828
"resource_limits": {
29-
"cpu": 8,
30-
"memory": 128,
31-
"disk": 200
29+
"cpu": 32,
30+
"memory": 512,
31+
"disk": 300
3232
}
3333
}
3434
]

0 commit comments

Comments
 (0)