76 lines
1.9 KiB
Python
76 lines
1.9 KiB
Python
'''--------------------------------------------------
|
|
Script randomly generates coordinates from (-10, -10)
|
|
to (10, 10), with step 0.5.
|
|
Then applies points from 0 to 10 to the coordinates.
|
|
|
|
Points value is determined by circle area.
|
|
|
|
Export the dataset to "data/synthetic_shots.csv"
|
|
|
|
---------------------------------------------------'''
|
|
|
|
import sys
|
|
import pandas as pd
|
|
import numpy as np
|
|
import csv
|
|
|
|
args = sys.argv[1:]
|
|
|
|
if not args:
|
|
print("Usage: python3 generate_synthetic_shots.py <number of generated shots>")
|
|
sys.exit(1)
|
|
|
|
n = int(args[0])
|
|
|
|
# Area circle
|
|
A10 = 1.5 ** 2 * np.pi
|
|
A9 = 2.5 ** 2 * np.pi
|
|
A8 = 3.5 ** 2 * np.pi
|
|
A7 = 4.5 ** 2 * np.pi
|
|
A6 = 5.5 ** 2 * np.pi
|
|
A5 = 6.5 ** 2 * np.pi
|
|
A4 = 7.5 ** 2 * np.pi
|
|
A3 = 8.5 ** 2 * np.pi
|
|
A2 = 9.5 ** 2 * np.pi
|
|
A1 = 10.5 ** 2 * np.pi
|
|
|
|
possible_values = np.linspace(-10, 10, 41) # fromn -10 to 10 with step 0.5
|
|
|
|
xy = [(np.random.choice(possible_values), np.random.choice(possible_values)) for _ in range(n)]
|
|
|
|
dataset = []
|
|
|
|
for i in xy:
|
|
A = (i[0]**2 + i[1]**2) * np.pi
|
|
|
|
#print(A)
|
|
|
|
if A <= A10:
|
|
dataset.append([10, i[0], i[1]])
|
|
elif A > A10 and A <= A9:
|
|
dataset.append([9, i[0], i[1]])
|
|
elif A > A9 and A <= A8:
|
|
dataset.append([8, i[0], i[1]])
|
|
elif A > A8 and A <= A7:
|
|
dataset.append([7, i[0], i[1]])
|
|
elif A > A7 and A <= A6:
|
|
dataset.append([6, i[0], i[1]])
|
|
elif A > A6 and A <= A5:
|
|
dataset.append([5, i[0], i[1]])
|
|
elif A > A5 and A <= A4:
|
|
dataset.append([4, i[0], i[1]])
|
|
elif A > A4 and A <= A3:
|
|
dataset.append([3, i[0], i[1]])
|
|
elif A > A3 and A <= A2:
|
|
dataset.append([2, i[0], i[1]])
|
|
elif A > A2 and A <= A1:
|
|
dataset.append([1, i[0], i[1]])
|
|
elif A > A1:
|
|
dataset.append([0, i[0], i[1]])
|
|
|
|
with open('data/synthetic_shots.csv', 'w', newline='') as csvfile:
|
|
fieldnames = ['points', 'x', 'y']
|
|
writer = csv.writer(csvfile)
|
|
writer.writerow(fieldnames)
|
|
writer.writerows(dataset)
|