Projekt_Sztuczna_Inteligencja/mines/disarming/parameter_json.py

50 lines
1.1 KiB
Python
Raw Normal View History

import json
import mines.disarming.mine_parameters as param
import os
from random import choice
# this module is self contained, used to generate a json file
DIR_DATA = os.path.join("../../resources", "data")
# 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")
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):
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("params4.txt", 1000)
if __name__ == "__main__":
main()