improved generate_data() method in parameter_json.py to not generate duplicates
This commit is contained in:
parent
c7845a0d1f
commit
fa249cf484
@ -1,6 +1,7 @@
|
||||
import json
|
||||
import mine_parameters as param
|
||||
import mines.disarming.mine_parameters as param
|
||||
import os
|
||||
from random import choice
|
||||
|
||||
|
||||
# this module is self contained, used to generate a json file
|
||||
@ -21,17 +22,27 @@ def param_presents():
|
||||
|
||||
def generate_data(file_name: str, lines: int):
|
||||
file = open(os.path.join(DIR_DATA, file_name), "w")
|
||||
data_set = set()
|
||||
|
||||
for x in range(100000):
|
||||
new_params = json.dumps(param.MineParameters().jsonifyable_dict())
|
||||
data_set.add(new_params)
|
||||
|
||||
for x in range(lines):
|
||||
new_params = json.dumps(param.MineParameters().jsonifyable_dict())
|
||||
file.write(new_params)
|
||||
if len(data_set) == 0:
|
||||
break
|
||||
|
||||
random_params = data_set.pop()
|
||||
file.write(random_params)
|
||||
file.write("\n")
|
||||
|
||||
del data_set
|
||||
|
||||
file.close()
|
||||
|
||||
|
||||
def main():
|
||||
generate_data("params3.txt", 20000)
|
||||
generate_data("params4.txt", 1000)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
Reference in New Issue
Block a user