mirror of
https://github.com/x1xhlol/system-prompts-and-models-of-ai-tools.git
synced 2026-08-16 21:24:09 +00:00
136 lines
4.9 KiB
Python
136 lines
4.9 KiB
Python
import pandas as pd
|
|
import json
|
|
import os
|
|
|
|
|
|
from s3Ops import read_file_from_s3
|
|
|
|
from backendAPIs import (
|
|
update_onboarding_status,
|
|
add_bank_transaction_records
|
|
)
|
|
|
|
def xlsx_to_df(xlsx_file, sheet_name):
|
|
df = pd.read_excel(xlsx_file, sheet_name = sheet_name)
|
|
df.columns = df.iloc[2]
|
|
df = df.drop(df.index[:3])
|
|
df = df.reset_index(drop=True)
|
|
|
|
return df
|
|
|
|
|
|
# TODO: add the remaining asset type mapping
|
|
def get_security_type(asset_type):
|
|
asset_to_security_type = {
|
|
"Common stock":"COMMON",
|
|
"Preferred stock":"PREFERRED",
|
|
"Warrants":"WARRANTS",
|
|
"Convertible promissory note/SAFEs": "POST MONEY SAFE"
|
|
}
|
|
|
|
for asset, security_type in asset_to_security_type.items():
|
|
if asset_type.lower() in asset.lower(): # Case-insensitive match
|
|
return security_type
|
|
|
|
return ""
|
|
|
|
|
|
def process_bank_transaction_records(df):
|
|
"""
|
|
Process and insert users from an Excel file into MongoDB.
|
|
|
|
Args:
|
|
file_path (str): Path to the Excel file.
|
|
"""
|
|
|
|
entity_id = os.getenv('ENTITY_ID')
|
|
fund_id = os.getenv('FUND_ID')
|
|
|
|
# Filter out rows with invalid Journal IDs
|
|
# df = df[~df['Journal ID'].isin(['Journal ID'])]
|
|
print(df.head())
|
|
|
|
transactions = []
|
|
|
|
# Iterate through the DataFrame and prepare partner records
|
|
for index, row in df.iterrows():
|
|
|
|
tdate = row['Date']
|
|
transaction_record = {
|
|
"fundId": fund_id,
|
|
"date": tdate.strftime('%m/%d/%Y'),
|
|
"memo": row['Name'] if pd.notna(row['Name']) else row['Memo'],
|
|
"credit": row['Credit'] if pd.notna(row['Credit']) else 0.0,
|
|
"debit": row['Debit'] if pd.notna(row['Debit']) else 0.0,
|
|
"balance": row['Balance'] if pd.notna(row['Balance']) else 0.0
|
|
}
|
|
|
|
response = add_bank_transaction_records(transaction_record)
|
|
print(f"Adding transaction {index}:\n {transaction_record}\n\n")
|
|
if 'error' in response:
|
|
print(f"Failed to fetch onboarding status: Error: {response['error']}")
|
|
print(f"Status Code: {response['status_code']}")
|
|
break # Process next company investment record...
|
|
transactions.append(transaction_record)
|
|
|
|
# Test with smaller set of records
|
|
# if index == 1:
|
|
# break
|
|
|
|
return transactions
|
|
|
|
|
|
def process_bank_transactions(file_path):
|
|
# Process bank transactions
|
|
step_number = 5
|
|
step_number -= 1
|
|
success_message = ""
|
|
error_message = ""
|
|
status = ""
|
|
|
|
bucket_name = os.getenv('S3_UPLOAD_BUCKET_NAME')
|
|
print(f"Processing file: {file_path}")
|
|
response = update_onboarding_status(step_number, "IN-PROGRESS", "", "")
|
|
if 'error' in response:
|
|
print(f"Failed to fetch onboarding status: Error: {response['error']}")
|
|
print(f"Status Code: {response['status_code']}")
|
|
return False
|
|
journal_excel_file = read_file_from_s3(bucket_name, file_path)
|
|
sheet_name = 'Bank Transactions Report'
|
|
transaction_df = xlsx_to_df(journal_excel_file, sheet_name)
|
|
print(transaction_df.head())
|
|
transactions = process_bank_transaction_records(transaction_df)
|
|
if transactions:
|
|
item_count = len(transactions)
|
|
success_message = f"Onboarded {item_count} bank transactions."
|
|
status = "COMPLETE"
|
|
else:
|
|
error_message = "No transactions were onboaerded."
|
|
status = "FAILED"
|
|
|
|
response = update_onboarding_status(step_number, status, error_message, success_message)
|
|
if 'error' in response:
|
|
print(f"Failed to fetch onboarding status: Error: {response['error']}")
|
|
print(f"Status Code: {response['status_code']}")
|
|
return False
|
|
|
|
# print(f"Journals list:\n {transactions}")
|
|
|
|
return True
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
from dotenv import load_dotenv
|
|
load_dotenv()
|
|
|
|
onboardingId = "66ea163564e2f97a059160ef"
|
|
os.environ["ONBOARDING_ID"] = onboardingId
|
|
os.environ["FUND_ID"] = "66c5e6d89ecbf552a05b84fc"
|
|
|
|
from initOnboarding import initialize_onboarding
|
|
initialize_onboarding()
|
|
|
|
found_files = {'lpa': '66c5e5c99ecbf552a05b84f9/20240917T235220Z/0-Please_DocuSign_CerraCap_II_LP_Limited_Partn.pdf', 'partner': '66c5e5c99ecbf552a05b84f9/20240917T235220Z/0-1-cerracap-ii-lp_2024-07_09_short_partner.xlsx', 'financials': '66c5e5c99ecbf552a05b84f9/20240917T235220Z/2-3-cerracap-ii-lp_2024-08-26_financials.xlsx', 'bankTransactions': '66c5e5c99ecbf552a05b84f9/20240917T235220Z/4-CerraCap_II__LP_bank_transactions_2016-01-01-2024-07-03.xlsx', 'journals': '66c5e5c99ecbf552a05b84f9/20240917T235220Z/5-cerracap-ii-lp_2024-07-09_journals-export.xlsx', 'fund_performance': '66c5e5c99ecbf552a05b84f9/20240917T235220Z/6-cerracap-ii-lp_2024-07-09_fund-performance-report.xlsx'}
|
|
financials_excel_file_path = found_files["bankTransactions"]
|
|
process_bank_transactions(financials_excel_file_path) |