BAB V KESIMPULAN DAN SARAN
5.2 Saran
Dari hasil penelitian Tugas Akhir ini, terdapat beberapa saran yang dapat dilakukan kedepannya terkait sistem yang dirancang yaitu:
1. Menambahkan sensor lain agar hasil dari input pada alat lebih akurat.
2. Menambakan parameter kesehatan paru-paru yang lainnya agar hasil keputusan kesehatan paru-paru lebih akurat.
3. Menambahkan feedback langsung atau controlling dari alat atau sistem agar lebih efisien.
4. Mencari metode lain agar hasil keputusan pada sistem lebih efisien dan akurat.
DAFTAR PUSTAKA
[ 1 ] tb.indonesa,id/pustaka-tbc/dashboard-tb/, Situasi TB di Indonesia, Kementrian Kesehatan Republik Indonesia, 2020
[ 2 ] gco.iarc.fr , Global Cancer Observatory (GCO)
[ 3 ] I. Naradhyana, U. Sunarya, and S. Hadiyoso, “Alat Pemantau Sistem Pernafasan Menggunakan Mikrokontroller dan E-health PCB”, e-Proceeding of Applied Science : vol.1, no.1, 2015, Universitas Telkom.
[ 4 ] L. Mayer and R. Bhikha, “Nails as Indicators of Health Status”, Tibb Inst., 2014.
[ 5 ] D. Kurniawan, R. Maulana, and M. H. H. Ichsan, “Implementasi Pendeteksi Penyakit Paru-Paru Berdasarkan Warna Kuku dan Suhu Tubuh Berbasis Sensor TCS3200 Dan Sensor LM35 dengan Metode Naive Bayes”, Jurnal Pengembangan Teknologi Informasi dan Ilmu Komputer, vol.3, no.4, hal.
3383–3389, 2019, Universitas Brawijaya.
[ 6 ] A. E. Munthafa and H. Mubarok, “Penerapan Metoda Analytic Hierarchy Process Dalam Sistem Pendukung Keputusan Penentuan Mahasiswa Berprestasi”, Jurnal Siliwangi, vol.3, no. 2, 2017, Universitas Siliwangi [ 7 ] P. Sethi, and S. R. Sarangi, “Internet Of Things: Architectures, Protocols, and
Applications”, Hindawi, Journal of Electrical and Computer Engineering, 2017, Department of Computer Science, IIT Delhi, New Delhi, India.
[ 8 ] Adnan M, “Radiology of The Respiratory System”, Medical Report, Department of Radiology Medical Faculty, UNHAS.
[ 9 ] P. Gokhale, O. Bhat and S. Bhat, “Introduction to IOT”, International Advanced Reasearch Journal in Science, Engineering and Technology, Vol.
5, Issue 1, January 2018, IT Dept., Smt. Kashibai Navale College of Engineering
[10] D. Sasmoko and Y. A. Wicaksono, “Implementasi Penerapan Internet of Things (IoT) Pada Monitoring Infus Menggunakan ESP 8266 dan We Untuk Berbagi Data”, Jurnal Ilmiah Informatika, 2017, Sekolah Tinggi Elektronika dan Komputer Semarang.
[11] Shan, H. "DS18B20 Waterproof Temperature Sensor Cable."
Terraelectronica. Ru (2017): 0-2.
[12] SAHULEKA, BRIAN., LIM, RESMANA., SANTOSO, PETRUS., Sistem Data Logging Sederhana Berbasis Internet Of Things untuk Pemantauan Suhu Tubuh dan Detak Jantung. Program Studi Teknik Elektro,Universitas Kristen Petra, 32, 1411-870X.
[13] D. A. E. Putra, “Smartphone Sebagai Gaya Hidup” 2015, Universitas Sumatera Utara.
[14] R. L. Sidam, M. S. Suraatmadja and H. Fauzi, “Perancangan Alat Ukur Denyut Nadi Menggunakan Sensor Strain Gauge Melalui Media Bluetooth Smartphone”, e-Proceeding of Engineering : Vol. 3, No. 2, Agustus 2016, Page 1305, Fakultas Teknik Elektro, Universtias Telkom.
[15] Tam, K., Feizollah, A., Anuar, N. B., Salleh, R., & Cavallaro, L. (2017). The Evolution of Android Malware and Android Analysis Techniques. ACM Computing Surveys, Vol. 0, No. 0, Article 00, 1-33.
[16] Clifton Craig, A. G. (2015). Learn Android Studio: Build Android Apps Quickly and Effectively. New York: Apress.
[17] Panchal, P. R., & Patel, M. A. (2017). A comparative study: Java Vs kotlin Programming in Android. International Journal of Innovative Trends in Engineering & Research, 4-10.
[18] Khan, M. E., & Khan, F. (2012). A Comparative Study of White Box, Black Box and Grey Box Testing Techniques. International Journal of Advanced Computer Science and Applications, Vol. 3, No.6, 12-15.
[19] Y. D. Yun, C. Lee, and H. S. Lim, “Designing an intelligent UI/UX system based on the cognitive response for smart senior,” Proceeding - 2016 2nd Int.
Conf. Sci. Inf. Technol. ICSITech 2016 Inf. Sci. Green Soc. Environ., pp.
281–284, 2017
[20] Zhong, Chang-Le, Zhen Zhu, and Ren-Gen Huang. "Study on the IOT architecture and gateway technology." 2015 14th International Symposium on Distributed Computing and Applications for Business Engineering and Science (DCABES). IEEE, 2015.
[21] K. M. Riki, R. Maulana and W. Kusuma, “Implementasi Sensor Piezoelektrik Sebagai Prototype Alat Musik Piano Berbasis Arduino UNO.”, Jurnal Pengembangan Teknologi Informasi dan Ilmu Komputer, Vol. 2, No. 11,
November 2018.
[22] L. Mardiansyah, S. Hartini, and W. Budiawan, “Perancangan Sistem Pendukung Keputusan Untuk Pemilihan Supplier Batik Menggunakan Algoritma Analytical Hierarchy Process (AHP)”, Industrial Engineering Online Journal, Vol. 3, No. 2, 2014, Fakultas Teknik, Universitas Diponegoro.
[23] Kusrini, “Konsep dan Aplikasi Sistem Pendukung Keputusan”, KM Kom- Yogyakarta : CV Andi Offset, 2007.
[24] J. A. Alonso, and M. T. Lamata, “Consistency In The Analytic Hierarchy Process: A New Approach”, International Journal of Uncertainty, Fuzziness and Knowledge-Based Systems, 14(04), 445-459, 2016.
[25] R. Wulandari, “Analisis QoS (Quality of Service) Pada Jaringan Internet (Studi Kasus : UPT Loka Uji Teknik Penambangan Jampang Kulon - LIPI)”, Jurnal Teknik Informatika dan Sistem Informasi : Vol. 2, No. 2, Agustus 2016.
[26] Firebase, “Firebase Realtime Database, 3 Desember 2019 [Online]. Tersedia di https://Firebase.google.com/docs/database. [Diakses pada 27 November 2020].
[27] A. Anisah and M. S. Mayasari, “Desain Database Sistem Informasi Penerimaan Peserta Didik Baru Pada Selective English Course.” Simetris J.
Tek. Mesin, Elektro Dan Ilmu Komput., Vol. 7, No. 1, P. 183, 2016.
[28] Kemalasari, P. S. Wardana and R. Adil, “Spirometer Non-Invasive Dengan Sensor Piezoelektrik Untuk Deteksi Kesehatan Paru-paru.”, Jurnal ELKOMIKA, Vol. 5, No. 2, 2017.
LAMPIRAN
SOURCE CODE ALAT
#include <Arduino.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <FirebaseESP8266.h>
#include <ESP8266WiFi.h>
//
#define CALIB_DONE
// TCS3200
#define S0 13 // D7
#define S1 0 // D3
#define S2 14 // D5
#define S3 12 // D6
#define sensorIn 5 // D1
#define piezoPIN A0 float frequency = 0;
// DS18B20
#define ds_pin 4 // D2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ds_pin);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature dsb18b20(&oneWire);
float temperature = 0.0;
float red, green, blue = 0.0;
int piezo_signal = 0;
float piezo_voltage = 0.0;
// map value
const int calibration_red_low = 160;
const int calibration_red_high = 700;
const int calibration_blue_low = 175;
const int calibration_blue_high = 700;
const int calibration_green_low = 150;
const int calibration_green_high = 800;
// wifi configuration
#define ssid "TEDDY"
#define password "asu12345"
// firebase configuration
#define FIREBASE_HOST "https://lung-apps-default- rtdb.firebaseio.com/"
#define FIREBASE_AUTH "vBLt8T5uNvYnaYLgSlFgcEUBKiY6QqMnHHNThT2g" //
settings/service account/database secret String node_path = "/device1";
//Define FirebaseESP8266 data object FirebaseData firebase_data;
FirebaseJson json;
float read_color(int s2_value, int s3_value) { digitalWrite(S2, s2_value);
digitalWrite(S3, s3_value);
// Reading the output frequency
//frequency = 10000.0 / pulseIn(sensorIn, LOW);
frequency = pulseIn(sensorIn, LOW);
return frequency;
}
// function to print a device address
void printAddress(DeviceAddress deviceAddress) {
for (uint8_t i = 0; i < 8; i++) {
if (deviceAddress[i] < 16) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
} }
// setup for wifi void setup_wifi() {
// Let us connect to WiFi WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) { delay(500);
Serial.print(".");
}
Serial.println("...");
Serial.println("WiFi Connected....IP Address:");
Serial.println(WiFi.localIP());
}
void setup_ds18b20(){
Serial.println("Dallas Temperature IC Control Library Demo");
// locate devices on the bus
Serial.print("Locating devices...");
dsb18b20.begin();
Serial.print("Found ");
Serial.print(dsb18b20.getDeviceCount(), DEC);
Serial.println(" devices.");
}
// setup firebase void setup_firebase(){
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
//Set database read timeout to 1 minute (max 15 minutes) // Firebase.setReadTimeout(firebaseData, 1000 * 60);
//tiny, small, medium, large and unlimited.
//Size and its write timeout e.g. tiny (1s), small (10s), medium ( 30s) and large (60s).
Firebase.setwriteSizeLimit(firebase_data, "tiny");
}
void read_temperature() {
dsb18b20.requestTemperatures(); // Send the command to get tempera tures
temperature = dsb18b20.getTempCByIndex(0);
if(temperature == DEVICE_DISCONNECTED_C) {
Serial.println("Error: Could not read temperature data");
return;
} }
void read_color(){
red = read_color(0, 0);
green = read_color(1, 1);
blue = read_color(0, 1);
float max = red;
if (green > max) max = green;
if (blue > max) max = blue;
red = round(255.0 * red / max);
green = round(255.0 * green / max);
blue = round(255.0 * blue / max);
}
int green_color = 0;
int blue_color = 0;
int red_color = 0;
void read_color_v2(){
// read color frequency red = read_color(0, 0);
green = read_color(1, 1);
blue = read_color(0, 1);
#ifdef CALIB_DONE
// mapping value between 0 - 255
red_color = map(red, calibration_red_low, calibration_red_high, 255, 0);
blue_color = map(blue, calibration_blue_low, calibration_blue_hi gh, 255, 0);
green_color = map(green, calibration_green_low, calibration_gree n_high, 255, 0 );
// limit highest value to 255
if (red_color > 255) red_color = 255;
if (blue_color > 255) blue_color = 255;
if (green_color > 255) green_color = 255;
// limit lowest value to 0
if (red_color < 0) red_color = 0;
if (blue_color < 0) blue_color = 0;
if (green_color < 0) green_color = 0;
#endif }
void read_piezo(){
piezo_signal = analogRead(piezoPIN);
piezo_voltage = piezo_signal * (3.3 / 1024.0);
}
boolean status_red, status_blue, status_green, status_temperature, s tatus_piezo_voltage, status_piezo_analog;
void send_data_to_firebase(){
// set json for red value
json.clear().set("R", red_color);
status_red = Firebase.updateNode(firebase_data, node_path + "/colo r", json);
// set json for green value
json.clear().set("G", green_color);
status_blue = Firebase.updateNode(firebase_data, node_path + "/col or", json);
// set json for blue value
json.clear().set("B", blue_color);
status_green = Firebase.updateNode(firebase_data, node_path + "/co lor", json);
// set json for temperature
json.clear().set("temperature", temperature);
status_temperature = Firebase.updateNode(firebase_data, node_path, json);
// set json for piezo
json.clear().set("voltage", piezo_voltage);
status_piezo_voltage = Firebase.updateNode(firebase_data, node_pat h + "/spirometer", json);
// set json for piezo analog
json.clear().set("analog", piezo_signal);
status_piezo_analog = Firebase.updateNode(firebase_data, node_path + "/spirometer", json);
if(status_red && status_green && status_blue && status_temperature && status_piezo_analog && status_piezo_voltage){
Serial.println("Update data successfully...");
} else {
Serial.println("Failed " + firebase_data.errorReason());
} }
void setup_tcs(){
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(sensorIn, INPUT);
// Setting frequency-scaling to 20%
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW);
}
void print_all_sensor(){
// tcs
Serial.print("R : ");
Serial.print(red_color);
Serial.print("\t G : ");
Serial.print(green_color);
Serial.print("\t B : ");
Serial.print(blue_color);
// temperature
Serial.print("\t Temperature (C) : ");
Serial.print(temperature);
// piezo
Serial.print("\t Piezo : ");
Serial.print(piezo_signal);
Serial.print(" - V - ");
Serial.print(piezo_voltage);
// end
Serial.println();
}
void setup() {
Serial.println(" -- Lung Monitoring -- ");
Serial.begin(9600);
setup_tcs();
setup_ds18b20();
setup_wifi();
setup_firebase();
}
void loop() {
read_temperature();
read_color_v2();
read_piezo();
print_all_sensor();
send_data_to_firebase();
delay(100);
}
SOURCE CODE APLIKASI A. Main Activity
package com.example.healthmonitoring;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import com.ekn.gruzer.gaugelibrary.ArcGauge;
import com.ekn.gruzer.gaugelibrary.HalfGauge;
import com.ekn.gruzer.gaugelibrary.Range;
import com.example.healthmonitoring.monitoring.MonitoringActivity;
import butterknife.BindView;
import butterknife.ButterKnife;
public class MainActivity extends AppCompatActivity {
@BindView(R.id.input_age) EditText inputAge;
@BindView(R.id.input_height) EditText inputHeight;
@BindView(R.id.input_gender) Spinner inputGender;
@Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
// butterknife
ButterKnife.bind(this);
// spinner for gender selection ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.gender, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdo wn_item);
inputGender.setAdapter(adapter);
verifyStoragePermissions(this);
}
public void startDashboard(View view){
String height = inputHeight.getText().toString();
String age = inputAge.getText().toString();
String jenis_kelamin =
inputGender.getSelectedItem().toString();
//call intent
Intent intent = new Intent(this, MonitoringActivity.class);
intent.putExtra("HEIGHT", height);
intent.putExtra("AGE", age);
intent.putExtra("GENDER", jenis_kelamin);
Log.d("INPUT-FORM", "startDashboard: " + height + " - " + age + " - " + jenis_kelamin);
startActivity(intent);
}
// Storage Permissions
private static final int REQUEST_EXTERNAL_STORAGE = 1;
private static String[] PERMISSIONS_STORAGE = { Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE };
/**
* Checks if the app has permission to write to device storage *
* If the app does not has permission then the user will be prompted to grant permissions
*
* @param activity */
public static void verifyStoragePermissions(Activity activity) { // Check if we have write permission
int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permission != PackageManager.PERMISSION_GRANTED) { // We don't have permission so prompt the user ActivityCompat.requestPermissions(
activity,
PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE );
} } }
B. Monitoring Activity
package com.example.healthmonitoring.monitoring;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.ekn.gruzer.gaugelibrary.ArcGauge;
import com.ekn.gruzer.gaugelibrary.MultiGauge;
import com.ekn.gruzer.gaugelibrary.Range;
import com.example.healthmonitoring.AHP.AHPActivity;
import com.example.healthmonitoring.fuzzy.FuzzyActivity;
import com.example.healthmonitoring.R;
import org.w3c.dom.Text;
import butterknife.BindView;
import butterknife.ButterKnife;
public class MonitoringActivity extends AppCompatActivity implements MonitoringView {
// find element
@BindView(R.id.temperature_gauge) ArcGauge tempGauge;
@BindView(R.id.oksigen_gauge) MultiGauge spiroMeter;
@BindView(R.id.temperature_status) TextView temperatureStatus;
@BindView(R.id.nail_color) ImageView nailColor;
@BindView(R.id.red_value) TextView redValue;
@BindView(R.id.blue_value) TextView blueValue;
@BindView(R.id.green_value) TextView greenValue;
@BindView(R.id.volume_standart) TextView volumeStandart;
@BindView(R.id.analog_spiro) TextView analogSpiro;
@BindView(R.id.voltage_spiro) TextView voltageSpiro;
@BindView(R.id.v_max) TextView vMax;
@BindView(R.id.v_min) TextView vMin;
@BindView(R.id.volume_ukur) TextView volumeUkur;
@BindView(R.id.spiro_decision) TextView spiroDecision;
String ageStr, vitalCapacityStr;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState);
// set main layout name
setContentView(R.layout.activity_main);
// butterknife
ButterKnife.bind(this);
// load gauges loadSpiroMeter();
loadTemperatureGauge();
// invoke MVP monitoring
MonitoringPresenter presenter = new MonitoringPresenter(this);
// get intent
Intent intent = getIntent();
ageStr = intent.getStringExtra("AGE");
String height = intent.getStringExtra("HEIGHT");
String gender = intent.getStringExtra("GENDER");
// set standart estimated VC
presenter.calculate_estimated_vital_capacity(Integer.parseInt(ageStr), Integer.parseInt(height), gender);
// invoke the methods presenter.getTemperature();
presenter.getColor();
presenter.getSpiroMeter();
}
@Override
public void setTemperature(String temperature) {
tempGauge.setValue(Double.parseDouble(temperature)); // set value
}
@Override
public void setColor(String color_R, String color_G, String color_B) {
// set value
spiroMeter.setValue(Double.parseDouble(color_R));
spiroMeter.setSecondValue(Double.parseDouble(color_G));
spiroMeter.setThirdValue(Double.parseDouble(color_B));
}
@Override
public void setTemperatureStatus(String status) { temperatureStatus.setText(status);
}
@Override
public void setNailColor(String color_R, String color_G, String color_B) {
nailColor.setColorFilter(Color.argb(255, Integer.parseInt(color_R), Integer.parseInt(color_G), Integer.parseInt(color_B)));
}
@Override
public void setRValue(String rValue) { redValue.setText(rValue);
}
@Override
public void setGValue(String gValue) { greenValue.setText(gValue);
}
@Override
public void setBValue(String bValue) { blueValue.setText(bValue);
}
@Override
public void setStandartVolume(String value) {
volumeStandart.setText("Estimasi : " + value + " L");
}
@Override
public void setVolumeUkur(String value) { vitalCapacityStr = value;
volumeUkur.setText("Pengukuran : " + value + " L");
}
@Override
public void setAnalogSpiro(String value) { analogSpiro.setText("Analog : " + value);
}
@Override
public void setVoltageSpiro(String value) {
voltageSpiro.setText("Voltage : " + value + " V");
}
@Override
public void setVMax(String value) {
vMax.setText("VMax : " + value + " V");
}
@Override
public void setVMin(String value) {
vMin.setText("VMin : " + value + " V");
}
@Override
public void setDecisionSpiro(String value) { spiroDecision.setText(value);
}
private void loadSpiroMeter(){
// set kadar oksigen spiroMeter.setMinValue(0);
spiroMeter.setMaxValue(255);
// red
Range range1_oksigen = new Range();
range1_oksigen.setColor(Color.parseColor("#ff0000"));
range1_oksigen.setFrom(0);
range1_oksigen.setTo(255);
// green
Range range2_oksigen = new Range();
range2_oksigen.setColor(Color.parseColor("#00ff00"));
range2_oksigen.setFrom(0);
range2_oksigen.setTo(255);
spiroMeter.setDisplayValuePoint(true);
spiroMeter.setUseRangeBGColor(true);
// blue
Range range3_oksigen = new Range();
range3_oksigen.setColor(Color.parseColor("#0000ff"));
range3_oksigen.setFrom(0);
range3_oksigen.setTo(255);
spiroMeter.addRange(range1_oksigen);
spiroMeter.addSecondRange(range2_oksigen);
spiroMeter.addThirdRange(range3_oksigen);
}
private void loadTemperatureGauge(){
// set temperature
tempGauge.setMinValue(20);
tempGauge.setMaxValue(50);
Range range1 = new Range();
range1.setColor(Color.parseColor("#0000ff"));
range1.setFrom(20);
range1.setTo(36.5);
Range range2 = new Range();
range2.setColor(Color.parseColor("#00ff00"));
range2.setFrom(36.5);
range2.setTo(37.2);
Range range3 = new Range();
range3.setColor(Color.parseColor("#ff0000"));
range3.setFrom(37.4);
range3.setTo(50);
tempGauge.addRange(range1);
tempGauge.addRange(range2);
tempGauge.addRange(range3);
}
// run fuzzy activity
public void startFuzzyActivity(View view){
double temperature = tempGauge.getValue();
double red_color = spiroMeter.getValue();
double green_color = spiroMeter.getSecondValue();
double blue_color = spiroMeter.getThirdValue();
//call fuzzy activity intent
Intent intent = new Intent(this, FuzzyActivity.class);
// passing variable
intent.putExtra("TEMPERATURE", temperature);
intent.putExtra("R", red_color);
intent.putExtra("G", green_color);
intent.putExtra("B", blue_color);
// debug
Log.d("FUZZY-VARIABLE", "Temperature : " + temperature);
Log.d("FUZZY-VARIABLE", "R : " + red_color);
Log.d("FUZZY-VARIABLE", "B : " + blue_color);
Log.d("FUZZY-VARIABLE", "G : " + green_color);
// invoke
startActivity(intent);
}
// run ahp activity
public void startAHPActivity(View view){
double temperature = tempGauge.getValue();
double red_color = spiroMeter.getValue();
double green_color = spiroMeter.getSecondValue();
double blue_color = spiroMeter.getThirdValue();
double vitalCapacity = Double.parseDouble(vitalCapacityStr);
double age = Double.parseDouble(ageStr);
Intent intent = new Intent(this, AHPActivity.class);
intent.putExtra("TEMPERATURE", temperature);
intent.putExtra("R", red_color);
intent.putExtra("G", green_color);
intent.putExtra("B", blue_color);
intent.putExtra("VC", vitalCapacity);
intent.putExtra("AGE", age);
startActivity(intent);
}
}
C. Monitoring Presenter
package com.example.healthmonitoring.monitoring;
import android.util.Log;
import androidx.annotation.NonNull;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.text.DecimalFormat;
public class MonitoringPresenter { private MonitoringView view;
// format
private static DecimalFormat df2 = new DecimalFormat("#.##");
//
String good_result = "Paru-paru anda sehat!";
String bad_result = "Paru-paru anda tidak sehat";
// firebase configuration
private DatabaseReference mDatabaseRef;
private ValueEventListener mDBListener;
private String node = "device1"; // node name in firebase private String childColor = "color"; // child name
private String childSpiro = "spirometer";
private String temperature;
private String colorR, colorG, colorB;
private String analogSpiro, voltageSpiro;
private double currentTemperature = 0;
private double prevTemperature = 0;
private double vital_capacity = 0;
private double minVoltage = 999;
private double maxVoltage = -999;
private double vcUkur = 0;
// constructor
public MonitoringPresenter(MonitoringView view){
this.view = view;
}
// get temperature from firebase void getTemperature(){
//get firebase reference based on node mDatabaseRef =
FirebaseDatabase.getInstance().getReference(node);
// listener
mDBListener = mDatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
// get value of temperature temperature =
String.valueOf(dataSnapshot.child("temperature").getValue());
// set temparture to view
view.setTemperature(temperature);
// set status temperature
view.setTemperatureStatus(discreteTemperature(Double.parseDouble(tempe rature)));
} }
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.d("firebase-error", "onCancelled: " + databaseError);
} });
}
// get color from firebase void getColor(){
//get firebase reference based on node mDatabaseRef =
FirebaseDatabase.getInstance().getReference(node);
// listener
mDBListener = mDatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
// get value of temperature colorR =
String.valueOf(dataSnapshot.child(childColor).child("R").getValue());
colorG =
String.valueOf(dataSnapshot.child(childColor).child("G").getValue());
colorB =
String.valueOf(dataSnapshot.child(childColor).child("B").getValue());
// set okisgen color to view
view.setColor(colorR, colorG, colorB);
view.setBValue("B : " + colorB);
view.setGValue("G : " + colorG);
view.setRValue("R : " + colorR);
// set oksigen s
view.setNailColor(colorR, colorG, colorB);
} }
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.d("firebase-error", "onCancelled: " + databaseError);
} });
}
// get spirometer from firebase void getSpiroMeter(){
//get firebase reference based on node mDatabaseRef =
FirebaseDatabase.getInstance().getReference(node);
// listener
mDBListener = mDatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
// get value of temperature analogSpiro =
String.valueOf(dataSnapshot.child(childSpiro).child("analog").getValue ());
voltageSpiro =
String.valueOf(dataSnapshot.child(childSpiro).child("voltage").getValu e());
view.setAnalogSpiro(df2.format(Double.parseDouble(analogSpiro)));
view.setVoltageSpiro(df2.format(Double.parseDouble(voltageSpiro)));
// track max, min value Double maxVoltage =
getMaximumVoltage(Double.parseDouble(voltageSpiro));
Double minVoltage =
getMinimumVoltage(Double.parseDouble(voltageSpiro));
view.setVMax(df2.format(maxVoltage));
view.setVMin(df2.format(minVoltage));
// calculate vital capacity
vcUkur= maxVoltage - minVoltage ; view.setVolumeUkur(df2.format(vcUkur));
// decision
if (checkVitalCapacity(vcUkur,vital_capacity)) view.setDecisionSpiro(good_result);
else
view.setDecisionSpiro(bad_result);
} }
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.d("firebase-error", "onCancelled: " + databaseError);
} });
}
// calculate volume estimasion based on physical parameter void calculate_estimated_vital_capacity(int age, int height, String gender){
if(gender.toLowerCase().equals("pria")){
//vital_capacity = (0.051 - 0.112 * age) * height;
vital_capacity = (0.052 * height) - (0.022*age) - 3.00;
} else if (gender.toLowerCase().equals("wanita")){
//vital_capacity = (21.78 -0.101 * age) * height;
vital_capacity = (0.041 * height) - (0.018*age) - 2.69;
}
view.setStandartVolume(df2.format(vital_capacity));
}
// get result decision
private String makeDecision(double temperature, double colorR, double colorG, double colorB){
// example
if( colorB >= 80){