From f71fee998043207ad0798bc2416f61e860cdc79d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20Parafi=C5=84ski?= Date: Tue, 9 Jun 2020 19:11:55 +0000 Subject: [PATCH] =?UTF-8?q?Zaktualizuj=20'RaportSzymonParafi=C5=84ski.md'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RaportSzymonParafiński.md | 58 +++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/RaportSzymonParafiński.md b/RaportSzymonParafiński.md index e488445..b767c39 100644 --- a/RaportSzymonParafiński.md +++ b/RaportSzymonParafiński.md @@ -111,6 +111,8 @@ void stanPola(int x, int y) { //[x][x][0] = 3 - środek i nawóz //[x][x][1] - wartość wzrostu rośliny + polecenie = "python pliki/injectCode.py 1 "; + if (stan[x][y][0] == 0) polecenie.append("0 0 "); if (stan[x][y][0] == 1) @@ -122,6 +124,8 @@ void stanPola(int x, int y) { int w = (stan[x][y][1]); std::string s = std::to_string(w); polecenie.append(s); + + decisionTree(polecenie); } ``` @@ -134,6 +138,21 @@ void decisionTree(string polecenie) { std::string str = polecenie; const char* c = str.c_str(); 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] @@ -144,28 +163,34 @@ import sys def prediction(warzywo, nawoz ,srodek, stan_wzrostu): - filename = 'decisionTree.sav' - tree = pickle.load(open(filename, 'rb')) - val = (tree.predict([[warzywo, nawoz, srodek, stan_wzrostu]])) - print(decision(val)) + filename = 'pliki/decisionTree.sav' + tree = pickle.load(open(filename, 'rb')) + val = (tree.predict([[warzywo, nawoz, srodek, stan_wzrostu]])) + save(val) + +def save(prediction): + pred = str(prediction) + plik = open('pliki/dec.txt', 'w') + plik.write(pred[1]) + plik.close() def decision(prediction): - if prediction == 0: - return "Nie_podejmuj_dzialania" - elif prediction == 1: - return "Zastosuj_nawoz" - elif prediction == 2: - return "Zastosuj_srodek" - elif prediction == 4: - return "Zbierz" - elif prediction == 5: - return "Roslina_juz_zgnila__zbierz_i_wyrzuc" + if prediction == 0: + return "Nie_podejmuj_dzialania" + elif prediction == 1: + return "Zastosuj_nawoz" + elif prediction == 2: + return "Zastosuj_srodek" + elif prediction == 4: + return "Zbierz" + elif prediction == 5: + return "Roslina_juz_zgnila__zbierz_i_wyrzuc" if __name__ == '__main__': - # Map command line arguments to function arguments. - prediction(*sys.argv[1:]) + # Map command line arguments to function arguments. + prediction(*sys.argv[1:]) ``` Generowane polecenie wygląda w ten sposób: ``` @@ -173,7 +198,6 @@ python injectCode.py a b c d ``` Gdzie: * a -> rodzaj warzywa - * 1: "burak" * b -> czy roślina była nawożona * 0: "nie" * 1: "tak"