-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateCsv.py
More file actions
25 lines (16 loc) · 1.09 KB
/
Copy pathcreateCsv.py
File metadata and controls
25 lines (16 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import csv
def create(rounds, offset, sigma_current, shots_per_round, points, player_index=int):
number = str(player_index)
with open('distribution' + number + '.csv', 'w', newline="") as file:
writer = csv.writer(file, delimiter=';')
writer.writerow(["Round's number", "Points", "Modified points", "Average amount of points per throw", "Sigma", "Coefficient"])
shots_taken = 0
for i in range(int(rounds)):
sum_of_points = sum_elements_range(points, shots_taken, shots_taken + shots_per_round - 1)
sum_of_points_cond = sum_elements_with_bool(points, shots_taken, shots_taken + shots_per_round - 1)
shots_taken += shots_per_round
writer.writerow([i + 1, sum_of_points, sum_of_points_cond, "%.2f" % (sum_of_points / shots_per_round), "%.2f" % sigma_current, offset])
def sum_elements_range(arr, start_idx, end_idx):
return sum([t[0] for t in arr[start_idx:end_idx+1]])
def sum_elements_with_bool(arr, start_idx, end_idx):
return sum(val for val, bool_val in arr[start_idx:end_idx+1] if bool_val)