import csv import datetime import uuid from pathlib import Path def cts_logger(scheduler, log_filename, log_data, response) -> None: with scheduler.lock: logger(log_filename, log_data, response) def logger(log_filename, log_data, response): with open(log_filename, mode='a', newline='') as log_file: log_writer = csv.writer(log_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) # Get the current date and time current_datetime = datetime.datetime.now() date_str = current_datetime.strftime("%Y-%m-%d") time_str = current_datetime.strftime("%H:%M:%S") log_data.append(date_str) log_data.append(time_str) log_data.append(response) # Write the log data to the CSV file log_writer.writerow(log_data) def cts_log_file_create(folder_name): file_path = Path(folder_name + "/") / f"CTS_user_log{uuid.uuid4()}.csv" with open(file_path, mode='a', newline='') as log_file: log_writer = csv.writer(log_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) headers = [ "user_query", "ref_question", "query_score", "code_executed", "ref_question_2", "query_score_2", "ref_question_3", "query_score_3", "similarity_metric", "model_used_for_embeddings", "lower_threshold", "upper_threshold", "date", "time", "response", ] # Write headers to the CSV file log_writer.writerow(headers) return file_path