GyuhoLee

[Add] Report, DB Connect

...@@ -35,7 +35,10 @@ dependencies { ...@@ -35,7 +35,10 @@ dependencies {
35 implementation 'org.tensorflow:tensorflow-lite:2.2.0' 35 implementation 'org.tensorflow:tensorflow-lite:2.2.0'
36 implementation 'org.tensorflow:tensorflow-lite-gpu:2.2.0' 36 implementation 'org.tensorflow:tensorflow-lite-gpu:2.2.0'
37 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 37 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
38 + implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2'
38 } 39 }
39 repositories { 40 repositories {
40 mavenCentral() 41 mavenCentral()
42 + maven { url "https://jitpack.io" }
43 +
41 } 44 }
......
1 +package com.khuhacker.pocketgym;
2 +
3 +import android.database.Cursor;
4 +import android.database.sqlite.SQLiteDatabase;
5 +import android.util.Log;
6 +
7 +import com.github.mikephil.charting.components.AxisBase;
8 +import com.github.mikephil.charting.formatter.IAxisValueFormatter;
9 +
10 +import java.sql.Date;
11 +import java.text.SimpleDateFormat;
12 +
13 +public class ChartXValueFormatter implements IAxisValueFormatter {
14 + private String[] mValues;
15 +
16 + ChartXValueFormatter(){
17 + mValues = new String[8];
18 + long day = 3600000 * 24;
19 + SQLiteDatabase db;
20 + String sql;
21 + for(int i = 0; i < 7; i++) {
22 + long now = System.currentTimeMillis() - (day * i);
23 + Date date = new Date(now);
24 + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
25 + String getTime = sdf.format(date);
26 + mValues[7 - i] = getTime.charAt(4) + ""+ getTime.charAt(5) + "/" + getTime.charAt(6) + getTime.charAt(7);
27 + }
28 + }
29 +
30 + @Override
31 + public String getFormattedValue(float value, AxisBase axis){
32 + return mValues[(int)value];
33 + }
34 +}
...@@ -311,6 +311,7 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder ...@@ -311,6 +311,7 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder
311 SQLiteDatabase db = dbHelper.getReadableDatabase(); 311 SQLiteDatabase db = dbHelper.getReadableDatabase();
312 String sql = "SELECT pushup FROM reports WHERE date=" + getTime + ";"; 312 String sql = "SELECT pushup FROM reports WHERE date=" + getTime + ";";
313 Cursor cs = db.rawQuery(sql, null); 313 Cursor cs = db.rawQuery(sql, null);
314 + cs.moveToNext();
314 int before = cs.getInt(0); 315 int before = cs.getInt(0);
315 316
316 db = dbHelper.getWritableDatabase(); 317 db = dbHelper.getWritableDatabase();
......
1 package com.khuhacker.pocketgym; 1 package com.khuhacker.pocketgym;
2 2
3 +import android.database.Cursor;
3 import android.database.sqlite.SQLiteDatabase; 4 import android.database.sqlite.SQLiteDatabase;
5 +import android.graphics.Color;
4 import android.os.Bundle; 6 import android.os.Bundle;
5 import android.util.Log; 7 import android.util.Log;
8 +import android.widget.TextView;
9 +
6 10
7 import androidx.appcompat.app.AppCompatActivity; 11 import androidx.appcompat.app.AppCompatActivity;
8 12
13 +import com.github.mikephil.charting.animation.Easing;
14 +import com.github.mikephil.charting.charts.LineChart;
15 +import com.github.mikephil.charting.components.Description;
16 +import com.github.mikephil.charting.components.XAxis;
17 +import com.github.mikephil.charting.components.YAxis;
18 +import com.github.mikephil.charting.data.Entry;
19 +import com.github.mikephil.charting.data.LineData;
20 +import com.github.mikephil.charting.data.LineDataSet;
21 +
9 import java.sql.Date; 22 import java.sql.Date;
10 import java.text.SimpleDateFormat; 23 import java.text.SimpleDateFormat;
24 +import java.util.ArrayList;
25 +import java.util.List;
26 +
11 27
12 public class ReportActivity extends AppCompatActivity { 28 public class ReportActivity extends AppCompatActivity {
13 29
30 + private LineChart lineChart;
31 +
14 @Override 32 @Override
15 protected void onCreate(Bundle savedInstanceState) { 33 protected void onCreate(Bundle savedInstanceState) {
16 super.onCreate(savedInstanceState); 34 super.onCreate(savedInstanceState);
17 - setContentView(R.layout.activity_choice); 35 + setContentView(R.layout.activity_report);
36 +
37 + DBHelper dbHelper = new DBHelper(this, "reports.db", null, 1);
38 + long now = System.currentTimeMillis();
39 + Date date = new Date(now);
40 + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
41 + String getTime = sdf.format(date);
42 + SQLiteDatabase db = dbHelper.getReadableDatabase();
43 + String sql = "SELECT * FROM reports WHERE date=" + getTime + ";";
44 + Cursor cs = db.rawQuery(sql, null);
45 + cs.moveToNext();
46 + int pushupCnt = cs.getInt(0);
47 + int squatCnt = cs.getInt(1);
48 + TextView sport = (TextView)findViewById(R.id.sport);
49 + sport.setText(String.valueOf(pushupCnt + squatCnt) + " 회");
50 + TextView caloriy = (TextView)findViewById(R.id.caloriy);
51 + caloriy.setText(String.valueOf((int)(0.25f * pushupCnt + 0.41f * squatCnt)) + " kcal");
52 + TextView clock = (TextView)findViewById(R.id.clock);
53 + clock.setText(String.valueOf((int)(0.05f * pushupCnt + 0.1f * squatCnt)) + " 분");
54 +
55 +
56 + lineChart = (LineChart)findViewById(R.id.chart);
57 + List<Entry> entries = new ArrayList<>();
58 + long day = 3600000 * 24;
59 + for(int i = 6; i >= 0; i--) {
60 + now = System.currentTimeMillis() - (day * i);
61 + date = new Date(now);
62 + sdf = new SimpleDateFormat("yyyyMMdd");
63 + getTime = sdf.format(date);
64 + db = dbHelper.getReadableDatabase();
65 + sql = "SELECT * FROM reports WHERE date=" + getTime + ";";
66 + cs = db.rawQuery(sql, null);
67 + cs.moveToNext();
68 + entries.add(new Entry(7 - i, cs.getFloat(0) + cs.getFloat(1)));
69 + }
70 +
71 + LineDataSet lineDataSet = new LineDataSet(entries, "횟수");
72 + lineDataSet.setLineWidth(2);
73 + lineDataSet.setCircleRadius(5);
74 + lineDataSet.setCircleColor(R.color.pacific);
75 + lineDataSet.setColor(R.color.pacific);
76 + lineDataSet.setDrawCircles(true);
77 + lineDataSet.setDrawHorizontalHighlightIndicator(false);
78 + lineDataSet.setDrawHighlightIndicators(true);
79 + lineDataSet.setDrawValues(true);
80 +
81 + LineData lineData = new LineData(lineDataSet);
82 + lineChart.setData(lineData);
83 +
84 + XAxis xAxis = lineChart.getXAxis();
85 + xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
86 + xAxis.setTextSize(11f);
87 + xAxis.setTextColor(Color.BLACK);
88 + xAxis.setLabelCount(7, true);
89 + xAxis.setDrawGridLines(false);
90 + xAxis.setValueFormatter(new ChartXValueFormatter());
91 +
92 +
93 + YAxis yLAxis = lineChart.getAxisLeft();
94 + yLAxis.setTextColor(Color.BLACK);
95 + yLAxis.setAxisMinimum(0f);
96 + yLAxis.setTextSize(15f);
97 + YAxis yRAxis = lineChart.getAxisRight();
98 + yRAxis.setDrawLabels(false);
99 + yRAxis.setDrawAxisLine(false);
100 + yRAxis.setDrawGridLines(false);
101 +
102 + Description description = new Description();
103 + description.setText("");
104 +
105 + lineChart.setVisibleXRangeMinimum(7);
106 + lineChart.setDoubleTapToZoomEnabled(false);
107 + lineChart.setDrawGridBackground(false);
108 + lineChart.setDescription(description);
109 + lineChart.animateY(2000, Easing.EasingOption.EaseInCubic);
110 + lineChart.invalidate();
18 } 111 }
19 112
20 } 113 }
......
1 +<?xml version="1.0" encoding="utf-8"?>
2 +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 + android:layout_width="match_parent"
4 + android:layout_height="match_parent"
5 + android:background="#FFFFFF"
6 + android:orientation="vertical">
7 +
8 + <TextView
9 + android:layout_width="wrap_content"
10 + android:layout_height="wrap_content"
11 + android:text="오늘의 운동"
12 + android:layout_gravity="center"
13 + android:textSize="40dp"
14 + android:layout_marginTop="30dp"/>
15 + <LinearLayout
16 + android:layout_width="match_parent"
17 + android:layout_height="130dp"
18 + android:layout_gravity="center"
19 + android:orientation="horizontal"
20 + android:layout_margin="10dp"
21 + android:layout_marginBottom="50dp">
22 +
23 + <LinearLayout
24 + android:layout_width="130dp"
25 + android:layout_height="match_parent"
26 + android:layout_gravity="center"
27 + android:background="@drawable/stroke_main"
28 + android:orientation="vertical"
29 + android:padding="15dp">
30 + <ImageView
31 + android:layout_width="70dp"
32 + android:layout_height="70dp"
33 + android:layout_gravity="center"
34 + android:src="@drawable/sport_icon" />
35 + <TextView
36 + android:id="@+id/sport"
37 + android:layout_width="wrap_content"
38 + android:layout_height="wrap_content"
39 + android:layout_gravity="center"
40 + android:text="1 회"
41 + android:textColor="@color/pacific"
42 + android:textSize="60px"
43 + android:textStyle="bold"/>
44 + </LinearLayout>
45 +
46 + <LinearLayout
47 + android:layout_width="130dp"
48 + android:layout_height="match_parent"
49 + android:layout_gravity="center"
50 + android:background="@drawable/stroke_main"
51 + android:orientation="vertical"
52 + android:padding="15dp">
53 + <ImageView
54 + android:layout_width="70dp"
55 + android:layout_height="70dp"
56 + android:layout_gravity="center"
57 + android:src="@drawable/caloriy_icon" />
58 + <TextView
59 + android:id="@+id/caloriy"
60 + android:layout_width="wrap_content"
61 + android:layout_height="wrap_content"
62 + android:layout_gravity="center"
63 + android:text="100 kcal"
64 + android:textColor="@color/pacific"
65 + android:textSize="60px"
66 + android:textStyle="bold"/>
67 + </LinearLayout>
68 +
69 + <LinearLayout
70 + android:layout_width="130dp"
71 + android:layout_height="match_parent"
72 + android:layout_gravity="center"
73 + android:background="@drawable/stroke_main"
74 + android:orientation="vertical"
75 + android:padding="15dp">
76 + <ImageView
77 + android:layout_width="60dp"
78 + android:layout_height="70dp"
79 + android:layout_gravity="center"
80 + android:src="@drawable/clock_icon" />
81 + <TextView
82 + android:id="@+id/clock"
83 + android:layout_width="wrap_content"
84 + android:layout_height="wrap_content"
85 + android:layout_gravity="center"
86 + android:text="30 분"
87 + android:textColor="@color/pacific"
88 + android:textSize="60px"
89 + android:textStyle="bold"/>
90 + </LinearLayout>
91 + </LinearLayout>
92 +
93 + <com.github.mikephil.charting.charts.LineChart
94 + android:id="@+id/chart"
95 + android:layout_width="match_parent"
96 + android:layout_height="match_parent" />
97 +
98 +</LinearLayout>
...\ No newline at end of file ...\ No newline at end of file
...@@ -5,7 +5,6 @@ buildscript { ...@@ -5,7 +5,6 @@ buildscript {
5 repositories { 5 repositories {
6 google() 6 google()
7 jcenter() 7 jcenter()
8 -
9 } 8 }
10 dependencies { 9 dependencies {
11 classpath 'com.android.tools.build:gradle:3.6.3' 10 classpath 'com.android.tools.build:gradle:3.6.3'
......