Skip to content

Commit

Permalink
Pattern & Layout modified
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiphago committed Feb 21, 2024
1 parent f9d00b4 commit 5dca042
Show file tree
Hide file tree
Showing 15 changed files with 229 additions and 145 deletions.
6 changes: 6 additions & 0 deletions .idea/compiler.xml

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

10 changes: 10 additions & 0 deletions .idea/deploymentTargetDropDown.xml

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

18 changes: 18 additions & 0 deletions .idea/gradle.xml

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

41 changes: 41 additions & 0 deletions .idea/inspectionProfiles/Project_Default.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.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

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

9 changes: 7 additions & 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 .idea/vcs.xml

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

15 changes: 14 additions & 1 deletion front-end/.idea/deploymentTargetDropDown.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@ import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.example.harmonycare.R
import com.example.harmonycare.databinding.FragmentPieChartBinding
import com.example.harmonycare.retrofit.ApiService
import com.example.harmonycare.retrofit.RecordGetRequest
import com.example.harmonycare.retrofit.RecordGetResponse
import com.example.harmonycare.retrofit.RetrofitClient
import com.github.mikephil.charting.animation.Easing
import com.github.mikephil.charting.charts.PieChart
import com.github.mikephil.charting.data.PieData
import com.github.mikephil.charting.data.PieDataSet
import com.github.mikephil.charting.data.PieEntry
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Locale
import com.example.harmonycare.databinding.FragmentBarChartBinding
import com.github.mikephil.charting.charts.BarChart
import com.github.mikephil.charting.data.BarData
import com.github.mikephil.charting.data.BarDataSet
import com.github.mikephil.charting.data.BarEntry

