Skip to content

Commit

Permalink
feat: add calculate_aggregat_amount function
Browse files Browse the repository at this point in the history
refactor: improve function names
refactor: improve variable names
  • Loading branch information
andreivladbrg committed Sep 29, 2023
1 parent 691a1ba commit a7c3792
Showing 1 changed file with 62 additions and 80 deletions.
142 changes: 62 additions & 80 deletions generate-schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,154 +2,136 @@
from datetime import datetime
import time


# Load the CSV file
df = pd.read_csv('Exactly_Schedule.csv')
schedule_data = pd.read_csv('Exactly_Schedule.csv')


def get_dates():
return df.iloc[5:50, 1].tolist()
def extract_dates():
return schedule_data.iloc[5:50, 1].tolist()


def get_recipients_addresses():
return df.iloc[0, 2:19].tolist()
def extract_recipient_addresses():
return schedule_data.iloc[0, 2:19].tolist()


def get_cliff_dates():
return df.iloc[1, 2:19].tolist()
def extract_cliff_dates():
return schedule_data.iloc[1, 2:19].tolist()


def get_cliff_timestamps():
dates = get_cliff_dates()
# Convert dates to UNIX timestamps
return [int(datetime.strptime(date, "%m/%d/%Y").timestamp()) for date in dates]
def convert_cliff_dates_to_timestamps():
cliff_dates = extract_cliff_dates()
return [int(datetime.strptime(date, "%m/%d/%Y").timestamp()) for date in cliff_dates]


def get_total_amounts():
amounts = df.iloc[3, 2:19].map(lambda x: int(x.replace(
',', '')) if isinstance(x, str) and x.replace(',', '').strip() != '' else None)
def extract_total_amounts():
amounts = schedule_data.iloc[3, 2:19].map(lambda x: int(x.replace(',', ''))
if isinstance(x, str) and x.replace(',', '').strip() != ''
else None)
return amounts.tolist()


def get_unlock_amounts():
amounts = df.iloc[5:50, 2:19].map(lambda x: int(x.replace(',', '')) if isinstance(
x, str) and x.replace(',', '').strip() != '' else None)
def extract_unlock_amounts():
amounts = schedule_data.iloc[5:50, 2:19].map(lambda x: int(x.replace(',', ''))
if isinstance(x, str) and x.replace(',', '').strip() != ''
else None)
return amounts.values.tolist()


def get_segments_milestones():
dates = get_dates()
# Convert dates to UNIX timestamps
return [int(time.mktime(datetime.strptime(date, "%B %d, %Y").timetuple())) for date in dates]
def convert_dates_to_milestones():
milestone_dates = extract_dates()
return [int(time.mktime(datetime.strptime(date, "%B %d, %Y").timetuple())) for date in milestone_dates]


def calculate_aggregate_amount():
total_amounts = extract_total_amounts()
return sum(total_amounts)

# Returns the milestones and the amount for a given index from 0 to 16
def get_segments_for(index):
dates = get_dates()
milestones = get_segments_milestones()
unlock_amounts = get_unlock_amounts()
row_unlock_amounts = [row[index] for row in unlock_amounts if row]

segments = []
def get_user_segments(index):
dates = extract_dates()
milestones = convert_dates_to_milestones()
unlock_amounts = extract_unlock_amounts()
user_unlock_amounts = [row[index] for row in unlock_amounts if row]

user_segments = []
for i in range(len(milestones)):
if row_unlock_amounts[i] > 0:
segments.append({
if user_unlock_amounts[i] > 0:
user_segments.append({
'milestone': milestones[i],
'amount': row_unlock_amounts[i],
'amount': user_unlock_amounts[i],
'date': dates[i]
})

segments = convert_to_segment_amounts(segments)

return segments
updated_segments = convert_to_segment_amounts(user_segments)
return updated_segments


def convert_to_segment_amounts(segments):
if len(segments) < 2:
return segments

# Create a new list of segment dictionaries with updated amounts
updated_segments = [segments[0]] # The first segment remains the same
updated_segments = [segments[0]]

for i in range(1, len(segments)):
# Calculate the difference in amounts between adjacent segments
diff_amount = segments[i]['amount'] - segments[i - 1]['amount']

# Create a new segment dictionary with the updated amount
updated_segment = {
'milestone': segments[i]['milestone'],
'amount': diff_amount,
'date': segments[i]['date']
}

# Append the updated segment to the updated_segments list
updated_segments.append(updated_segment)

return updated_segments


def print_recipients_addresses():
print(get_recipients_addresses())


def print_total_amounts():
print(get_total_amounts())


def print_unlock_amounts():
print(get_unlock_amounts())


def generate_segments_functions():
def print_segment_functions():
for i in range(16):
user_number = i + 1
user_id = i + 1
print(
f"function getSegmentsForUser{user_number}() public pure returns (LockupDynamic.Segment[] memory) {{")
f"function getSegmentsForUser{user_id}() public pure returns (LockupDynamic.Segment[] memory) {{")
print(f" LockupDynamic.Segment[] memory segments = new LockupDynamic.Segment[](36);")
generate_segments_for(i)
print("return segments; }")
print_segments(i)
print(" return segments; \n}")


def generate_segments_for(index):
segments = get_segments_for(index)
def print_segments(index):
segments = get_user_segments(index)
for i, segment in enumerate(segments):
amount = formatNumber(segment['amount'])
formatted_amount = format_number(segment['amount'])
milestone = segment['milestone']
date = segment['date']
print(
f"segments[{i}] = getSegment({{ amount: {amount}e18, milestone: {milestone} }}); // {date} ")
f" segments[{i}] = getSegment({{ amount: {formatted_amount}e18, milestone: {milestone} }}); // {date}")


def generate_users_functions():
recipients_addresses = get_recipients_addresses()
start_times = get_cliff_timestamps()
total_amounts = get_total_amounts()
def print_user_functions():
addresses = extract_recipient_addresses()
start_times = convert_cliff_dates_to_timestamps()
total_amounts = extract_total_amounts()

for i in range(16):
user_number = i + 1
recipient_address = recipients_addresses[i]
user_id = i + 1
address = addresses[i]
start_time = start_times[i]
total_amount = formatNumber(total_amounts[i])
print(f"""function getParamsForUser{user_number}() public view returns (LockupDynamic.CreateWithMilestones memory) {{
total_amount = format_number(total_amounts[i])
print(f"""function getParamsForUser{user_id}() public view returns (LockupDynamic.CreateWithMilestones memory) {{
return LockupDynamic.CreateWithMilestones({{
asset: EXA,
broker: broker,
cancelable: true,
recipient: {recipient_address},
segments: getSegmentsForUser{user_number}(),
recipient: {address},
segments: getSegmentsForUser{user_id}(),
sender: EXACTLY_PROTOCOL_OWNER,
startTime: {start_time},
totalAmount: {total_amount}e18
}});
}}""")


def formatNumber(num):
if num % 1 == 0:
return int(num)
else:
return num
def format_number(number):
return int(number) if number % 1 == 0 else float(number)


generate_users_functions()
generate_segments_functions()
# Print the functions
print_user_functions()
print_segment_functions()

0 comments on commit a7c3792

Please sign in to comment.