Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<!-- Activity for graphing data -->
<activity
android:name="com.bae.myapplication.activities.DataGraphViewActivity"
android:screenOrientation="landscape">
android:screenOrientation="landscape" android:parentActivityName=".activities.MenuActivity">
</activity>

<!-- for FileProvider -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public class DataAnalysisActivity extends AppCompatActivity {
private static final int LISTVIEW_TEXTVIEW = R.id.sampleLabel;
private static final int LISTVIEW_SAMPLE_LABEL = R.id.sampleLabel;
private static final int LISTVIEW_RGB_LABEL = R.id.RGBLabel;
private static final int LISTVIEW_RPOINT_LABEL = R.id.RPointLabelTitle;
private static final int LISTVIEW_RPOINTSTD_LABEL = R.id.RPointSTDLabel;
private static final int LISTVIEW_Alpha_LABEL = R.id.AlphaLabel;
private static final int LISTVIEW_RPOINTBeta_LABEL = R.id.BetaLabel;
private static final int LISTVIEW_TRANSFORMEDVALUE_LABEL = R.id.TransformedValueLabel;
private static final int LISTVIEW_COMPARISONVALUE_LABEL = R.id.ComparativeValueLabel;

Expand Down Expand Up @@ -142,11 +142,13 @@ private void setBalloonListeners() {
ImageButton b2 = findViewById(R.id.avgrgbTip2);
ImageButton b3 = findViewById(R.id.avgrgbTip3);
ImageButton b4 = findViewById(R.id.avgrgbTip4);
ImageButton b5 = findViewById(R.id.avgrgbTip5);

b1.setOnClickListener(new avgRGBOnClickListener(b1));
b2.setOnClickListener(new avgRValOnClickListener(b2));
b3.setOnClickListener(new avgRValSTDOnClickListener(b3));
b4.setOnClickListener(new RatioOnClickListener(b4));
b5.setOnClickListener(new snrOnClick(b5));
}

/**
Expand Down Expand Up @@ -193,7 +195,7 @@ public avgRValSTDOnClickListener(ImageButton button) {

@Override
public void onClick(View v) {
balloons.getAvgRValSTDBalloon().showAlignBottom(button);
balloons.getAlphaBalloon().showAlignBottom(button);
}
}

Expand All @@ -213,6 +215,23 @@ public void onClick(View v) {
}
}

/**
* Tooltip listener
*/
private class snrOnClick implements View.OnClickListener {
private ImageButton button;

public snrOnClick(ImageButton button) {
this.button = button;
}

@Override
public void onClick(View v) {
balloons.getSnrBalloon().showAlignBottom(button);
}
}


/**
* Transition to MainActivity to restart the process.
*/
Expand Down Expand Up @@ -275,8 +294,8 @@ public View getView(int position, View convertView, ViewGroup parent) {
DataCaptureModule.Element sampleData = getItem(position);
TextView sampleLabel = convertView.findViewById(LISTVIEW_SAMPLE_LABEL);
TextView RGBLabel = convertView.findViewById(LISTVIEW_RGB_LABEL);
TextView RPointLabel = convertView.findViewById(LISTVIEW_RPOINT_LABEL);
TextView RPointSTDLabel = convertView.findViewById(LISTVIEW_RPOINTSTD_LABEL);
TextView AlphaLabel = convertView.findViewById(LISTVIEW_Alpha_LABEL);
TextView BetaLabel = convertView.findViewById(LISTVIEW_RPOINTBeta_LABEL);
TextView transformedValueLabel = convertView.findViewById(LISTVIEW_TRANSFORMEDVALUE_LABEL);
TextView comparisonValueLabel = convertView.findViewById(LISTVIEW_COMPARISONVALUE_LABEL);

Expand All @@ -288,10 +307,10 @@ public View getView(int position, View convertView, ViewGroup parent) {
sampleLabel.setText("x" + position);
}
RGBLabel.setText(String.format("(%.0f, %.0f, %.0f)", sampleData.getAvgR(), sampleData.getAvgG(), sampleData.getAvgB()));
RPointLabel.setText(String.format("%.2f", sampleData.getRPoint()));
RPointSTDLabel.setText(String.format("%.2E", sampleData.getRPointSTD()));
AlphaLabel.setText(String.format("%.2f", sampleData.getAlpha()));
BetaLabel.setText(String.format("%.2E", sampleData.getBeta()));
transformedValueLabel.setText(String.format("%.2f", sampleData.getTransformedValue()));
comparisonValueLabel.setText(String.format("%.2f", sampleData.getComparativeValue()));
comparisonValueLabel.setText(String.format("%.2f", sampleData.getSnr()));

return convertView;
}
Expand Down Expand Up @@ -353,6 +372,7 @@ public void onClick(View v) {
csvFile);

// send as an intent

Intent exportDataIntent = new Intent(Intent.ACTION_SEND);
exportDataIntent.setType("text/csv");
exportDataIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ public class DataAnalysisBalloons {
// balloons for tooltips
private Balloon avgRGBBalloon;
private Balloon avgRValBalloon;
private Balloon avgRValSTDBalloon;
//private Balloon avgRValSTDBalloon;
private Balloon ratioBalloon;
private Balloon snrBalloon;
private Balloon alphaBalloon;

public DataAnalysisBalloons(AppCompatActivity context)
{
Expand All @@ -27,16 +29,26 @@ public DataAnalysisBalloons(AppCompatActivity context)
.build();

avgRValBalloon = balloonBuilder
.setText(res.getString(R.string.avg_rval))
.setText(res.getString(R.string.alpha))
.build();

avgRValSTDBalloon = balloonBuilder
.setText(res.getString(R.string.avg_rvalstd))
.build();
//avgRValSTDBalloon = balloonBuilder
// .setText(res.getString(R.string.avg_rvalstd))
// .build();

ratioBalloon = balloonBuilder
.setText(res.getString(R.string.ratio))
.build();

// Additions For Alpha and SNR tooltips
alphaBalloon = balloonBuilder
.setText(res.getString(R.string.alpha))
.build();

snrBalloon = balloonBuilder
.setText(res.getString(R.string.snr))
.build();

}

public Balloon getAvgRGBBalloon() {
Expand All @@ -47,11 +59,14 @@ public Balloon getAvgRValBalloon() {
return avgRValBalloon;
}

public Balloon getAvgRValSTDBalloon() {
return avgRValSTDBalloon;
}
// public Balloon getAvgRValSTDBalloon() {
// return avgRValSTDBalloon;
// }

public Balloon getRatioBalloon() {
return ratioBalloon;
}

public Balloon getSnrBalloon() {return snrBalloon;}
public Balloon getAlphaBalloon() {return alphaBalloon;}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ public String saveData()
DataCaptureModule module = new DataCaptureModule();
for (DataProcessor dp : dps)
{
double snr = dp.getBeta()/dps.get(0).getBeta(); // snr = Beta_sample/Beta_control

DataCaptureModule.Element elem = new DataCaptureModule.Element(
dp.getAvgRValue(), dp.getAvgGValue(), dp.getAvgBValue(),
dp.getAvgRPoint(), dp.getRPointSTD(), dp.getComparativeValue(), dp.getTransformedValue());
dp.getAvgRPoint(), dp.getRPointSTD(), dp.getComparativeValue(), dp.getTransformedValue(),
dp.getAlpha(), dp.getBeta(), snr);
module.putElement(elem);
}
return DataStore.primaryDataStore.putModule(module, ActivityTransitions.FROM_DATA_CAPTURE_ACTIVITY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class DataProcessor {
private double comparativeValue;
private double transformedValue;

private double alpha;
private double beta;


public DataProcessor() {
sampleColors = new ArrayList<>();
Expand All @@ -52,6 +55,8 @@ public void addSampleColor(int sampleColor) {
public void start() {
// Calculate rPoints
// Do (r + g) / b
// May be irrelevant due to new algorithm...

for (int i = 0; i < sampleColors.size(); i++) {
int r = Color.red(sampleColors.get(i));
int g = Color.green(sampleColors.get(i));
Expand All @@ -62,7 +67,7 @@ public void start() {
rPoints.add(rPoint);
}

// Calculate r,g,b
// Calculate avg(r,g,b)
for (int i = 0; i < sampleColors.size(); i++) {
int color = sampleColors.get(i);
avg_rval += Color.red(color);
Expand All @@ -74,19 +79,29 @@ public void start() {
avg_gval /= size;
avg_bval /= size;

// May be irrelevant due to new algorithm
// Calculate average R Point
for (Double d : rPoints) {
avg_rpoint += d;
}
avg_rpoint /= rPoints.size();

// May be irrelevant due to new algorithm
// Calculate R Point STD
double mean = getAvgRPoint();
double squaredDiffs = 0;
for (Double d : rPoints) {
squaredDiffs += Math.pow(d - mean, 2);
}
rPointSTD = squaredDiffs / rPoints.size();


// Calculates alpha & beta
for (int i = 0; i < sampleColors.size(); ++i){
int color = sampleColors.get(i);
alpha = (double) avg_rval/avg_gval;
beta = alpha * Math.exp(alpha);
}
}


Expand Down Expand Up @@ -158,4 +173,9 @@ public void setTransformedValue(double val) {
public double getTransformedValue() {
return transformedValue;
}

public double getAlpha(){ return alpha;}

public double getBeta() { return beta;}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ public static class Element implements Serializable
private double comparativeValue;
private double transformedValue;

public Element(double avgR, double avgG, double avgB, double rPoint, double rPointSTD, double comparativeValue, double transformedValue)
private double alpha;
private double beta;
private double snr;

public Element(double avgR, double avgG, double avgB, double rPoint, double rPointSTD,
double comparativeValue, double transformedValue, double alpha, double beta,
double snr)
{
this.avgR = avgR;
this.avgG = avgG;
Expand All @@ -37,6 +43,9 @@ public Element(double avgR, double avgG, double avgB, double rPoint, double rPoi
this.rPointSTD = rPointSTD;
this.comparativeValue = comparativeValue;
this.transformedValue = transformedValue;
this.alpha = alpha;
this.beta = beta;
this.snr = snr;
}

/** Getters */
Expand All @@ -48,14 +57,18 @@ public Element(double avgR, double avgG, double avgB, double rPoint, double rPoi
public double getComparativeValue() { return comparativeValue; }
public double getTransformedValue() { return transformedValue; }

public double getAlpha() {return alpha;}
public double getBeta() {return beta;}
public double getSnr() {return snr;}


public DataCaptureModule getParent() { return parent; }

public void setParent(DataCaptureModule parent) { this.parent = parent; }

}

// Contains the examples. e.g. control, x1, x2, x3, x4
// Contains the samples. e.g. control, x1, x2, x3, x4
private ArrayList<Element> elements = new ArrayList<>();


Expand All @@ -68,6 +81,8 @@ public void putElement(Element elem)
elements.add(elem);
}


// Add beta, alpha, snr to csv file
/**
* @return A raw string that represents the DataSet as a CSV file extension.
*/
Expand All @@ -76,15 +91,15 @@ public String getCSV()
StringBuilder rawCSV = new StringBuilder(new String());

// append column titles
rawCSV.append("avgR,avgG,avgB,rPoint,rPointSTD,TransformedValue,S/N\n");
rawCSV.append("\"avg(R,G,B)\",rPoint,rPointSTD,TransformedValue,Alpha, Beta,SNR\n");

// for each element, append a row
for (Element elem : elements)
{
@SuppressLint("DefaultLocale") String newRow = String.format("%f,%f,%f,%f,%f,%f,%f\n",
@SuppressLint("DefaultLocale") String newRow = String.format("\"(%.0f, %.0f, %.0f)\",%f,%f,%f,%f,%f,%f\n",
elem.getAvgR(), elem.getAvgG(), elem.getAvgB(),
elem.getRPoint(), elem.getRPointSTD(), elem.getTransformedValue(),
elem.getComparativeValue());
elem.getAlpha(), elem.getBeta(), elem.getSnr());
rawCSV.append(newRow);
}

Expand Down
10 changes: 5 additions & 5 deletions app/src/main/res/layout-land/activity_datagraphview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

<Button
android:id="@+id/GraphView_ExitBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="1dp"
android:layout_width="81dp"
android:layout_height="35dp"
android:layout_marginBottom="24dp"
android:text="EXIT"
android:visibility="gone"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/GraphView_Plot" />
app:layout_constraintTop_toBottomOf="@+id/GraphViewAddDataSetsBtn" />

<ImageButton
android:id="@+id/GraphViewAddDataSetsBtn"
Expand Down
Loading