class BarChartFragment : Fragment() {

private var _binding: FragmentPieChartBinding? = null
private var _binding: FragmentBarChartBinding? = null
private val binding get() = _binding!!
private lateinit var selectedDate: Calendar
private lateinit var sharedPreferences: SharedPreferences

@SuppressLint("MissingInflatedId")
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentPieChartBinding.inflate(inflater, container, false)
_binding = FragmentBarChartBinding.inflate(inflater, container, false)
val root: View = binding.root
//sharedPreference 초기화
sharedPreferences = requireActivity().getSharedPreferences("MyPrefs", Context.MODE_PRIVATE)
Expand Down Expand Up @@ -79,24 +79,29 @@ class BarChartFragment : Fragment() {
datePickerDialog.datePicker.maxDate = System.currentTimeMillis()
datePickerDialog.show()
}

private fun updateSelectedDateButtonText() {
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
val formattedDate = dateFormat.format(selectedDate.time)
binding.button.text = formattedDate
}

private fun fetchRecordsForSelectedDate(authToken: String) {
val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
val formattedDate = dateFormat.format(selectedDate.time)

val apiService = RetrofitClient.createService(ApiService::class.java)
val call = apiService.getRecordsForDay(formattedDate, 1, "Bearer $authToken")
val call = apiService.getRecordsForDay(formattedDate, 7, "Bearer $authToken")

call.enqueue(object : Callback<RecordGetResponse> {
override fun onResponse(call: Call<RecordGetResponse>, response: Response<RecordGetResponse>) {
override fun onResponse(
call: Call<RecordGetResponse>,
response: Response<RecordGetResponse>
) {
if (response.isSuccessful) {
val recordResponse = response.body()
if (recordResponse != null) {
displayRecordsOnPieChart(recordResponse.response)
displayRecordsOnBarChart(recordResponse.response)
} else {
// Handle null response
}
Expand All @@ -111,28 +116,22 @@ class BarChartFragment : Fragment() {
})
}

private fun displayRecordsOnPieChart(recordResponse: List<RecordGetRequest>) {
val mpPieChart: PieChart = _binding!!.pieChart
private fun displayRecordsOnBarChart(recordResponse: List<RecordGetRequest>) {
val mpBarChart: BarChart = _binding!!.barChart

// Clear any existing entries
mpPieChart.clear()
mpPieChart.setUsePercentValues(false) // 퍼센트 값 사용 안 함
mpPieChart.setExtraOffsets(5f, 10f, 5f, 5f)
mpPieChart.legend.isEnabled = false
mpPieChart.description.isEnabled = false
mpPieChart.isDrawHoleEnabled = true
mpPieChart.setHoleColor(Color.WHITE)
mpPieChart.transparentCircleRadius = 61f
mpPieChart.animateY(1000, Easing.EaseInOutCubic)
mpPieChart.centerText = "Day + 3"
mpPieChart.setCenterTextSize(20f)
mpPieChart.invalidate()
mpBarChart.clear()
mpBarChart.setDrawBarShadow(false)
mpBarChart.setDrawValueAboveBar(true)
mpBarChart.description.isEnabled = false
mpBarChart.setPinchZoom(false)
mpBarChart.setDrawGridBackground(false)

// Define the total duration of a day (in minutes)
val totalMinutesInDay = 24 * 60

// Initialize lists to hold entry data
val entries = ArrayList<PieEntry>()
val entries = ArrayList<BarEntry>()
val colors = ArrayList<Int>()

// recordTask에 따른 색상 맵
Expand All @@ -144,15 +143,11 @@ class BarChartFragment : Fragment() {
"BATH" to R.color.bath_orange
)

// Create a list to store occupied time slots
val occupiedTimeSlots = mutableListOf<IntRange>()

// Iterate over the records
var previousEndTime = 0 // 이전 endTime을 추적하기 위한 변수 추가
for (record in recordResponse) {
val startTime = getMinutesFromTimeString(record.startTime)
val endTime = getMinutesFromTimeString(record.endTime)
val timeSlot = startTime until endTime
occupiedTimeSlots.add(timeSlot)

// Get color based on recordTask
val colorResId = taskColorMap[record.recordTask] ?: R.color.dark_gray // Default color if not found
Expand All @@ -161,56 +156,28 @@ class BarChartFragment : Fragment() {
// Add the entry for this record with corresponding color
val duration = endTime - startTime
val percentage = duration.toFloat() / totalMinutesInDay * 100
entries.add(PieEntry(percentage, record.recordTask))
entries.add(BarEntry(startTime.toFloat(), percentage))
colors.add(color)
}

// Find the empty time slots and add them as gray entries
val emptyTimeSlots = findEmptyTimeSlots(occupiedTimeSlots, totalMinutesInDay)
for (emptySlot in emptyTimeSlots) {
val duration = emptySlot.last - emptySlot.first
val percentage = duration.toFloat() / totalMinutesInDay * 100
entries.add(PieEntry(percentage, "Empty"))
colors.add(Color.GRAY)
}

// Configure the data set
val dataSet = PieDataSet(entries, "")
val dataSet = BarDataSet(entries, "")
dataSet.colors = colors
dataSet.valueTextSize = 16f
dataSet.valueTextColor = Color.BLACK
dataSet.barBorderWidth = 1.0f

// Create the PieData object and set it to the chart
val data = PieData(dataSet)
mpPieChart.data = data
// Create the BarData object and set it to the chart
val data = BarData(dataSet)
mpBarChart.data = data

// Refresh the chart
mpPieChart.invalidate()
mpBarChart.invalidate()
}

private fun findEmptyTimeSlots(occupiedTimeSlots: List<IntRange>, totalMinutesInDay: Int): List<IntRange> {
val emptyTimeSlots = mutableListOf<IntRange>()
var previousEndTime = 0

for (occupiedSlot in occupiedTimeSlots) {
if (occupiedSlot.first > previousEndTime) {
val emptySlot = previousEndTime until occupiedSlot.first
emptyTimeSlots.add(emptySlot)
}
previousEndTime = occupiedSlot.last
}

if (previousEndTime < totalMinutesInDay) {
val lastEmptySlot = previousEndTime until totalMinutesInDay
emptyTimeSlots.add(lastEmptySlot)
}

return emptyTimeSlots
}
private fun getMinutesFromTimeString(timeString: String): Int {
val parts = timeString.split(" ")[1].split(":")
return parts[0].toInt() * 60 + parts[1].toInt()
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class PieChartFragment : Fragment() {
val occupiedTimeSlots = mutableListOf<IntRange>()

// Iterate over the records
var previousEndTime = 0 // 이전 endTime을 추적하기 위한 변수 추가
for (record in recordResponse) {
val startTime = getMinutesFromTimeString(record.startTime)
val endTime = getMinutesFromTimeString(record.endTime)
Expand All @@ -160,17 +161,27 @@ class PieChartFragment : Fragment() {

// Add the entry for this record with corresponding color
val duration = endTime - startTime
if (previousEndTime < startTime) {
val emptyDuration = startTime - previousEndTime
val emptyPercentage = emptyDuration.toFloat() / totalMinutesInDay * 100
entries.add(PieEntry(emptyPercentage, "Empty"))
colors.add(Color.GRAY)
}
val percentage = duration.toFloat() / totalMinutesInDay * 100
entries.add(PieEntry(percentage, record.recordTask))
colors.add(color)

// 빈 슬롯 처리


previousEndTime = endTime // 이전 endTime 업데이트
}

// Find the empty time slots and add them as gray entries
val emptyTimeSlots = findEmptyTimeSlots(occupiedTimeSlots, totalMinutesInDay)
for (emptySlot in emptyTimeSlots) {
val duration = emptySlot.last - emptySlot.first
val percentage = duration.toFloat() / totalMinutesInDay * 100
entries.add(PieEntry(percentage, "Empty"))
// 마지막 endTime부터 23:59:59까지 빈 슬롯 추가
if (previousEndTime < totalMinutesInDay) {
val emptyDuration = totalMinutesInDay - previousEndTime
val emptyPercentage = emptyDuration.toFloat() / totalMinutesInDay * 100
entries.add(PieEntry(emptyPercentage, "Empty"))
colors.add(Color.GRAY)
}

Expand Down
Binary file modified front-end/app/src/main/res/drawable/googlelogin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions front-end/app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

<ImageButton
android:id="@+id/GoogleLoginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="350dp"
android:layout_height="75dp"
android:src="@drawable/googlelogin"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
Loading

0 comments on commit 5dca042

Please sign in to comment.