Last active
October 5, 2020 12:48
-
-
Save deckb/e47768f350acaaba3a2c0db84966584a to your computer and use it in GitHub Desktop.
`rentbw` scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import csv | |
import datetime as dt | |
import os | |
import random | |
# import pytz | |
# example | |
# python3 ./rentbw-modeling-input.py --out-file out.csv --min-pct 0.001 --max-pct 0.01 | |
# run `rentbw-modeling` with out.csv | |
# ./run_and_plot.sh model_config.json /path/to/out.csv csv_output.csv | |
HEADER = ["datetime","function","payer","receiver","days","net_frac","cpu_frac","max_payment","queue_max"] | |
# 2021-01-01T01:00:00.000 | |
# DT_FORMAT = "%Y-%m/%DT%H:%M:%S.%s" | |
BW_FRAC = 1000000000000000 # 1.0 = 10^15 | |
CONFIG_ACT = "configrentbw" | |
EXEC_ACT = "rentbwexec" | |
RENT_ACT = "rentbw" | |
USER = "aaaaaaaaaaaa" | |
RENT_DAYS = 30 | |
FEE_AMOUNT = "50000000.0001" | |
parser = argparse.ArgumentParser(description='Create eosio.contract tester csv input file') | |
parser.add_argument('--out-file', metavar='S', type=str, required=True, help='output file') | |
# parser.add_argument('--config-file', metavar='S', type=str, required=True, help='config file') | |
parser.add_argument('--min-pct', metavar='F', type=float, required=True, help='min pct') | |
parser.add_argument('--max-pct', metavar='F', type=float, required=True,help='max pct') | |
parser.add_argument('--start-time', metavar='N', type=int, default=1609545600, help='starting time in epoch seconds') | |
parser.add_argument('--days', metavar='N', type=int, default=100, help='number of days to iterate') | |
# parser.add_argument('--step-time', metavar='N', type=int, default=24, help='step time in hours') | |
parser.add_argument('--step-count', metavar='N', type=int, default=1, help='number of times to call rentbw in a step') | |
parser.add_argument('--step-count-time', metavar='N', type=int, default=60, help='how much time between step-count in minutes.') | |
parser.add_argument('--step-exec', metavar='N', type=int, default=1, help='how many times to execute `rentbwexec` per day') | |
args = parser.parse_args() | |
def add_z(ts): | |
return ts.replace('+00:00', 'Z') | |
with open(args.out_file, 'w', newline='') as csvout: | |
writer = csv.writer(csvout, delimiter=',', | |
quotechar='|', quoting=csv.QUOTE_MINIMAL) | |
writer.writerow(HEADER) | |
# exec_time = dt.datetime.fromtimestamp(args.start_time, tz=pytz.utc) | |
exec_time = dt.datetime.fromtimestamp(args.start_time) | |
print(f'configuring at: {exec_time} local') | |
# config_time = dt.datetime.fromtimestamp(args.start_time, tz=pytz.utc) | |
config_time = dt.datetime.fromtimestamp(args.start_time) | |
writer.writerow([(config_time.isoformat()), CONFIG_ACT, args.config_file, 0, 0, 0, 0, 0, 0]) | |
for cnt in range(args.days): | |
# rent_time = dt.datetime.fromtimestamp(args.start_time, tz=pytz.utc) + dt.timedelta(days=cnt) | |
rent_time = dt.datetime.fromtimestamp(args.start_time) + dt.timedelta(days=cnt) | |
exec_cnt = 0 | |
for step_cnt in range(args.step_count): | |
if exec_cnt < args.step_exec: | |
exec_cnt += 1 | |
writer.writerow([(rent_time.isoformat()), EXEC_ACT, USER, USER, 0, 0, 0, FEE_AMOUNT, args.step_count]) | |
rent_time += dt.timedelta(minutes=args.step_count_time) | |
pct = int(random.uniform(args.min_pct, args.max_pct) * BW_FRAC) | |
print(f'time: {rent_time} pct: {pct}') | |
writer.writerow([(rent_time.isoformat()), RENT_ACT, USER, USER, RENT_DAYS, pct, pct, FEE_AMOUNT, 0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment