Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.79 KB | None | 0 0
  1. def plot_aggregated(tput_paths, delta_time=5):
  2.     raw_tputs = []
  3.     stopped_at = []
  4.     for path in tput_paths:
  5.         tput = []
  6.         partition_id = path.split('-')[-1]
  7.         move_path = '/'.join(path.split('/')
  8.                              [:-1]) + '/movedTo-moved2-partition-' + partition_id
  9.         stop_path = '/'.join(path.split('/')[:-1]) + \
  10.             '/stopped-tx-stream-partition-' + partition_id
  11.         stopped_at.append(get_stopped_time_partition(stop_path))
  12.         with open(path, 'r') as f, open(move_path, 'r') as mp:
  13.             # f.readline()
  14.             for line in f:
  15.                 movedTo = 0
  16.                 moved2 = 0
  17.                 timestamp = 0
  18.                 try:
  19.                     movedTo, moved2, timestamp = map(
  20.                         lambda i: int(i), mp.readline()[:-1].split())
  21.                 except:
  22.                     pass
  23.                 (total_txs, timestamp, validator) = line.split()
  24.                 total_txs = int(total_txs)
  25.                 timestamp = int(timestamp)
  26.                 total_txs = total_txs - movedTo - moved2
  27.                 assert(total_txs > 0)
  28.                 tput.append((timestamp, total_txs))
  29.  
  30.         raw_tputs.append(tput)
  31.  
  32.     # remove non-overlapping ends
  33.     max_min = 0
  34.     min_max = float('inf')
  35.     for tput in raw_tputs:
  36.         max_min = max(max_min, tput[0][0])
  37.         min_max = min(min_max, tput[-1][0])
  38.     for tput in raw_tputs:
  39.         while tput[0][0] < max_min:
  40.             tput.remove(tput[0])
  41.         while tput[-1][0] > min_max:
  42.             tput.pop()
  43.  
  44.     aggregated_tputs = []
  45.  
  46.     delta = delta_time*1e9
  47.     start_time = max_min
  48.  
  49.     data_points_i = [0 for i in range(len(raw_tputs))]
  50.     running = True
  51.     # Aggregate
  52.     first = True
  53.     all_txs_sum = 0
  54.     while True:
  55.         aggregated_data = []
  56.         for tput_i, tput in enumerate(raw_tputs):
  57.             prev_idx = data_points_i[tput_i]
  58.             while True:
  59.                 idx = data_points_i[tput_i]
  60.                 if idx >= len(tput):
  61.                     running = False
  62.                     break
  63.                 data_points_i[tput_i] += 1
  64.                 if tput[idx][0] > start_time + delta:
  65.                     break
  66.  
  67.             if running == False:
  68.                 break
  69.  
  70.             # previous_tput[tput_i] = tput[prev_idx][1] + tput[idx][1] - previous_tput[tput_i]
  71.             # print(tput_i, previous_tput[tput_i])
  72.             time_passed = (tput[idx][0] - tput[prev_idx][0])/1e9
  73.             if time_passed == 0:
  74.                 running = False
  75.                 break
  76.             all_txs_sum += tput[idx][1] - tput[prev_idx][1]
  77.             if first == True:
  78.                 first_time = tput[idx][0]
  79.                 first = False
  80.             last_time = tput[idx][0]
  81.             aggregated_data.append(
  82.                 ((tput[idx][0] + tput[prev_idx][0])/2., (tput[idx][1] - tput[prev_idx][1])/time_passed))
  83.         if running == False:
  84.             break
  85.         avg_time = np.average(list(map(lambda i: i[0], aggregated_data)))
  86.         sum_txs = sum(list(map(lambda i: i[1], aggregated_data)))
  87.         aggregated_tputs.append((avg_time, sum_txs))
  88.         start_time += delta
  89.  
  90.     print(last_time - first_time, all_txs_sum)
  91.  
  92.     # plot
  93.     fig, ax = plt.subplots()
  94.     avg_times = list(map(lambda i: (i[0] - max_min)/1e9, aggregated_tputs))
  95.  
  96.     ax.plot(avg_times, list(map(lambda i: i[1], aggregated_tputs)))
  97.     ax.set(xlabel='time (s)', ylabel='tx/s')
  98.     ylim1, ylim2 = plt.ylim()
  99.     plt.ylim((0, ylim2))
  100.     # plt.show()
  101.  
  102.     # Plot stopped lines
  103.     labels = {'label': 'Limit reached'}
  104.     for stop in stopped_at:
  105.         if stop != None:
  106.             plt.axvline(x=(stop - max_min)/1e9, color='r',
  107.                         linestyle='--', **labels)
  108.         labels = {}
  109.  
  110.     return fig, ax
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement