From 564dee84a97a26a26dfe8d6b31e89c5e109fcb9b Mon Sep 17 00:00:00 2001 From: alamasrorul Date: Wed, 20 Nov 2019 12:21:01 +0700 Subject: [PATCH] CBR Function Is Activated --- app/src/main/AndroidManifest.xml | 16 +- .../feature/diagnosis/DiagnosisActivity.kt | 1 + .../feature/diagnosis/DiagnosisAdapter.kt | 309 ++++++++++++++++++ .../feature/diagnosis/DiagnosisPresenter.kt | 36 +- .../lovebird/repository/model/Gejala.kt | 6 +- app/src/main/res/values/styles.xml | 4 + 6 files changed, 347 insertions(+), 25 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 08c118c..ef16aa0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,10 +9,18 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> - - - - + + + + diff --git a/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisActivity.kt b/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisActivity.kt index f95ff7c..7551390 100644 --- a/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisActivity.kt +++ b/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisActivity.kt @@ -41,6 +41,7 @@ class DiagnosisActivity : AppCompatActivity(), DiagnosisContract.View { val intent = Intent(this, HasilActivity::class.java) intent.putExtra("namaburung", textNamaBurung.toString()) startActivity(intent) + adapter.cbr() } bindView() diff --git a/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisAdapter.kt b/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisAdapter.kt index 55d067a..4e5e5d8 100644 --- a/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisAdapter.kt +++ b/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisAdapter.kt @@ -16,6 +16,16 @@ class DiagnosisAdapter internal constructor(private val context: Context) : private var mCheckedGejala: ArrayList = ArrayList() private var inputGejala : ArrayList = ArrayList() + + //Array Penyakit + private var cacingan : ArrayList = arrayListOf(0,1,2,3,4) + private var kutuBurung : ArrayList = arrayListOf(0,4,5,6,9) + private var snot : ArrayList = arrayListOf(0,7,8,11,12) + private var berakKapur : ArrayList = arrayListOf(0,1,10,17) + private var mencretBakteri : ArrayList = arrayListOf(0,1,2) + private var bubul : ArrayList = arrayListOf(13,14) + private var virusBurung: ArrayList = arrayListOf(15,16) + private var mListData: List init { @@ -54,6 +64,13 @@ class DiagnosisAdapter internal constructor(private val context: Context) : mCheckedGejala.add(gejala) inputGejala.add(gejala.kodeGejala) + //cek output + for (element in mCheckedGejala) { + println(element) + } + + + } else { holder.mCbGejala.isChecked = false gejala.isChecked = false @@ -61,12 +78,304 @@ class DiagnosisAdapter internal constructor(private val context: Context) : inputGejala.remove(gejala.kodeGejala) } + intent.putExtra("checked", mCheckedGejala) intent.putExtra("gejala", gejala) } + + + + } + fun cbr(){ + + + var hs1:Float =0f + var hs2:Float =0f + var hs3:Float =0f + var hs4:Float =0f + var hs5:Float =0f + var hs6:Float =0f + var hs7:Float =0f + + + + + var tb1:Float =0f + var tb2:Float =0f + var tb3:Float =0f + var tb4:Float =0f + var tb5:Float =0f + var tb6:Float =0f + var tb7:Float =0f + + + var tbp1:Float =0f + var tbp2:Float =0f + var tbp3:Float =0f + var tbp4:Float =0f + var tbp5:Float =0f + var tbp6:Float =0f + var tbp7:Float =0f + + + + var Penyakit: String="" + var persentaseCBR: Float=0f + var bobotMax: Float=0f + + + //Penyakit 1 + + for (i in 0 until cacingan.size){ + + //total bobot + tbp1 += mListData[cacingan[i]].bobot + for(j in 0 until inputGejala.size) + { + + if(cacingan[i]==inputGejala[j]) + { + tb1 += mListData[cacingan[i]].bobot + + } + } + } + + //Penyakit 2 + for (i in 0 until kutuBurung.size){ + + //total bobot + tbp2 += mListData[kutuBurung[i]].bobot + for(j in 0 until inputGejala.size) + { + if(kutuBurung[i]==inputGejala[j]) + { + tb2 += mListData[kutuBurung[i]].bobot + + } + } + } + + + //Penyakit 3 + for (i in 0 until snot.size){ + + //total bobot + tbp3 += mListData[snot[i]].bobot + for(j in 0 until inputGejala.size) + { + if(snot[i]==inputGejala[j]) + { + tb3 += mListData[snot[i]].bobot + + } + } + } + + + //Penyakit 4 + for (i in 0 until berakKapur.size){ + + //total bobot + tbp4 += mListData[berakKapur[i]].bobot + for(j in 0 until inputGejala.size) + { + if(berakKapur[i]==inputGejala[j]) + { + tb4 += mListData[berakKapur[i]].bobot + + } + } + } + + //Penyakit 5 + for (i in 0 until mencretBakteri.size){ + + //total bobot + tbp5 += mListData[mencretBakteri[i]].bobot + for(j in 0 until inputGejala.size) + { + if(mencretBakteri[i]==inputGejala[j]) + { + tb5 += mListData[mencretBakteri[i]].bobot + + } + } + } + + //Penyakit 6 + for (i in 0 until bubul.size){ + + //total bobot + tbp6 += mListData[bubul[i]].bobot + for(j in 0 until inputGejala.size) + { + if(bubul[i]==inputGejala[j]) + { + tb6 += mListData[bubul[i]].bobot + + } + } + } + + + //Penyakit 7 + for (i in 0 until virusBurung.size){ + + //total bobot + tbp7 += mListData[virusBurung[i]].bobot + for(j in 0 until inputGejala.size) + { + if(virusBurung[i]==inputGejala[j]) + { + tb7 += mListData[virusBurung[i]].bobot + + } + } + } + + + hs1=(tb1/tbp1)*100 + hs2=(tb2/tbp2)*100 + hs3=(tb3/tbp3)*100 + hs4=(tb4/tbp4)*100 + hs5=(tb5/tbp5)*100 + hs6=(tb6/tbp7)*100 + hs7=(tb7/tbp7)*100 + println("Hasil : "+hs1) + println("TB : "+ tb1) + println("TBP : "+ tbp1) + println("Hasil : "+hs2) + println("TB : "+ tb2) + println("TBP : "+ tbp2) + println("Hasil : "+hs3) + println("TB : "+ tb3) + println("TBP : "+ tbp3) + println("Hasil : "+hs4) + println("TB : "+ tb4) + println("TBP : "+ tbp4) + println("Hasil : "+hs5) + println("TB : "+ tb5) + println("TBP : "+ tbp5) + println("Hasil : "+hs6) + println("TB : "+ tb6) + println("TBP : "+ tbp6) + println("Hasil : "+hs7) + println("TB : "+ tb7) + println("TBP : "+ tbp7) + + + + //Searching paling besar + if (hs1>persentaseCBR){ + persentaseCBR=hs1 + Penyakit="Cacingan" + bobotMax=tb1 + } + else if(hs1==persentaseCBR) { + if (bobotMax < tb1) + { + persentaseCBR=hs1 + Penyakit="Cacingan" + bobotMax=tb1 + } + } + + if (hs2>persentaseCBR){ + persentaseCBR=hs2 + Penyakit="Kutu Burung" + bobotMax=tb2 + } + else if(hs2==persentaseCBR) { + if (bobotMax < tb2) + { + persentaseCBR=hs2 + Penyakit="Kutu Burung" + bobotMax=tb2 + } + } + + if (hs3>persentaseCBR){ + persentaseCBR=hs3 + Penyakit="Snot" + bobotMax=tb3 + } + else if(hs3==persentaseCBR) { + if (bobotMax < tb3) + { + persentaseCBR=hs3 + Penyakit="Snot" + bobotMax=tb3 + } + } + + if (hs4>persentaseCBR){ + persentaseCBR=hs4 + Penyakit="Berak Kapur" + bobotMax=tb4 + } + else if(hs4==persentaseCBR) { + if (bobotMax < tb4) + { + persentaseCBR=hs4 + Penyakit="Berak Kapur" + bobotMax=tb4 + } + } + + if (hs5>persentaseCBR){ + persentaseCBR=hs5 + Penyakit="Mencret Bakteri" + bobotMax=tb5 + } + else if(hs5==persentaseCBR) { + if (bobotMax < tb5) + { + persentaseCBR=hs5 + Penyakit="Mencret Bakteri" + bobotMax=tb5 + } + } + + if (hs6>persentaseCBR){ + persentaseCBR=hs6 + Penyakit="Bubul" + bobotMax=tb6 + } + else if(hs6==persentaseCBR) { + if (bobotMax < tb6) + { + persentaseCBR=hs6 + Penyakit="Bubul" + bobotMax=tb6 + } + } + + if (hs7>persentaseCBR){ + persentaseCBR=hs7 + Penyakit="Virus Burung" + bobotMax=tb7 + } + else if(hs7==persentaseCBR) { + if (bobotMax < tb7) + { + persentaseCBR=hs7 + Penyakit="Virus Burung" + bobotMax=tb7 + } + } + + println("Diagnosa Penyakit : "+Penyakit) + println("Persentase CBR : "+persentaseCBR) + + + } class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { var mCbGejala: CheckBox = itemView.findViewById(R.id.checkbox_gejala) } + + + } \ No newline at end of file diff --git a/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisPresenter.kt b/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisPresenter.kt index e68f72b..025f72e 100644 --- a/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisPresenter.kt +++ b/app/src/main/java/com/makaryostudio/lovebird/feature/diagnosis/DiagnosisPresenter.kt @@ -18,24 +18,24 @@ class DiagnosisPresenter internal constructor(private val view: DiagnosisContrac override fun loadListGejala() { val listGejala = arrayListOf( - Gejala(1, "Nafsu Makan Menurun", 5), - Gejala(2,"Kotoran Cair",3), - Gejala(3, "Bulu Tidak Rapi", 2), - Gejala(4, "Kurang Bergairah/Lemas", 3), - Gejala(5, "Bobot Burung Menurun", 2), - Gejala(6, "Jarang Berkicau", 2), - Gejala(7, "Sering Menggigit Bulu", 2), - Gejala(8, "Kotoran Berwarna Keruh", 2), - Gejala(9, "Kotoran Berbau Busuk", 2), - Gejala(10, "Banyak Kutu", 4), - Gejala(11, "Sayang Menggantung", 5), - Gejala(12, "Mata Berair", 4), - Gejala(13, "Mata Bengkak", 3), - Gejala(14, "Kaki Bengkak", 3), - Gejala(15, "Kuku Memanjang", 2), - Gejala(16, "Lemah", 3), - Gejala(17, "Kelumpuhan Anggota Badan", 4), - Gejala(18, "Kotoran Seperti Kapur", 3) + Gejala(0, "Nafsu Makan Menurun", 5f), + Gejala(1,"Kotoran Cair",3f), + Gejala(2, "Bulu Tidak Rapi", 2f), + Gejala(3, "Kurang Bergairah/Lemas", 3f), + Gejala(4, "Bobot Burung Menurun", 2f), + Gejala(5, "Jarang Berkicau", 2f), + Gejala(6, "Sering Menggigit Bulu", 2f), + Gejala(7, "Kotoran Berwarna Keruh", 2f), + Gejala(8, "Kotoran Berbau Busuk", 2f), + Gejala(9, "Banyak Kutu", 4f), + Gejala(10, "Sayang Menggantung", 5f), + Gejala(11, "Mata Berair", 4f), + Gejala(12, "Mata Bengkak", 3f), + Gejala(13, "Kaki Bengkak", 3f), + Gejala(14, "Kuku Memanjang", 2f), + Gejala(15, "Lemah", 3f), + Gejala(16, "Kelumpuhan Anggota Badan", 4f), + Gejala(17, "Kotoran Seperti Kapur", 3f) ) diff --git a/app/src/main/java/com/makaryostudio/lovebird/repository/model/Gejala.kt b/app/src/main/java/com/makaryostudio/lovebird/repository/model/Gejala.kt index d37587a..1174e03 100644 --- a/app/src/main/java/com/makaryostudio/lovebird/repository/model/Gejala.kt +++ b/app/src/main/java/com/makaryostudio/lovebird/repository/model/Gejala.kt @@ -6,7 +6,7 @@ import android.os.Parcelable data class Gejala( var kodeGejala: Int, var gejalaDialami: String = "", - var bobot: Int + var bobot: Float ) : Parcelable { var isChecked: Boolean = false @@ -14,7 +14,7 @@ data class Gejala( parcel.readInt(), parcel.readString().toString(), - parcel.readInt() + parcel.readFloat() ) { isChecked = parcel.readByte() != 0.toByte() } @@ -22,7 +22,7 @@ data class Gejala( override fun writeToParcel(parcel: Parcel, flags: Int) { parcel.writeInt(kodeGejala) parcel.writeString(gejalaDialami) - parcel.writeInt(bobot) + parcel.writeFloat(bobot) parcel.writeByte(if (isChecked) 1 else 0) } diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5885930..3dfb71a 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -8,4 +8,8 @@ @color/colorAccent + +