feat: add overdue analytics by sector with swipeable UI in AnalyticsScreen
This commit is contained in:
@@ -9,5 +9,6 @@ data class AnalyticsState(
|
|||||||
val timelineDates: List<Date> = emptyList(),
|
val timelineDates: List<Date> = emptyList(),
|
||||||
val plannedProgressPoints: List<Float> = emptyList(),
|
val plannedProgressPoints: List<Float> = emptyList(),
|
||||||
val realizedProgressPoints: List<Float> = emptyList(),
|
val realizedProgressPoints: List<Float> = emptyList(),
|
||||||
val overdueByTag: List<Pair<String, Int>> = emptyList()
|
val overdueByTag: List<Pair<String, Int>> = emptyList(),
|
||||||
|
val overdueBySector: List<Pair<String, Int>> = emptyList()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,9 +4,13 @@ import androidx.compose.foundation.Canvas
|
|||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.foundation.pager.HorizontalPager
|
||||||
|
import androidx.compose.foundation.pager.rememberPagerState
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
@@ -119,8 +123,8 @@ fun AnalyticsScreen(
|
|||||||
// Card 2: Progresso do Projeto: Planejado vs. Realizado
|
// Card 2: Progresso do Projeto: Planejado vs. Realizado
|
||||||
SCurveCard(analyticsState)
|
SCurveCard(analyticsState)
|
||||||
|
|
||||||
// Card 3: Atrasados por TAG
|
// Card 3: OSs Atrasadas (TAG / Setor alternáveis por swipe)
|
||||||
OverdueByTagCard(analyticsState.overdueByTag)
|
OverdueAnalyticsCard(analyticsState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -361,11 +365,14 @@ fun SCurveCard(analyticsState: AnalyticsState) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gráfico 3: OSs Atrasadas por TAG (Ativo)
|
* Gráfico 3: OSs Atrasadas por TAG e por Setor
|
||||||
* Lista as TAGs com maior volume de OSs pendentes e com prazo vencido
|
* Permite alternar horizontalmente (swipe) entre as duas visualizações.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun OverdueByTagCard(overdueByTag: List<Pair<String, Int>>) {
|
fun OverdueAnalyticsCard(analyticsState: AnalyticsState) {
|
||||||
|
val pagerState = rememberPagerState(pageCount = { 2 })
|
||||||
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
colors = CardDefaults.cardColors(containerColor = Color.White),
|
colors = CardDefaults.cardColors(containerColor = Color.White),
|
||||||
@@ -377,90 +384,140 @@ fun OverdueByTagCard(overdueByTag: List<Pair<String, Int>>) {
|
|||||||
.padding(16.dp)
|
.padding(16.dp)
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Text(
|
// Header with Dynamic Title & Page Indicator Dots
|
||||||
text = "Atrasados por TAG",
|
Row(
|
||||||
fontSize = 16.sp,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = BrandBlack,
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(bottom = 16.dp)
|
.padding(bottom = 16.dp),
|
||||||
)
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = if (pagerState.currentPage == 0) "Atrasados por TAG" else "Atrasados por Setor",
|
||||||
|
fontSize = 16.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = BrandBlack
|
||||||
|
)
|
||||||
|
|
||||||
if (overdueByTag.isEmpty()) {
|
// Page Indicator Dots
|
||||||
Box(
|
Row(
|
||||||
modifier = Modifier
|
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||||
.fillMaxWidth()
|
verticalAlignment = Alignment.CenterVertically
|
||||||
.height(100.dp),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
) {
|
||||||
Text(
|
repeat(2) { index ->
|
||||||
text = "Parabéns! Nenhuma OS atrasada no momento.",
|
val isSelected = pagerState.currentPage == index
|
||||||
color = Color(0xFF2E7D32),
|
Box(
|
||||||
fontWeight = FontWeight.Medium,
|
modifier = Modifier
|
||||||
fontSize = 13.sp
|
.size(if (isSelected) 10.dp else 8.dp)
|
||||||
)
|
.background(
|
||||||
|
color = if (isSelected) BrandGreen else Color.LightGray,
|
||||||
|
shape = CircleShape
|
||||||
|
)
|
||||||
|
.clickable {
|
||||||
|
coroutineScope.launch {
|
||||||
|
pagerState.animateScrollToPage(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
val displayList = overdueByTag
|
|
||||||
val maxCount = displayList.maxOfOrNull { it.second } ?: 1
|
|
||||||
|
|
||||||
Column(
|
HorizontalPager(
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
state = pagerState,
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) { page ->
|
||||||
|
val (items, emptyMsg) = if (page == 0) {
|
||||||
|
analyticsState.overdueByTag to "Parabéns! Nenhuma OS atrasada por TAG no momento."
|
||||||
|
} else {
|
||||||
|
analyticsState.overdueBySector to "Parabéns! Nenhuma OS atrasada por Setor no momento."
|
||||||
|
}
|
||||||
|
|
||||||
|
OverdueBarChartContent(
|
||||||
|
displayList = items,
|
||||||
|
emptyMessage = emptyMsg
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun OverdueBarChartContent(
|
||||||
|
displayList: List<Pair<String, Int>>,
|
||||||
|
emptyMessage: String
|
||||||
|
) {
|
||||||
|
if (displayList.isEmpty()) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(100.dp),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = emptyMessage,
|
||||||
|
color = Color(0xFF2E7D32),
|
||||||
|
fontWeight = FontWeight.Medium,
|
||||||
|
fontSize = 13.sp,
|
||||||
|
textAlign = TextAlign.Center
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val maxCount = displayList.maxOfOrNull { it.second } ?: 1
|
||||||
|
|
||||||
|
Column(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
displayList.forEachIndexed { index, (label, count) ->
|
||||||
|
val barColor = when (index) {
|
||||||
|
0 -> Color(0xFF4CAF50) // Green
|
||||||
|
1 -> Color(0xFF2196F3) // Blue
|
||||||
|
2 -> Color(0xFFFF9800) // Orange
|
||||||
|
3 -> Color(0xFFFFC107) // Amber/Yellow
|
||||||
|
else -> Color(0xFF9C27B0) // Purple
|
||||||
|
}
|
||||||
|
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
displayList.forEachIndexed { index, (tag, count) ->
|
// Label (TAG Name or Sector Name)
|
||||||
val barColor = when (index) {
|
Text(
|
||||||
0 -> Color(0xFF4CAF50) // Green
|
text = label,
|
||||||
1 -> Color(0xFF2196F3) // Blue
|
fontSize = 12.sp,
|
||||||
2 -> Color(0xFFFF9800) // Orange
|
fontWeight = FontWeight.Bold,
|
||||||
3 -> Color(0xFFFFC107) // Amber/Yellow
|
color = BrandBlack,
|
||||||
else -> Color(0xFF9C27B0) // Purple
|
modifier = Modifier.width(90.dp),
|
||||||
}
|
maxLines = 1
|
||||||
|
)
|
||||||
|
|
||||||
Row(
|
// Bar Container
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
Box(
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier
|
||||||
) {
|
.weight(1f)
|
||||||
// TAG Name
|
.height(18.dp)
|
||||||
Text(
|
.background(Color(0xFFEEEEEE), shape = RoundedCornerShape(4.dp))
|
||||||
text = tag,
|
) {
|
||||||
fontSize = 12.sp,
|
Box(
|
||||||
fontWeight = FontWeight.Bold,
|
modifier = Modifier
|
||||||
color = BrandBlack,
|
.fillMaxWidth(count.toFloat() / maxCount.toFloat())
|
||||||
modifier = Modifier.width(90.dp),
|
.fillMaxHeight()
|
||||||
maxLines = 1
|
.background(barColor, shape = RoundedCornerShape(4.dp))
|
||||||
)
|
)
|
||||||
|
|
||||||
// Bar Container
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.height(18.dp)
|
|
||||||
.background(Color(0xFFEEEEEE), shape = RoundedCornerShape(4.dp))
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth(count.toFloat() / maxCount.toFloat())
|
|
||||||
.fillMaxHeight()
|
|
||||||
.background(barColor, shape = RoundedCornerShape(4.dp))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
|
|
||||||
// Count number
|
|
||||||
Text(
|
|
||||||
text = count.toString(),
|
|
||||||
fontSize = 12.sp,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = BrandBlack,
|
|
||||||
modifier = Modifier.width(20.dp),
|
|
||||||
textAlign = TextAlign.End
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
|
||||||
|
// Count number
|
||||||
|
Text(
|
||||||
|
text = count.toString(),
|
||||||
|
fontSize = 12.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = BrandBlack,
|
||||||
|
modifier = Modifier.width(20.dp),
|
||||||
|
textAlign = TextAlign.End
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -557,7 +557,7 @@ class MaintenanceViewModel(private val repository: MaintenanceRepository) : View
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Overdue tags
|
// 3. Overdue tags and sectors
|
||||||
val referenceDate = if (Date().before(projectEnd)) projectEnd else Date()
|
val referenceDate = if (Date().before(projectEnd)) projectEnd else Date()
|
||||||
|
|
||||||
val overdueActivities = activities.filter { act ->
|
val overdueActivities = activities.filter { act ->
|
||||||
@@ -581,6 +581,31 @@ class MaintenanceViewModel(private val repository: MaintenanceRepository) : View
|
|||||||
top + listOf("Outros" to othersCount)
|
top + listOf("Outros" to othersCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val overdueBySectorMap = overdueActivities
|
||||||
|
.groupBy { if (it.setor.isBlank()) "Sem Setor" else it.setor }
|
||||||
|
.mapValues { it.value.size }
|
||||||
|
|
||||||
|
val finalOverdueBySector = if (overdueActivities.isEmpty()) {
|
||||||
|
emptyList()
|
||||||
|
} else {
|
||||||
|
val plantSectors = activities
|
||||||
|
.map { if (it.setor.isBlank()) "Sem Setor" else it.setor }
|
||||||
|
.distinct()
|
||||||
|
|
||||||
|
val fullOverdueBySector = plantSectors
|
||||||
|
.map { sector -> sector to (overdueBySectorMap[sector] ?: 0) }
|
||||||
|
.sortedWith(compareByDescending<Pair<String, Int>> { it.second }.thenBy { it.first })
|
||||||
|
|
||||||
|
val displayLimit = 4
|
||||||
|
if (fullOverdueBySector.size <= displayLimit) {
|
||||||
|
fullOverdueBySector
|
||||||
|
} else {
|
||||||
|
val top = fullOverdueBySector.take(displayLimit - 1)
|
||||||
|
val othersCount = fullOverdueBySector.drop(displayLimit - 1).sumOf { it.second }
|
||||||
|
top + listOf("Outros" to othersCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return AnalyticsState(
|
return AnalyticsState(
|
||||||
teamMetrics = teamMetrics,
|
teamMetrics = teamMetrics,
|
||||||
projectStart = projectStart,
|
projectStart = projectStart,
|
||||||
@@ -588,7 +613,8 @@ class MaintenanceViewModel(private val repository: MaintenanceRepository) : View
|
|||||||
timelineDates = timelineDates,
|
timelineDates = timelineDates,
|
||||||
plannedProgressPoints = plannedProgressPoints,
|
plannedProgressPoints = plannedProgressPoints,
|
||||||
realizedProgressPoints = realizedProgressPoints,
|
realizedProgressPoints = realizedProgressPoints,
|
||||||
overdueByTag = finalOverdueByTag
|
overdueByTag = finalOverdueByTag,
|
||||||
|
overdueBySector = finalOverdueBySector
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import androidx.test.core.app.ApplicationProvider
|
|||||||
import com.example.data.local.AppDatabase
|
import com.example.data.local.AppDatabase
|
||||||
import com.example.data.remote.GoogleSheetsSyncService
|
import com.example.data.remote.GoogleSheetsSyncService
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertNotNull
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.robolectric.RobolectricTestRunner
|
import org.robolectric.RobolectricTestRunner
|
||||||
@@ -252,6 +253,9 @@ class ExampleRobolectricTest {
|
|||||||
// 4. Verify realized progress points has correct count
|
// 4. Verify realized progress points has correct count
|
||||||
assertEquals(5, state.realizedProgressPoints.size)
|
assertEquals(5, state.realizedProgressPoints.size)
|
||||||
|
|
||||||
|
// 5. Verify overdueBySector is present
|
||||||
|
assertNotNull(state.overdueBySector)
|
||||||
|
|
||||||
collectionJob.cancel()
|
collectionJob.cancel()
|
||||||
}
|
}
|
||||||
db.close()
|
db.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user