mirror of
https://github.com/x1xhlol/system-prompts-and-models-of-ai-tools.git
synced 2026-08-16 21:24:09 +00:00
125 lines
4.6 KiB
Python
125 lines
4.6 KiB
Python
import pandas as pd
|
|
import json
|
|
import os
|
|
|
|
|
|
from s3Ops import read_file_from_s3
|
|
|
|
from backendAPIs import (
|
|
update_onboarding_status,
|
|
add_performance_record
|
|
)
|
|
|
|
def xlsx_to_df(xlsx_file, sheet_name):
|
|
df = pd.read_excel(xlsx_file, sheet_name = sheet_name, header=2,skiprows=2)
|
|
return df
|
|
|
|
|
|
def process_performance_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')
|
|
role_id = os.getenv('ROLE_ID')
|
|
|
|
performance_records = []
|
|
|
|
# Iterate through the DataFrame and prepare partner records
|
|
for index, row in df.iterrows():
|
|
|
|
print(row.to_dict())
|
|
|
|
if row['Type'].strip().lower() == "contribution":
|
|
continue
|
|
|
|
tdate = row['Date']
|
|
performance_record = {
|
|
"fundId": fund_id,
|
|
"entityId": entity_id,
|
|
"roleId": role_id,
|
|
"receivedDate": tdate.strftime('%m/%d/%Y'),
|
|
"amount": row['Value'] if row['Value'] >= 0 else row['Value']*-1,
|
|
"gainLoss": "GAIN" if row['Value'] >= 0 else "LOSS",
|
|
"type": row['Type'],
|
|
"partnerExactName": row["Partner"]
|
|
}
|
|
|
|
response = add_performance_record(performance_record)
|
|
print(f"Adding joural ledger {index}\n {performance_record}\n\n")
|
|
if 'error' in response:
|
|
print(response)
|
|
print(f"Failed to fetch onboarding status: Error: {response['error']}")
|
|
print(f"Status Code: {response['status_code']}")
|
|
# break # Process next company investment record...
|
|
continue
|
|
|
|
|
|
performance_records.append(performance_record)
|
|
print(f"Performance record: \n{performance_record}")
|
|
|
|
# Test with smaller set of records
|
|
# if index == 1:
|
|
# break
|
|
|
|
return performance_records
|
|
|
|
|
|
def process_fund_performance(file_path):
|
|
# Process partner data
|
|
step_number = 7
|
|
step_number -= 1
|
|
success_message = ""
|
|
error_message = ""
|
|
status = "IN-PROGRESS"
|
|
|
|
bucket_name = os.getenv('S3_UPLOAD_BUCKET_NAME')
|
|
print(f"Processing file: {file_path}")
|
|
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
|
|
performance_excel_file = read_file_from_s3(bucket_name, file_path)
|
|
sheet_name = 'Partner Capital Activity Detail'
|
|
performance_df = xlsx_to_df(performance_excel_file, sheet_name)
|
|
print(performance_df)
|
|
perf_records = process_performance_records(performance_df)
|
|
if perf_records:
|
|
item_count = len(perf_records)
|
|
success_message = f"Onboarded {item_count} fund performance records."
|
|
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 {perf_records}")
|
|
|
|
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["fund_performance"]
|
|
process_fund_performance(financials_excel_file_path) |