Skip to content

Commit

Permalink
move validator in parser and store unix timestamps instead of localiz…
Browse files Browse the repository at this point in the history
…ed times
  • Loading branch information
stedfn committed Oct 15, 2024
1 parent 61c8fe9 commit c94920e
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions debug_scripts/estimate_epoch_start_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,48 +82,38 @@ def get_exponential_weighted_epoch_lengths(url,
return epoch_lengths, exponential_weighted_average_epoch_length


# Function to check if timezone is valid
def is_valid_timezone(timezone_str):
def valid_timezone(timezone_str):
try:
pytz.timezone(timezone_str)
return True
return pytz.timezone(timezone_str)
except pytz.UnknownTimeZoneError:
return False
raise argparse.ArgumentTypeError(f"Invalid timezone '{timezone_str}'")


# Function to approximate future epoch start dates
def predict_future_epochs(starting_epoch_timestamp, avg_epoch_length,
num_future_epochs, timezone_str):
num_future_epochs, target_timezone):
future_epochs = []
current_timestamp = ns_to_seconds(
starting_epoch_timestamp) # Convert from nanoseconds to seconds

# Set up the timezone
target_timezone = pytz.timezone(timezone_str)

for i in range(1, num_future_epochs + 1):
# Add the average epoch length for each future epoch
future_timestamp = current_timestamp + (i * avg_epoch_length)
future_epochs.append(future_timestamp)

# Convert timestamp to datetime in target timezone
future_datetime = datetime.fromtimestamp(future_timestamp,
target_timezone)

# Format date
future_date = future_datetime.strftime('%Y-%m-%d %H:%M:%S %Z%z %A')
future_epochs.append(future_date)

print(f"Predicted start of epoch {i}: {future_date}")

return future_epochs


# Main function to run the process
def main(args):
if not is_valid_timezone(args.timezone):
print(f"Error: Invalid timezone '{args.timezone}'")
return

latest_block = get_block(args.url, None)
next_epoch_id = latest_block['next_epoch_id']
current_epoch_first_block = get_block(args.url, next_epoch_id)
Expand Down Expand Up @@ -179,6 +169,7 @@ def __call__(self, parser, namespace, values, option_string=None):
help="Number of future epochs to predict.")
parser.add_argument(
"--timezone",
type=valid_timezone,
default="UTC",
help="Time zone to display times in (e.g., 'America/New_York').")

Expand Down

0 comments on commit c94920e

Please sign in to comment.