Zaktualizuj 'RaportSzymonParafiński.md'

This commit is contained in:
Szymon Parafiński 2020-06-09 19:11:55 +00:00
parent eccc3b22f5
commit f71fee9980

View File

@ -111,6 +111,8 @@ void stanPola(int x, int y) {
//[x][x][0] = 3 - środek i nawóz //[x][x][0] = 3 - środek i nawóz
//[x][x][1] - wartość wzrostu rośliny //[x][x][1] - wartość wzrostu rośliny
polecenie = "python pliki/injectCode.py 1 ";
if (stan[x][y][0] == 0) if (stan[x][y][0] == 0)
polecenie.append("0 0 "); polecenie.append("0 0 ");
if (stan[x][y][0] == 1) if (stan[x][y][0] == 1)
@ -122,6 +124,8 @@ void stanPola(int x, int y) {
int w = (stan[x][y][1]); int w = (stan[x][y][1]);
std::string s = std::to_string(w); std::string s = std::to_string(w);
polecenie.append(s); polecenie.append(s);
decisionTree(polecenie);
} }
``` ```
@ -134,6 +138,21 @@ void decisionTree(string polecenie) {
std::string str = polecenie; std::string str = polecenie;
const char* c = str.c_str(); const char* c = str.c_str();
system(c); system(c);
int line = 0;
ifstream inFile;
inFile.open("pliki/dec.txt");
if (!inFile) {
cout << "Unable to open file";
exit(1); // terminate with error
}
while (inFile >> line) {
decyzja = line;
}
inFile.close();
akcja();
} }
``` ```
#### injectCode(): [python] #### injectCode(): [python]
@ -144,28 +163,34 @@ import sys
def prediction(warzywo, nawoz ,srodek, stan_wzrostu): def prediction(warzywo, nawoz ,srodek, stan_wzrostu):
filename = 'decisionTree.sav' filename = 'pliki/decisionTree.sav'
tree = pickle.load(open(filename, 'rb')) tree = pickle.load(open(filename, 'rb'))
val = (tree.predict([[warzywo, nawoz, srodek, stan_wzrostu]])) val = (tree.predict([[warzywo, nawoz, srodek, stan_wzrostu]]))
print(decision(val)) save(val)
def save(prediction):
pred = str(prediction)
plik = open('pliki/dec.txt', 'w')
plik.write(pred[1])
plik.close()
def decision(prediction): def decision(prediction):
if prediction == 0: if prediction == 0:
return "Nie_podejmuj_dzialania" return "Nie_podejmuj_dzialania"
elif prediction == 1: elif prediction == 1:
return "Zastosuj_nawoz" return "Zastosuj_nawoz"
elif prediction == 2: elif prediction == 2:
return "Zastosuj_srodek" return "Zastosuj_srodek"
elif prediction == 4: elif prediction == 4:
return "Zbierz" return "Zbierz"
elif prediction == 5: elif prediction == 5:
return "Roslina_juz_zgnila__zbierz_i_wyrzuc" return "Roslina_juz_zgnila__zbierz_i_wyrzuc"
if __name__ == '__main__': if __name__ == '__main__':
# Map command line arguments to function arguments. # Map command line arguments to function arguments.
prediction(*sys.argv[1:]) prediction(*sys.argv[1:])
``` ```
Generowane polecenie wygląda w ten sposób: Generowane polecenie wygląda w ten sposób:
``` ```
@ -173,7 +198,6 @@ python injectCode.py a b c d
``` ```
Gdzie: Gdzie:
* a -> rodzaj warzywa * a -> rodzaj warzywa
* 1: "burak"
* b -> czy roślina była nawożona * b -> czy roślina była nawożona
* 0: "nie" * 0: "nie"
* 1: "tak" * 1: "tak"