2021-05-23 11:43:31 +02:00
|
|
|
import json
|
2021-05-23 17:00:07 +02:00
|
|
|
import mines.disarming.mine_parameters as param
|
2021-05-23 11:43:31 +02:00
|
|
|
import os
|
2021-05-23 17:00:07 +02:00
|
|
|
from random import choice
|
2021-05-23 11:43:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
# this module is self contained, used to generate a json file
|
2021-05-23 13:38:16 +02:00
|
|
|
DIR_DATA = os.path.join("../../resources", "data")
|
2021-05-23 11:43:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
# just to show, how mine parameters works
|
|
|
|
def param_presents():
|
|
|
|
mine = param.MineParameters()
|
|
|
|
print(mine.jsonifyable_dict())
|
|
|
|
|
|
|
|
json_mine = json.dumps(mine.jsonifyable_dict())
|
|
|
|
print(json_mine)
|
|
|
|
|
|
|
|
new_mine = param.MineParameters(json.loads(json_mine))
|
|
|
|
print(new_mine.get_parameters())
|
|
|
|
|
|
|
|
|
|
|
|
def generate_data(file_name: str, lines: int):
|
|
|
|
file = open(os.path.join(DIR_DATA, file_name), "w")
|
2021-05-23 17:00:07 +02:00
|
|
|
data_set = set()
|
2021-05-23 11:43:31 +02:00
|
|
|
|
2021-05-23 17:00:07 +02:00
|
|
|
for x in range(100000):
|
2021-05-23 11:43:31 +02:00
|
|
|
new_params = json.dumps(param.MineParameters().jsonifyable_dict())
|
2021-05-23 17:00:07 +02:00
|
|
|
data_set.add(new_params)
|
|
|
|
|
|
|
|
for x in range(lines):
|
|
|
|
if len(data_set) == 0:
|
|
|
|
break
|
|
|
|
|
|
|
|
random_params = data_set.pop()
|
|
|
|
file.write(random_params)
|
2021-05-23 11:43:31 +02:00
|
|
|
file.write("\n")
|
|
|
|
|
2021-05-23 17:00:07 +02:00
|
|
|
del data_set
|
|
|
|
|
2021-05-23 11:43:31 +02:00
|
|
|
file.close()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2021-05-23 17:00:07 +02:00
|
|
|
generate_data("params4.txt", 1000)
|
2021-05-23 11:43:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|