mirror of
https://github.com/x1xhlol/system-prompts-and-models-of-ai-tools.git
synced 2026-08-16 21:24:09 +00:00
133 lines
4.3 KiB
Python
133 lines
4.3 KiB
Python
import io
|
|
import os
|
|
import json
|
|
import base64
|
|
import time
|
|
from s3Ops import read_file_from_s3
|
|
import pandas as pd
|
|
import re
|
|
from backendAPIs import (
|
|
update_fund,
|
|
update_onboarding_status
|
|
)
|
|
|
|
def clean_currency(x):
|
|
try:
|
|
if isinstance(x, str):
|
|
return float(re.sub(r'[\$,]', '', x))
|
|
return float(x)
|
|
except:
|
|
return 0 # or np.nan if you prefer
|
|
|
|
|
|
def get_partner_summary(df):
|
|
# Calculate values
|
|
total_commitment = df['Commitment'].apply(clean_currency).sum()
|
|
earliest_date = pd.to_datetime(df['Issue date']).min()
|
|
general_partner = df[df['Class'] == 'General Partner']['Partner'].iloc[0]
|
|
|
|
# Create dictionary with results
|
|
summary_dict = {
|
|
'total_commitments': total_commitment,
|
|
'earliest_issue_date': earliest_date.strftime('%m/%d/%Y'),
|
|
'general_partner': general_partner
|
|
}
|
|
|
|
return summary_dict
|
|
|
|
|
|
def get_partners_from_excel(xlsx_file):
|
|
"""
|
|
Read Excel file containing pa information.
|
|
Remove headers and return clean df
|
|
|
|
Args:
|
|
file_path (str): Path to the Excel file.
|
|
sheet_name (str): Excel sheet name with partner list
|
|
Returns:
|
|
pd.DataFrame: DataFrame containing partner information.
|
|
"""
|
|
sheet_name = 'Partners'
|
|
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)
|
|
|
|
fields_dict = get_partner_summary(df)
|
|
|
|
return fields_dict
|
|
|
|
def onboardFunds(lpa_file_path):
|
|
|
|
|
|
# input_bucket = os.getenv('S3_UPLOAD_BUCKET_NAME')
|
|
step_number = 2
|
|
step_number -= 1
|
|
success_message = ""
|
|
error_message = ""
|
|
status = "IN-PROGRESS"
|
|
|
|
print("IN-PROGREE")
|
|
|
|
response = update_onboarding_status(step_number, status, error_message, success_message)
|
|
|
|
bucket_name = os.getenv('S3_UPLOAD_BUCKET_NAME')
|
|
print(f"Processing file: {lpa_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
|
|
partner_excel_file = read_file_from_s3(bucket_name,lpa_file_path)
|
|
partners_df = get_partners_from_excel(partner_excel_file)
|
|
print(partners_df)
|
|
|
|
fund_data = {
|
|
"fundSize": partners_df["total_commitments"],
|
|
"dateFormed": partners_df["earliest_issue_date"],
|
|
"fundDuration": "10",
|
|
"gpName": partners_df["general_partner"],
|
|
"investmentperiodmanagementFee": "2%",
|
|
"mgmtCoName": "Test Mgt Co",
|
|
"postInvestmentPeriodmanagementFee": "4%"
|
|
}
|
|
|
|
response = update_fund(fund_data)
|
|
print(f"Response: \n {response}")
|
|
fund_id = response["data"]["data"]["_id"]
|
|
print(f"Setting fund id in the environment {fund_id}")
|
|
os.environ["FUND_ID"] = fund_id
|
|
|
|
|
|
if fund_id:
|
|
success_message = f"Onboarded fund {fund_id} journal records."
|
|
status = "COMPLETE"
|
|
else:
|
|
error_message = "No journals 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
|
|
|
|
return fund_id
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
from dotenv import load_dotenv
|
|
load_dotenv()
|
|
|
|
onboardingId = "66ea163564e2f97a059160ef"
|
|
os.environ["ONBOARDING_ID"] = onboardingId
|
|
|
|
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'}
|
|
lpa_file_path = found_files["lpa"]
|
|
onboardFunds(lpa_file_path)
|