AndroidAPS/app/src/main/java/info/nightscout/androidaps/TDDStatsActivity.java

559 lines
22 KiB
Java
Raw Normal View History

2018-03-15 23:46:34 +01:00
package info.nightscout.androidaps;
2017-01-08 13:01:54 +01:00
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Rect;
2017-01-08 13:01:54 +01:00
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
2017-01-18 04:31:47 +01:00
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.MotionEvent;
2017-01-08 13:01:54 +01:00
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
2017-01-08 13:01:54 +01:00
import android.widget.Button;
2017-01-18 03:08:19 +01:00
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
2017-01-08 13:01:54 +01:00
import android.widget.TextView;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DateFormat;
2017-01-18 03:08:19 +01:00
import java.text.DecimalFormat;
2017-01-08 13:01:54 +01:00
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
2017-01-08 13:01:54 +01:00
import java.util.Date;
import java.util.LinkedList;
2017-01-08 13:01:54 +01:00
import java.util.List;
2017-10-08 14:41:51 +02:00
import info.nightscout.androidaps.data.Profile;
2017-01-08 13:01:54 +01:00
import info.nightscout.androidaps.db.DanaRHistoryRecord;
2018-03-15 23:46:34 +01:00
import info.nightscout.androidaps.db.TDD;
2017-02-19 19:15:14 +01:00
import info.nightscout.androidaps.events.EventPumpStatusChanged;
2018-03-15 23:46:34 +01:00
import info.nightscout.androidaps.interfaces.PumpInterface;
2017-01-08 13:01:54 +01:00
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
2018-03-15 23:46:34 +01:00
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
2017-04-21 12:15:08 +02:00
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.PumpDanaR.events.EventDanaRSyncStatus;
2018-03-15 23:46:34 +01:00
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRS.DanaRSPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
2018-03-26 08:47:44 +02:00
import info.nightscout.androidaps.plugins.PumpInsight.InsightPlugin;
2017-11-21 23:00:53 +01:00
import info.nightscout.androidaps.queue.Callback;
2017-01-08 13:01:54 +01:00
import info.nightscout.utils.DecimalFormatter;
2017-06-02 10:25:49 +02:00
import info.nightscout.utils.SP;
2017-02-09 16:32:44 +01:00
import info.nightscout.utils.SafeParse;
2017-01-08 13:01:54 +01:00
2018-03-15 23:46:34 +01:00
public class TDDStatsActivity extends Activity {
private static Logger log = LoggerFactory.getLogger(TDDStatsActivity.class);
2017-01-08 13:01:54 +01:00
2017-02-19 19:15:14 +01:00
TextView statusView, statsMessage, totalBaseBasal2;
2017-01-18 03:08:19 +01:00
EditText totalBaseBasal;
2017-01-08 13:01:54 +01:00
Button reloadButton;
LinearLayoutManager llm;
2017-02-19 19:15:14 +01:00
TableLayout tl, ctl, etl;
2017-01-18 03:08:19 +01:00
String TBB;
double magicNumber;
DecimalFormat decimalFormat;
2017-01-08 13:01:54 +01:00
2018-03-15 23:46:34 +01:00
List<TDD> historyList = new ArrayList<>();
List<TDD> dummies;
2017-01-08 13:01:54 +01:00
2018-03-15 23:46:34 +01:00
public TDDStatsActivity() {
2017-01-08 13:01:54 +01:00
super();
}
@Override
protected void onResume() {
super.onResume();
MainApp.bus().register(this);
}
@Override
protected void onPause() {
super.onPause();
MainApp.bus().unregister(this);
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
View myView = getCurrentFocus();
2017-02-19 19:15:14 +01:00
if (myView instanceof EditText) {
Rect rect = new Rect();
myView.getGlobalVisibleRect(rect);
2017-02-19 19:15:14 +01:00
if (!rect.contains((int) event.getRawX(), (int) event.getRawY())) {
myView.clearFocus();
}
}
}
2017-02-19 19:15:14 +01:00
return super.dispatchTouchEvent(event);
}
2017-01-08 13:01:54 +01:00
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.danar_statsactivity);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
statusView = (TextView) findViewById(R.id.danar_stats_connection_status);
reloadButton = (Button) findViewById(R.id.danar_statsreload);
2017-01-18 03:08:19 +01:00
totalBaseBasal = (EditText) findViewById(R.id.danar_stats_editTotalBaseBasal);
2017-01-20 03:17:50 +01:00
totalBaseBasal2 = (TextView) findViewById(R.id.danar_stats_editTotalBaseBasal2);
statsMessage = (TextView) findViewById(R.id.danar_stats_Message);
statusView.setVisibility(View.GONE);
statsMessage.setVisibility(View.GONE);
2017-01-20 03:17:50 +01:00
totalBaseBasal2.setEnabled(false);
totalBaseBasal2.setClickable(false);
totalBaseBasal2.setFocusable(false);
totalBaseBasal2.setInputType(0);
2017-01-18 03:08:19 +01:00
decimalFormat = new DecimalFormat("0.000");
llm = new LinearLayoutManager(this);
2017-06-02 10:25:49 +02:00
TBB = SP.getString("TBB", "10.00");
2017-10-08 14:41:51 +02:00
Profile profile = MainApp.getConfigBuilder().getProfile();
if (profile != null) {
double cppTBB = profile.baseBasalSum();
TBB = decimalFormat.format(cppTBB);
SP.putString("TBB", TBB);
}
2017-10-08 14:41:51 +02:00
totalBaseBasal.setText(TBB);
if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().needsManualTDDLoad)
reloadButton.setVisibility(View.GONE);
2017-01-18 03:08:19 +01:00
// stats table
tl = (TableLayout) findViewById(R.id.main_table);
TableRow tr_head = new TableRow(this);
tr_head.setBackgroundColor(Color.DKGRAY);
tr_head.setLayoutParams(new TableLayout.LayoutParams(
2017-02-11 03:46:44 +01:00
TableLayout.LayoutParams.MATCH_PARENT,
2017-01-18 03:08:19 +01:00
TableLayout.LayoutParams.WRAP_CONTENT));
TextView label_date = new TextView(this);
label_date.setText(MainApp.gs(R.string.danar_stats_date));
2017-01-18 03:08:19 +01:00
label_date.setTextColor(Color.WHITE);
tr_head.addView(label_date);
TextView label_basalrate = new TextView(this);
label_basalrate.setText(MainApp.gs(R.string.danar_stats_basalrate));
2017-01-18 03:08:19 +01:00
label_basalrate.setTextColor(Color.WHITE);
tr_head.addView(label_basalrate);
TextView label_bolus = new TextView(this);
label_bolus.setText(MainApp.gs(R.string.danar_stats_bolus));
2017-01-18 03:08:19 +01:00
label_bolus.setTextColor(Color.WHITE);
tr_head.addView(label_bolus);
TextView label_tdd = new TextView(this);
label_tdd.setText(MainApp.gs(R.string.danar_stats_tdd));
2017-01-18 03:08:19 +01:00
label_tdd.setTextColor(Color.WHITE);
tr_head.addView(label_tdd);
TextView label_ratio = new TextView(this);
label_ratio.setText(MainApp.gs(R.string.danar_stats_ratio));
2017-01-18 03:08:19 +01:00
label_ratio.setTextColor(Color.WHITE);
tr_head.addView(label_ratio);
// add stats headers to tables
tl.addView(tr_head, new TableLayout.LayoutParams(
2017-02-11 03:46:44 +01:00
TableLayout.LayoutParams.MATCH_PARENT,
2017-01-18 03:08:19 +01:00
TableLayout.LayoutParams.WRAP_CONTENT));
// cumulative table
ctl = (TableLayout) findViewById(R.id.cumulative_table);
TableRow ctr_head = new TableRow(this);
ctr_head.setBackgroundColor(Color.DKGRAY);
ctr_head.setLayoutParams(new TableLayout.LayoutParams(
2017-02-11 03:46:44 +01:00
TableLayout.LayoutParams.MATCH_PARENT,
2017-01-18 03:08:19 +01:00
TableLayout.LayoutParams.WRAP_CONTENT));
TextView label_cum_amount_days = new TextView(this);
label_cum_amount_days.setText(MainApp.gs(R.string.danar_stats_amount_days));
2017-01-18 03:08:19 +01:00
label_cum_amount_days.setTextColor(Color.WHITE);
ctr_head.addView(label_cum_amount_days);
TextView label_cum_tdd = new TextView(this);
label_cum_tdd.setText(MainApp.gs(R.string.danar_stats_tdd));
2017-01-18 03:08:19 +01:00
label_cum_tdd.setTextColor(Color.WHITE);
ctr_head.addView(label_cum_tdd);
TextView label_cum_ratio = new TextView(this);
label_cum_ratio.setText(MainApp.gs(R.string.danar_stats_ratio));
2017-01-18 03:08:19 +01:00
label_cum_ratio.setTextColor(Color.WHITE);
ctr_head.addView(label_cum_ratio);
// add cummulative headers to tables
ctl.addView(ctr_head, new TableLayout.LayoutParams(
2017-02-11 03:46:44 +01:00
TableLayout.LayoutParams.MATCH_PARENT,
2017-01-18 03:08:19 +01:00
TableLayout.LayoutParams.WRAP_CONTENT));
// expontial table
etl = (TableLayout) findViewById(R.id.expweight_table);
TableRow etr_head = new TableRow(this);
etr_head.setBackgroundColor(Color.DKGRAY);
etr_head.setLayoutParams(new TableLayout.LayoutParams(
2017-02-11 03:46:44 +01:00
TableLayout.LayoutParams.MATCH_PARENT,
2017-01-18 03:08:19 +01:00
TableLayout.LayoutParams.WRAP_CONTENT));
TextView label_exp_weight = new TextView(this);
label_exp_weight.setText(MainApp.gs(R.string.danar_stats_weight));
2017-01-18 03:08:19 +01:00
label_exp_weight.setTextColor(Color.WHITE);
etr_head.addView(label_exp_weight);
TextView label_exp_tdd = new TextView(this);
label_exp_tdd.setText(MainApp.gs(R.string.danar_stats_tdd));
2017-01-18 03:08:19 +01:00
label_exp_tdd.setTextColor(Color.WHITE);
etr_head.addView(label_exp_tdd);
TextView label_exp_ratio = new TextView(this);
label_exp_ratio.setText(MainApp.gs(R.string.danar_stats_ratio));
2017-01-18 03:08:19 +01:00
label_exp_ratio.setTextColor(Color.WHITE);
etr_head.addView(label_exp_ratio);
// add expontial headers to tables
etl.addView(etr_head, new TableLayout.LayoutParams(
2017-02-11 03:46:44 +01:00
TableLayout.LayoutParams.MATCH_PARENT,
2017-01-18 03:08:19 +01:00
TableLayout.LayoutParams.WRAP_CONTENT));
2017-01-08 13:01:54 +01:00
reloadButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
2017-11-21 23:00:53 +01:00
runOnUiThread(new Runnable() {
@Override
public void run() {
reloadButton.setVisibility(View.GONE);
statusView.setVisibility(View.VISIBLE);
statsMessage.setVisibility(View.VISIBLE);
statsMessage.setText(MainApp.gs(R.string.danar_stats_warning_Message));
2017-11-21 23:00:53 +01:00
}
});
2018-03-15 23:46:34 +01:00
ConfigBuilderPlugin.getCommandQueue().loadTDDs( new Callback() {
2017-01-08 13:01:54 +01:00
@Override
public void run() {
2018-03-15 23:46:34 +01:00
loadDataFromDB();
2017-01-08 13:01:54 +01:00
runOnUiThread(new Runnable() {
@Override
public void run() {
reloadButton.setVisibility(View.VISIBLE);
statusView.setVisibility(View.GONE);
2017-01-18 03:08:19 +01:00
statsMessage.setVisibility(View.GONE);
2017-01-08 13:01:54 +01:00
}
});
}
});
}
});
2017-01-18 03:08:19 +01:00
totalBaseBasal.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
2017-02-19 19:15:14 +01:00
if (actionId == EditorInfo.IME_ACTION_DONE) {
totalBaseBasal.clearFocus();
return true;
}
return false;
}
});
totalBaseBasal.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
2017-02-19 19:15:14 +01:00
if (hasFocus) {
totalBaseBasal.getText().clear();
} else {
2017-06-02 10:25:49 +02:00
SP.putString("TBB", totalBaseBasal.getText().toString());
TBB = SP.getString("TBB", "");
2018-03-15 23:46:34 +01:00
loadDataFromDB();
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(totalBaseBasal.getWindowToken(), 0);
}
}
});
2018-03-15 23:46:34 +01:00
loadDataFromDB();
2017-01-08 13:01:54 +01:00
}
2018-03-15 23:46:34 +01:00
private void loadDataFromDB() {
historyList = MainApp.getDbHelper().getTDDs();
2017-05-22 12:52:19 +02:00
//only use newest 10
historyList = historyList.subList(0, Math.min(10, historyList.size()));
//fill single gaps
dummies = new LinkedList();
DateFormat df = new SimpleDateFormat("dd.MM.");
2017-10-08 14:41:51 +02:00
for (int i = 0; i < historyList.size() - 1; i++) {
2018-03-15 23:46:34 +01:00
TDD elem1 = historyList.get(i);
TDD elem2 = historyList.get(i + 1);
if (!df.format(new Date(elem1.date)).equals(df.format(new Date(elem2.date + 25 * 60 * 60 * 1000)))) {
TDD dummy = new TDD();
dummy.date = elem1.date - 24 * 60 * 60 * 1000;
dummy.basal = elem1.basal / 2;
dummy.bolus = elem1.bolus / 2;
dummies.add(dummy);
2018-03-15 23:46:34 +01:00
elem1.basal /= 2;
elem1.bolus /= 2;
}
}
historyList.addAll(dummies);
2018-03-15 23:46:34 +01:00
Collections.sort(historyList, new Comparator<TDD>() {
@Override
2018-03-15 23:46:34 +01:00
public int compare(TDD lhs, TDD rhs) {
return (int) (rhs.date - lhs.date);
}
});
2017-01-08 13:01:54 +01:00
runOnUiThread(new Runnable() {
@Override
public void run() {
2017-01-18 03:08:19 +01:00
cleanTable(tl);
cleanTable(ctl);
cleanTable(etl);
DateFormat df = new SimpleDateFormat("dd.MM.");
2017-01-20 03:17:50 +01:00
2017-02-19 19:15:14 +01:00
if (TextUtils.isEmpty(TBB)) {
totalBaseBasal.setError("Please Enter Total Base Basal");
return;
2017-02-19 19:15:14 +01:00
} else {
2017-02-09 16:32:44 +01:00
magicNumber = SafeParse.stringToDouble(TBB);
}
2017-02-19 19:15:14 +01:00
magicNumber *= 2;
totalBaseBasal2.setText(decimalFormat.format(magicNumber));
2017-01-08 13:01:54 +01:00
int i = 0;
double sum = 0d;
double weighted03 = 0d;
double weighted05 = 0d;
double weighted07 = 0d;
2018-03-19 21:54:32 +01:00
//TDD table
2018-03-15 23:46:34 +01:00
for (TDD record : historyList) {
double tdd = record.getTotal();
2017-01-18 03:08:19 +01:00
// Create the table row
2018-03-15 23:46:34 +01:00
TableRow tr = new TableRow(TDDStatsActivity.this);
2017-02-19 19:15:14 +01:00
if (i % 2 != 0) tr.setBackgroundColor(Color.DKGRAY);
2017-10-08 14:41:51 +02:00
if (dummies.contains(record)) {
tr.setBackgroundColor(Color.argb(125, 255, 0, 0));
}
2017-02-19 19:15:14 +01:00
tr.setId(100 + i);
2017-01-18 03:08:19 +01:00
tr.setLayoutParams(new TableLayout.LayoutParams(
2017-02-11 03:46:44 +01:00
TableLayout.LayoutParams.MATCH_PARENT,
2017-01-18 03:08:19 +01:00
TableLayout.LayoutParams.WRAP_CONTENT));
// Here create the TextView dynamically
2018-03-15 23:46:34 +01:00
TextView labelDATE = new TextView(TDDStatsActivity.this);
2017-02-19 19:15:14 +01:00
labelDATE.setId(200 + i);
2018-03-15 23:46:34 +01:00
labelDATE.setText(df.format(new Date(record.date)));
2017-01-18 03:08:19 +01:00
labelDATE.setTextColor(Color.WHITE);
tr.addView(labelDATE);
2018-03-15 23:46:34 +01:00
TextView labelBASAL = new TextView(TDDStatsActivity.this);
2017-02-19 19:15:14 +01:00
labelBASAL.setId(300 + i);
2018-03-15 23:46:34 +01:00
labelBASAL.setText(DecimalFormatter.to2Decimal(record.basal) + " U");
2017-01-18 03:08:19 +01:00
labelBASAL.setTextColor(Color.WHITE);
tr.addView(labelBASAL);
2018-03-15 23:46:34 +01:00
TextView labelBOLUS = new TextView(TDDStatsActivity.this);
2017-02-19 19:15:14 +01:00
labelBOLUS.setId(400 + i);
2018-03-15 23:46:34 +01:00
labelBOLUS.setText(DecimalFormatter.to2Decimal(record.bolus) + " U");
2017-01-18 03:08:19 +01:00
labelBOLUS.setTextColor(Color.WHITE);
tr.addView(labelBOLUS);
2018-03-15 23:46:34 +01:00
TextView labelTDD = new TextView(TDDStatsActivity.this);
2017-02-19 19:15:14 +01:00
labelTDD.setId(500 + i);
2017-01-18 03:08:19 +01:00
labelTDD.setText(DecimalFormatter.to2Decimal(tdd) + " U");
labelTDD.setTextColor(Color.WHITE);
tr.addView(labelTDD);
2018-03-15 23:46:34 +01:00
TextView labelRATIO = new TextView(TDDStatsActivity.this);
2017-02-19 19:15:14 +01:00
labelRATIO.setId(600 + i);
labelRATIO.setText(Math.round(100 * tdd / magicNumber) + " %");
2017-01-18 03:08:19 +01:00
labelRATIO.setTextColor(Color.WHITE);
tr.addView(labelRATIO);
// add stats rows to tables
tl.addView(tr, new TableLayout.LayoutParams(
2017-02-11 03:46:44 +01:00
TableLayout.LayoutParams.MATCH_PARENT,
2017-01-18 03:08:19 +01:00
TableLayout.LayoutParams.WRAP_CONTENT));
2017-01-08 13:01:54 +01:00
i++;
2018-03-19 21:54:32 +01:00
}
i = 0;
//cumulative TDDs
for (TDD record : historyList) {
if(!historyList.isEmpty() && df.format(new Date(record.date)).equals(df.format(new Date()))) {
//Today should not be included
continue;
}
i++;
sum = sum + record.getTotal();
2017-01-18 03:08:19 +01:00
// Create the cumtable row
2018-03-15 23:46:34 +01:00
TableRow ctr = new TableRow(TDDStatsActivity.this);
2017-02-19 19:15:14 +01:00
if (i % 2 == 0) ctr.setBackgroundColor(Color.DKGRAY);
ctr.setId(700 + i);
2017-01-18 03:08:19 +01:00
ctr.setLayoutParams(new TableLayout.LayoutParams(
2017-02-11 03:46:44 +01:00
TableLayout.LayoutParams.MATCH_PARENT,
2017-01-18 03:08:19 +01:00
TableLayout.LayoutParams.WRAP_CONTENT));
// Here create the TextView dynamically
2018-03-15 23:46:34 +01:00
TextView labelDAYS = new TextView(TDDStatsActivity.this);
2017-02-19 19:15:14 +01:00
labelDAYS.setId(800 + i);
2017-01-18 03:08:19 +01:00
labelDAYS.setText("" + i);
labelDAYS.setTextColor(Color.WHITE);
ctr.addView(labelDAYS);
2018-03-15 23:46:34 +01:00
TextView labelCUMTDD = new TextView(TDDStatsActivity.this);
2017-02-19 19:15:14 +01:00
labelCUMTDD.setId(900 + i);
labelCUMTDD.setText(DecimalFormatter.to2Decimal(sum / i) + " U");
2017-01-18 03:08:19 +01:00
labelCUMTDD.setTextColor(Color.WHITE);
ctr.addView(labelCUMTDD);
2018-03-15 23:46:34 +01:00
TextView labelCUMRATIO = new TextView(TDDStatsActivity.this);
2017-02-19 19:15:14 +01:00
labelCUMRATIO.setId(1000 + i);
labelCUMRATIO.setText(Math.round(100 * sum / i / magicNumber) + " %");
2017-01-18 03:08:19 +01:00
labelCUMRATIO.setTextColor(Color.WHITE);
ctr.addView(labelCUMRATIO);
// add cummulative rows to tables
ctl.addView(ctr, new TableLayout.LayoutParams(
2017-02-11 03:46:44 +01:00
TableLayout.LayoutParams.MATCH_PARENT,
2017-01-18 03:08:19 +01:00
TableLayout.LayoutParams.WRAP_CONTENT));
2017-01-08 13:01:54 +01:00
}
if (isOldData(historyList) && ConfigBuilderPlugin.getActivePump().getPumpDescription().needsManualTDDLoad) {
2017-01-18 03:08:19 +01:00
statsMessage.setVisibility(View.VISIBLE);
statsMessage.setText(MainApp.gs(R.string.danar_stats_olddata_Message));
2017-01-18 03:08:19 +01:00
2017-01-08 13:01:54 +01:00
} else {
2017-01-18 03:08:19 +01:00
tl.setBackgroundColor(Color.TRANSPARENT);
2017-01-08 13:01:54 +01:00
}
2018-03-19 21:54:32 +01:00
if(!historyList.isEmpty() && df.format(new Date(historyList.get(0).date)).equals(df.format(new Date()))) {
2018-03-15 23:46:34 +01:00
//Today should not be included
historyList.remove(0);
}
2017-01-08 13:01:54 +01:00
Collections.reverse(historyList);
i = 0;
2017-01-18 03:08:19 +01:00
2018-03-15 23:46:34 +01:00
for (TDD record : historyList) {
double tdd = record.getTotal();
2017-02-19 19:15:14 +01:00
if (i == 0) {
2017-01-08 13:01:54 +01:00
weighted03 = tdd;
weighted05 = tdd;
weighted07 = tdd;
} else {
2017-02-19 19:15:14 +01:00
weighted07 = (weighted07 * 0.3 + tdd * 0.7);
weighted05 = (weighted05 * 0.5 + tdd * 0.5);
weighted03 = (weighted03 * 0.7 + tdd * 0.3);
2017-01-08 13:01:54 +01:00
}
i++;
}
2017-01-18 03:08:19 +01:00
// Create the exptable row
2018-03-15 23:46:34 +01:00
TableRow etr = new TableRow(TDDStatsActivity.this);
2017-02-19 19:15:14 +01:00
if (i % 2 != 0) etr.setBackgroundColor(Color.DKGRAY);
etr.setId(1100 + i);
2017-01-18 03:08:19 +01:00
etr.setLayoutParams(new TableLayout.LayoutParams(
2017-02-11 03:46:44 +01:00
TableLayout.LayoutParams.MATCH_PARENT,
2017-01-18 03:08:19 +01:00
TableLayout.LayoutParams.WRAP_CONTENT));
// Here create the TextView dynamically
2018-03-15 23:46:34 +01:00
TextView labelWEIGHT = new TextView(TDDStatsActivity.this);
2017-02-19 19:15:14 +01:00
labelWEIGHT.setId(1200 + i);
2017-01-18 03:08:19 +01:00
labelWEIGHT.setText("0.3\n" + "0.5\n" + "0.7");
labelWEIGHT.setTextColor(Color.WHITE);
etr.addView(labelWEIGHT);
2018-03-15 23:46:34 +01:00
TextView labelEXPTDD = new TextView(TDDStatsActivity.this);
2017-02-19 19:15:14 +01:00
labelEXPTDD.setId(1300 + i);
2017-01-18 03:08:19 +01:00
labelEXPTDD.setText(DecimalFormatter.to2Decimal(weighted03)
+ " U\n" + DecimalFormatter.to2Decimal(weighted05)
+ " U\n" + DecimalFormatter.to2Decimal(weighted07) + " U");
labelEXPTDD.setTextColor(Color.WHITE);
etr.addView(labelEXPTDD);
2018-03-15 23:46:34 +01:00
TextView labelEXPRATIO = new TextView(TDDStatsActivity.this);
2017-02-19 19:15:14 +01:00
labelEXPRATIO.setId(1400 + i);
labelEXPRATIO.setText(Math.round(100 * weighted03 / magicNumber) + " %\n"
+ Math.round(100 * weighted05 / magicNumber) + " %\n"
+ Math.round(100 * weighted07 / magicNumber) + " %");
2017-01-18 03:08:19 +01:00
labelEXPRATIO.setTextColor(Color.WHITE);
etr.addView(labelEXPRATIO);
// add exponentail rows to tables
etl.addView(etr, new TableLayout.LayoutParams(
2017-02-11 03:46:44 +01:00
TableLayout.LayoutParams.MATCH_PARENT,
2017-01-18 03:08:19 +01:00
TableLayout.LayoutParams.WRAP_CONTENT));
2017-01-08 13:01:54 +01:00
}
});
}
2017-01-18 03:08:19 +01:00
private void cleanTable(TableLayout table) {
int childCount = table.getChildCount();
// Remove all rows except the first one
if (childCount > 1) {
table.removeViews(1, childCount - 1);
}
}
2017-01-08 13:01:54 +01:00
@Subscribe
public void onStatusEvent(final EventDanaRSyncStatus s) {
log.debug("EventDanaRSyncStatus: " + s.message);
runOnUiThread(
new Runnable() {
@Override
public void run() {
statusView.setText(s.message);
}
});
}
@Subscribe
2017-02-19 19:15:14 +01:00
public void onStatusEvent(final EventPumpStatusChanged c) {
2017-01-08 13:01:54 +01:00
runOnUiThread(
new Runnable() {
@Override
public void run() {
2017-02-19 19:15:14 +01:00
statusView.setText(c.textStatus());
2017-01-08 13:01:54 +01:00
}
}
);
}
2018-03-15 23:46:34 +01:00
public static boolean isOldData(List<TDD> historyList) {
Object activePump = MainApp.getConfigBuilder().getActivePump();
PumpInterface dana = MainApp.getSpecificPlugin(DanaRPlugin.class);
PumpInterface danaRS = MainApp.getSpecificPlugin(DanaRSPlugin.class);
PumpInterface danaV2 = MainApp.getSpecificPlugin(DanaRv2Plugin.class);
PumpInterface danaKorean = MainApp.getSpecificPlugin(DanaRKoreanPlugin.class);
2018-03-26 08:47:44 +02:00
PumpInterface insight = MainApp.getSpecificPlugin(InsightPlugin.class);
2018-03-15 23:46:34 +01:00
boolean startsYesterday = activePump == dana || activePump == danaRS || activePump == danaV2 || activePump == danaKorean || activePump == insight;
DateFormat df = new SimpleDateFormat("dd.MM.");
return (historyList.size() < 3 || !(df.format(new Date(historyList.get(0).date)).equals(df.format(new Date(System.currentTimeMillis() - (startsYesterday?1000 * 60 * 60 * 24:0))))));
}
2017-01-08 13:01:54 +01:00
}