데이터베이스 이름 수정

This commit is contained in:
2025-07-08 14:36:09 +09:00
parent a2b6c58560
commit 422a16aa0c
3 changed files with 23 additions and 15 deletions

View File

@ -129,7 +129,7 @@ def main():
yesterday = (datetime.now() - timedelta(days=1)).date() yesterday = (datetime.now() - timedelta(days=1)).date()
engine = db.engine engine = db.engine
table = db_schema.fg_manager_static_air table = db_schema.air
with engine.connect() as conn: with engine.connect() as conn:
for station_name in station_list: for station_name in station_list:

View File

@ -156,10 +156,18 @@ def determine_date_range(table, config_start, config_end, force_update, engine):
yesterday = datetime.now().date() - timedelta(days=1) yesterday = datetime.now().date() - timedelta(days=1)
actual_end = min(yesterday, config_end) actual_end = min(yesterday, config_end)
latest_db_date = get_latest_date_from_db(engine, table) latest_db_date = get_latest_date_from_db(engine, table)
if latest_db_date and not force_update:
actual_start = latest_db_date + timedelta(days=1) if force_update:
else:
actual_start = config_start actual_start = config_start
else:
if latest_db_date is not None:
actual_start = latest_db_date + timedelta(days=1)
else:
actual_start = config_start
if actual_start > actual_end:
return None, None
return actual_start, actual_end return actual_start, actual_end
# ------------------------ # ------------------------
@ -170,8 +178,8 @@ def process_dimension_metric(engine, client, property_id, config, table, dims, m
config_end = datetime.strptime(config.get("endDt", datetime.now().strftime("%Y%m%d")), "%Y%m%d").date() config_end = datetime.strptime(config.get("endDt", datetime.now().strftime("%Y%m%d")), "%Y%m%d").date()
actual_start, actual_end = determine_date_range(table, config_start, config_end, force_update, engine) actual_start, actual_end = determine_date_range(table, config_start, config_end, force_update, engine)
if actual_start > actual_end: if actual_start is None or actual_end is None:
print(f"[INFO] 이미 모든 데이터가 수집되어 있습니다: {actual_start} > {actual_end}") print(f"[INFO] 이미 모든 데이터가 수집되어 있습니다 또는 수집 범위가 없습니다.")
return return
for start_dt, end_dt in date_range_chunks(actual_start, actual_end, max_rows): for start_dt, end_dt in date_range_chunks(actual_start, actual_end, max_rows):
@ -209,15 +217,15 @@ def main():
update_config_file_with_max_rows(max_rows) update_config_file_with_max_rows(max_rows)
tasks = [ tasks = [
(db_schema.fg_manager_static_ga4_by_date, ["date"], ["activeUsers", "screenPageViews", "sessions"]), (db_schema.ga4_by_date, ["date"], ["activeUsers", "screenPageViews", "sessions"]),
(db_schema.fg_manager_static_ga4_by_source, ["date", "sessionSource"], ["sessions"]), (db_schema.ga4_by_source, ["date", "sessionSource"], ["sessions"]),
(db_schema.fg_manager_static_ga4_by_medium, ["date", "sessionMedium"], ["sessions"]), (db_schema.ga4_by_medium, ["date", "sessionMedium"], ["sessions"]),
(db_schema.fg_manager_static_ga4_by_device, ["date", "deviceCategory"], ["activeUsers"]), (db_schema.ga4_by_device, ["date", "deviceCategory"], ["activeUsers"]),
(db_schema.fg_manager_static_ga4_by_country, ["date", "country"], ["activeUsers"]), (db_schema.ga4_by_country, ["date", "country"], ["activeUsers"]),
(db_schema.fg_manager_static_ga4_by_city, ["date", "city"], ["activeUsers"]) (db_schema.ga4_by_city, ["date", "city"], ["activeUsers"])
] ]
with ThreadPoolExecutor(max_workers=4) as executor: with ThreadPoolExecutor(max_workers=max_workers) as executor:
futures = [ futures = [
executor.submit(process_dimension_metric, engine, client, property_id, ga4_cfg, executor.submit(process_dimension_metric, engine, client, property_id, ga4_cfg,
table, dims, mets, max_rows, debug, force_update) table, dims, mets, max_rows, debug, force_update)
@ -229,4 +237,4 @@ def main():
print("[INFO] GA4 데이터 수집 및 저장 완료") print("[INFO] GA4 데이터 수집 및 저장 완료")
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -132,7 +132,7 @@ def main():
debug = config.get("debug", False) debug = config.get("debug", False)
force_update = config.get("force_update", False) force_update = config.get("force_update", False)
table = db_schema.fg_manager_static_weather table = db_schema.weather
engine = db.engine engine = db.engine
now = datetime.now() now = datetime.now()