Skip to content
Snippets Groups Projects
Commit 0d794a39 authored by s183927's avatar s183927
Browse files

You can now save and import saved data

parent 7158e4b2
No related branches found
No related tags found
No related merge requests found
import pygame
import os
import time
import numpy as np
import pandas as pd
from random import randint
from sklearn.neighbors import NearestNeighbors
......@@ -112,18 +114,59 @@ while True:
black = np.vstack((black, color))
points = np.vstack((points, color))
loop = False
# check if button presses are down or up, if they are, they save or import data
if event.key == pygame.K_DOWN:
# check if previous files exist
try:
os.remove("training.txt")
os.remove("points.txt")
os.remove("white.txt")
os.remove("black.txt")
except:
pass
dataFile = open("training.txt", "w")
dataFile.write(str(points) + "\n")
dataFile.write(str(white) + "\n")
dataFile.write((str(black) + "\n"))
dataFile.close()
# make a file for the points matrix
pointsFile = open("points.txt", "w")
for n in points:
for i in range(len(n)):
if i == len(n) - 1:
pointsFile.write(str(n[i]))
else:
pointsFile.write(str(n[i]) + " ")
pointsFile.write("\n")
pointsFile.close()
# make a file for the white matrix
whiteFile = open("white.txt", "w")
for n in white:
for i in range(len(n)):
if i == len(n) - 1:
whiteFile.write(str(n[i]))
else:
whiteFile.write(str(n[i]) + " ")
whiteFile.write("\n")
whiteFile.close()
# make a file for the black matrix
blackFile = open("black.txt", "w")
for n in black:
for i in range(len(n)):
if i == len(n) - 1:
blackFile.write(str(n[i]))
else:
blackFile.write(str(n[i]) + " ")
blackFile.write("\n")
blackFile.close()
text("Data successfully saved to files", (255,255,255), smallfont, 10, 10)
pygame.display.update()
if event.key == pygame.K_UP:
try:
pass
points = np.loadtxt("points.txt")
white = np.loadtxt("white.txt")
black = np.loadtxt("black.txt")
text("Data successfully imported", (255,255,255), smallfont, 10, 10)
pygame.display.update()
except:
pass
\ No newline at end of file
text("Data failed to be imported", (255,255,255), mediumfont, 10, 10)
pygame.display.update()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment