Zaktualizuj 'RaportSzymonParafiński.md'
This commit is contained in:
parent
eccc3b22f5
commit
f71fee9980
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user