Compare commits
5 Commits
2b6ec33837
...
7bd134ed8d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7bd134ed8d | ||
|
|
a0a541e387 | ||
|
|
654e1754ab | ||
|
|
7a5784831c | ||
|
|
94c863484c |
@@ -9,7 +9,7 @@ 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, Double>> = emptyList(),
|
||||||
val overdueBySector: List<Pair<String, Int>> = emptyList(),
|
val overdueBySector: List<Pair<String, Double>> = emptyList(),
|
||||||
val selectedSetorSCurve: String = "Todos"
|
val selectedSetorSCurve: String = "Todos"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -39,6 +39,20 @@ data class MaintenanceActivity(
|
|||||||
else -> ActivityStatus.EM_ANDAMENTO
|
else -> ActivityStatus.EM_ANDAMENTO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val formattedHoras: String
|
||||||
|
get() {
|
||||||
|
val hrs = duracaoHorasCalculada
|
||||||
|
return if (hrs <= 0.0) "0h"
|
||||||
|
else if (hrs % 1.0 == 0.0) "${hrs.toInt()}h"
|
||||||
|
else "${hrs}h"
|
||||||
|
}
|
||||||
|
|
||||||
|
val formattedDescricao: String
|
||||||
|
get() {
|
||||||
|
val prefix = "$formattedHoras - "
|
||||||
|
return if (descricao.startsWith(prefix)) descricao else "$prefix$descricao"
|
||||||
|
}
|
||||||
|
|
||||||
@delegate:Transient
|
@delegate:Transient
|
||||||
val dataInicioMillis: Long by lazy {
|
val dataInicioMillis: Long by lazy {
|
||||||
(parseFullDateTime(dataInicio) ?: parseDateOnly(dataInicio))?.time ?: 0L
|
(parseFullDateTime(dataInicio) ?: parseDateOnly(dataInicio))?.time ?: 0L
|
||||||
|
|||||||
@@ -77,9 +77,21 @@ fun AnalyticsScreen(
|
|||||||
val currentUser by viewModel.currentUser.collectAsStateWithLifecycle()
|
val currentUser by viewModel.currentUser.collectAsStateWithLifecycle()
|
||||||
val userAccessLevel by viewModel.userAccessLevel.collectAsStateWithLifecycle()
|
val userAccessLevel by viewModel.userAccessLevel.collectAsStateWithLifecycle()
|
||||||
val allHistory by viewModel.allHistoryState.collectAsStateWithLifecycle()
|
val allHistory by viewModel.allHistoryState.collectAsStateWithLifecycle()
|
||||||
|
val simulationConfig by viewModel.simulationConfig.collectAsStateWithLifecycle()
|
||||||
|
val selectedActivity by viewModel.selectedActivity.collectAsStateWithLifecycle()
|
||||||
|
val selectedActivityHistory by viewModel.selectedActivityHistory.collectAsStateWithLifecycle()
|
||||||
|
val selectedActivityFindings by viewModel.selectedActivityFindings.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
|
val referenceDate = remember(simulationConfig) {
|
||||||
|
val simMillis = simulationConfig.simulatedDateMillis
|
||||||
|
if (simulationConfig.isActive && simMillis != null) {
|
||||||
|
Date(simMillis)
|
||||||
|
} else {
|
||||||
|
Date()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var selectedOverdueGroup by remember { mutableStateOf<SelectedOverdueGroup?>(null) }
|
var selectedOverdueGroup by remember { mutableStateOf<SelectedOverdueGroup?>(null) }
|
||||||
var selectedActivityToEdit by remember { mutableStateOf<MaintenanceActivity?>(null) }
|
|
||||||
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
@@ -178,6 +190,12 @@ fun AnalyticsScreen(
|
|||||||
.padding(16.dp),
|
.padding(16.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
) {
|
) {
|
||||||
|
// Banner de Alerta de Simulação de Data
|
||||||
|
SimulationAlertBanner(
|
||||||
|
simulationConfig = simulationConfig,
|
||||||
|
onDismiss = { viewModel.clearDateSimulation() }
|
||||||
|
)
|
||||||
|
|
||||||
if (activities.isEmpty()) {
|
if (activities.isEmpty()) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -217,34 +235,35 @@ fun AnalyticsScreen(
|
|||||||
|
|
||||||
// Modal 1: Listagem das OSs Atrasadas por Grupo (TAG ou Setor)
|
// Modal 1: Listagem das OSs Atrasadas por Grupo (TAG ou Setor)
|
||||||
selectedOverdueGroup?.let { group ->
|
selectedOverdueGroup?.let { group ->
|
||||||
val topSectors = analyticsState.overdueBySector.take(3).map { it.first }
|
val topSectors = analyticsState.overdueBySector.map { it.first }
|
||||||
|
val topTags = analyticsState.overdueByTag.take(9).map { it.first }
|
||||||
OverdueActivitiesListModal(
|
OverdueActivitiesListModal(
|
||||||
group = group,
|
group = group,
|
||||||
allActivities = activities,
|
allActivities = activities,
|
||||||
projectEnd = analyticsState.projectEnd,
|
projectEnd = analyticsState.projectEnd,
|
||||||
topSectors = topSectors,
|
topSectors = topSectors,
|
||||||
|
topTags = topTags,
|
||||||
|
referenceDate = referenceDate,
|
||||||
onDismiss = { selectedOverdueGroup = null },
|
onDismiss = { selectedOverdueGroup = null },
|
||||||
onActivityClick = { activity ->
|
onActivityClick = { activity ->
|
||||||
selectedOverdueGroup = null
|
selectedOverdueGroup = null
|
||||||
selectedActivityToEdit = activity
|
viewModel.selectActivity(activity)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modal 2: Edição da OS Selecionada
|
// Modal 2: Edição da OS Selecionada
|
||||||
selectedActivityToEdit?.let { activity ->
|
if (selectedActivity != null) {
|
||||||
val history = remember(allHistory, activity) {
|
|
||||||
allHistory.filter { it.numeroOs == activity.numeroOs }
|
|
||||||
}
|
|
||||||
EditActivityBottomSheet(
|
EditActivityBottomSheet(
|
||||||
activity = activity,
|
activity = selectedActivity!!,
|
||||||
history = history,
|
history = selectedActivityHistory,
|
||||||
|
findings = selectedActivityFindings,
|
||||||
currentUser = currentUser,
|
currentUser = currentUser,
|
||||||
userAccessLevel = userAccessLevel,
|
userAccessLevel = userAccessLevel,
|
||||||
onDismiss = { selectedActivityToEdit = null },
|
onDismiss = { viewModel.selectActivity(null) },
|
||||||
onUpdateProgress = { newPercentual, observation, photoPath ->
|
onUpdateProgress = { newPercentual, observation, photoPath ->
|
||||||
viewModel.updateProgress(
|
viewModel.updateProgress(
|
||||||
numeroOs = activity.numeroOs,
|
numeroOs = selectedActivity!!.numeroOs,
|
||||||
novoPercentual = newPercentual,
|
novoPercentual = newPercentual,
|
||||||
observacao = observation,
|
observacao = observation,
|
||||||
fotoPath = photoPath,
|
fotoPath = photoPath,
|
||||||
@@ -252,14 +271,23 @@ fun AnalyticsScreen(
|
|||||||
emailEditor = currentUser?.email
|
emailEditor = currentUser?.email
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
onAddFinding = { tipo, desc ->
|
||||||
|
viewModel.addFinding(selectedActivity!!.numeroOs, tipo, desc)
|
||||||
|
},
|
||||||
|
onUpdateFinding = { finding ->
|
||||||
|
viewModel.updateFinding(finding)
|
||||||
|
},
|
||||||
|
onDeleteFinding = { finding ->
|
||||||
|
viewModel.deleteFinding(finding)
|
||||||
|
},
|
||||||
onSavePhotoFromUri = { uri ->
|
onSavePhotoFromUri = { uri ->
|
||||||
viewModel.saveLocalPhotoFromUri(uri, activity.numeroOs)
|
viewModel.saveLocalPhotoFromUri(uri, selectedActivity!!.numeroOs)
|
||||||
},
|
},
|
||||||
onCreateCameraUri = {
|
onCreateCameraUri = {
|
||||||
viewModel.createTempCameraPhotoUri(activity.numeroOs)
|
viewModel.createTempCameraPhotoUri(selectedActivity!!.numeroOs)
|
||||||
},
|
},
|
||||||
onSoftDeletePhoto = { path ->
|
onSoftDeletePhoto = { path ->
|
||||||
viewModel.softDeletePhoto(path, activity.numeroOs)
|
viewModel.softDeletePhoto(path, selectedActivity!!.numeroOs)
|
||||||
},
|
},
|
||||||
onGoogleLoginClick = {
|
onGoogleLoginClick = {
|
||||||
googleSignInLauncher.launch(googleSignInClient.signInIntent)
|
googleSignInLauncher.launch(googleSignInClient.signInIntent)
|
||||||
@@ -623,7 +651,7 @@ fun OverdueAnalyticsCard(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun OverdueBarChartContent(
|
private fun OverdueBarChartContent(
|
||||||
displayList: List<Pair<String, Int>>,
|
displayList: List<Pair<String, Double>>,
|
||||||
emptyMessage: String,
|
emptyMessage: String,
|
||||||
onItemClick: (String) -> Unit = {}
|
onItemClick: (String) -> Unit = {}
|
||||||
) {
|
) {
|
||||||
@@ -643,7 +671,7 @@ private fun OverdueBarChartContent(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val maxCount = displayList.maxOfOrNull { it.second } ?: 1
|
val maxCount = displayList.maxOfOrNull { it.second } ?: 1.0
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
@@ -658,6 +686,11 @@ private fun OverdueBarChartContent(
|
|||||||
else -> Color(0xFF9C27B0) // Purple
|
else -> Color(0xFF9C27B0) // Purple
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val fillRatio = if (maxCount > 0) (count / maxCount).toFloat().coerceIn(0f, 1f) else 0f
|
||||||
|
val formattedHours = if (count <= 0.0) "0h"
|
||||||
|
else if (count % 1.0 == 0.0) "${count.toInt()}h"
|
||||||
|
else String.format(java.util.Locale.US, "%.1fh", count)
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -684,7 +717,7 @@ private fun OverdueBarChartContent(
|
|||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth(count.toFloat() / maxCount.toFloat())
|
.fillMaxWidth(fillRatio)
|
||||||
.fillMaxHeight()
|
.fillMaxHeight()
|
||||||
.background(barColor, shape = RoundedCornerShape(4.dp))
|
.background(barColor, shape = RoundedCornerShape(4.dp))
|
||||||
)
|
)
|
||||||
@@ -692,13 +725,13 @@ private fun OverdueBarChartContent(
|
|||||||
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
|
||||||
// Count number
|
// Count number formatted in hours
|
||||||
Text(
|
Text(
|
||||||
text = count.toString(),
|
text = formattedHours,
|
||||||
fontSize = 12.sp,
|
fontSize = 12.sp,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
color = BrandBlack,
|
color = BrandBlack,
|
||||||
modifier = Modifier.width(20.dp),
|
modifier = Modifier.width(42.dp),
|
||||||
textAlign = TextAlign.End
|
textAlign = TextAlign.End
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -716,13 +749,13 @@ fun OverdueActivitiesListModal(
|
|||||||
group: SelectedOverdueGroup,
|
group: SelectedOverdueGroup,
|
||||||
allActivities: List<MaintenanceActivity>,
|
allActivities: List<MaintenanceActivity>,
|
||||||
projectEnd: Date,
|
projectEnd: Date,
|
||||||
topSectors: List<String>,
|
topSectors: List<String> = emptyList(),
|
||||||
|
topTags: List<String> = emptyList(),
|
||||||
|
referenceDate: Date = Date(),
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
onActivityClick: (MaintenanceActivity) -> Unit
|
onActivityClick: (MaintenanceActivity) -> Unit
|
||||||
) {
|
) {
|
||||||
val referenceDate = remember { Date() }
|
val filteredActivities = remember(group, allActivities, referenceDate, topSectors, topTags) {
|
||||||
|
|
||||||
val filteredActivities = remember(group, allActivities, referenceDate, topSectors) {
|
|
||||||
allActivities.filter { act ->
|
allActivities.filter { act ->
|
||||||
val isNotCompleted = act.percentualExecucao < 100
|
val isNotCompleted = act.percentualExecucao < 100
|
||||||
val endDate = parseFullDateTime(act.dataFim) ?: parseDateOnly(act.dataFim)
|
val endDate = parseFullDateTime(act.dataFim) ?: parseDateOnly(act.dataFim)
|
||||||
@@ -732,7 +765,14 @@ fun OverdueActivitiesListModal(
|
|||||||
|
|
||||||
when (group.type) {
|
when (group.type) {
|
||||||
OverdueGroupType.TAG -> {
|
OverdueGroupType.TAG -> {
|
||||||
if (group.label == "Sem TAG") act.tag.isBlank() else act.tag == group.label
|
val actTag = if (act.tag.isBlank()) "Sem TAG" else act.tag
|
||||||
|
if (group.label == "Outros") {
|
||||||
|
!topTags.contains(actTag)
|
||||||
|
} else if (group.label == "Sem TAG") {
|
||||||
|
act.tag.isBlank()
|
||||||
|
} else {
|
||||||
|
act.tag == group.label
|
||||||
|
}
|
||||||
}
|
}
|
||||||
OverdueGroupType.SETOR -> {
|
OverdueGroupType.SETOR -> {
|
||||||
val actSetor = if (act.setor.isBlank()) "Sem Setor" else act.setor
|
val actSetor = if (act.setor.isBlank()) "Sem Setor" else act.setor
|
||||||
@@ -745,7 +785,10 @@ fun OverdueActivitiesListModal(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}.sortedWith(
|
||||||
|
compareByDescending<MaintenanceActivity> { it.duracaoHorasCalculada }
|
||||||
|
.thenBy { it.dataFimMillis }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
@@ -846,7 +889,7 @@ fun OverdueActivitiesListModal(
|
|||||||
|
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
Text(
|
Text(
|
||||||
text = activity.descricao,
|
text = activity.formattedDescricao,
|
||||||
fontSize = 12.sp,
|
fontSize = 12.sp,
|
||||||
fontWeight = FontWeight.Medium,
|
fontWeight = FontWeight.Medium,
|
||||||
color = Color.DarkGray,
|
color = Color.DarkGray,
|
||||||
|
|||||||
@@ -421,7 +421,7 @@ fun MaintenanceDashboardScreen(
|
|||||||
TextField(
|
TextField(
|
||||||
value = searchQuery,
|
value = searchQuery,
|
||||||
onValueChange = { viewModel.setSearchQuery(it) },
|
onValueChange = { viewModel.setSearchQuery(it) },
|
||||||
placeholder = { Text("Buscar por OS, descrição...", fontSize = 14.sp) },
|
placeholder = { Text("Buscar por OS, TAG, descrição...", fontSize = 14.sp) },
|
||||||
leadingIcon = { Icon(Icons.Default.Search, contentDescription = "Buscar") },
|
leadingIcon = { Icon(Icons.Default.Search, contentDescription = "Buscar") },
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
if (searchQuery.isNotEmpty()) {
|
if (searchQuery.isNotEmpty()) {
|
||||||
@@ -984,9 +984,8 @@ fun OSListItemCard(
|
|||||||
|
|
||||||
Spacer(modifier = Modifier.height(6.dp))
|
Spacer(modifier = Modifier.height(6.dp))
|
||||||
|
|
||||||
// Title Description
|
|
||||||
Text(
|
Text(
|
||||||
text = activity.descricao,
|
text = activity.formattedDescricao,
|
||||||
fontSize = 13.sp,
|
fontSize = 13.sp,
|
||||||
fontWeight = FontWeight.Medium,
|
fontWeight = FontWeight.Medium,
|
||||||
color = BrandBlack,
|
color = BrandBlack,
|
||||||
@@ -1403,7 +1402,7 @@ fun EditActivityBottomSheet(
|
|||||||
) {
|
) {
|
||||||
Column(modifier = Modifier.padding(12.dp)) {
|
Column(modifier = Modifier.padding(12.dp)) {
|
||||||
Text(
|
Text(
|
||||||
text = activity.descricao,
|
text = activity.formattedDescricao,
|
||||||
fontSize = 13.sp,
|
fontSize = 13.sp,
|
||||||
fontWeight = FontWeight.Medium,
|
fontWeight = FontWeight.Medium,
|
||||||
color = BrandBlack
|
color = BrandBlack
|
||||||
|
|||||||
@@ -253,7 +253,8 @@ class MaintenanceViewModel(private val repository: MaintenanceRepository) : View
|
|||||||
val matchQuery = query.isBlank() ||
|
val matchQuery = query.isBlank() ||
|
||||||
activity.numeroOs.contains(query, ignoreCase = true) ||
|
activity.numeroOs.contains(query, ignoreCase = true) ||
|
||||||
activity.descricao.contains(query, ignoreCase = true) ||
|
activity.descricao.contains(query, ignoreCase = true) ||
|
||||||
activity.recurso.contains(query, ignoreCase = true)
|
activity.recurso.contains(query, ignoreCase = true) ||
|
||||||
|
activity.tag.contains(query, ignoreCase = true)
|
||||||
|
|
||||||
val matchQuickFilter = when (quickFilter) {
|
val matchQuickFilter = when (quickFilter) {
|
||||||
"Todos" -> true
|
"Todos" -> true
|
||||||
@@ -818,45 +819,31 @@ class MaintenanceViewModel(private val repository: MaintenanceRepository) : View
|
|||||||
isNotCompleted && endMs < Long.MAX_VALUE && endMs < referenceDateMs
|
isNotCompleted && endMs < Long.MAX_VALUE && endMs < referenceDateMs
|
||||||
}
|
}
|
||||||
|
|
||||||
val overdueByTag = overdueActivities
|
val overdueByTagList = overdueActivities
|
||||||
.groupBy { if (it.tag.isBlank()) "Sem TAG" else it.tag }
|
.groupBy { if (it.tag.isBlank()) "Sem TAG" else it.tag }
|
||||||
.mapValues { it.value.size }
|
.mapValues { entry -> entry.value.sumOf { it.duracaoHorasCalculada } }
|
||||||
.toList()
|
.toList()
|
||||||
.sortedByDescending { it.second }
|
.sortedWith(compareByDescending<Pair<String, Double>> { it.second }.thenBy { it.first })
|
||||||
|
|
||||||
val displayLimit = 4
|
val finalOverdueByTag = if (overdueByTagList.size <= 9) {
|
||||||
val finalOverdueByTag = if (overdueByTag.size <= displayLimit) {
|
overdueByTagList
|
||||||
overdueByTag
|
|
||||||
} else {
|
} else {
|
||||||
val top = overdueByTag.take(displayLimit - 1)
|
val top = overdueByTagList.take(9)
|
||||||
val othersCount = overdueByTag.drop(displayLimit - 1).sumOf { it.second }
|
val othersHours = overdueByTagList.drop(9).sumOf { it.second }
|
||||||
top + listOf("Outros" to othersCount)
|
top + listOf("Outros" to othersHours)
|
||||||
}
|
}
|
||||||
|
|
||||||
val overdueBySectorMap = overdueActivities
|
val overdueBySectorMap = overdueActivities
|
||||||
.groupBy { if (it.setor.isBlank()) "Sem Setor" else it.setor }
|
.groupBy { if (it.setor.isBlank()) "Sem Setor" else it.setor }
|
||||||
.mapValues { it.value.size }
|
.mapValues { entry -> entry.value.sumOf { it.duracaoHorasCalculada } }
|
||||||
|
|
||||||
val finalOverdueBySector = if (overdueActivities.isEmpty()) {
|
|
||||||
emptyList()
|
|
||||||
} else {
|
|
||||||
val plantSectors = activities
|
val plantSectors = activities
|
||||||
.map { if (it.setor.isBlank()) "Sem Setor" else it.setor }
|
.map { if (it.setor.isBlank()) "Sem Setor" else it.setor }
|
||||||
.distinct()
|
.distinct()
|
||||||
|
|
||||||
val fullOverdueBySector = plantSectors
|
val finalOverdueBySector = plantSectors
|
||||||
.map { sector -> sector to (overdueBySectorMap[sector] ?: 0) }
|
.map { sector -> sector to (overdueBySectorMap[sector] ?: 0.0) }
|
||||||
.sortedWith(compareByDescending<Pair<String, Int>> { it.second }.thenBy { it.first })
|
.sortedWith(compareByDescending<Pair<String, Double>> { 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,
|
||||||
|
|||||||
@@ -479,19 +479,19 @@ class ExampleRobolectricTest {
|
|||||||
|
|
||||||
// 1. Current Date (July 2026): 0 or 1 overdue OS because CSV activities are in Aug/Sep 2026
|
// 1. Current Date (July 2026): 0 or 1 overdue OS because CSV activities are in Aug/Sep 2026
|
||||||
val overdueJuly = state.overdueBySector.sumOf { it.second }
|
val overdueJuly = state.overdueBySector.sumOf { it.second }
|
||||||
assertTrue("Expected overdueJuly <= 1, got $overdueJuly", overdueJuly <= 1)
|
assertTrue("Expected overdueJuly <= 10.0, got $overdueJuly", overdueJuly <= 10.0)
|
||||||
|
|
||||||
// 2. Simulated Future Date (August 20, 2026): OSs due before Aug 20 start appearing as overdue
|
// 2. Simulated Future Date (August 20, 2026): OSs due before Aug 20 start appearing as overdue
|
||||||
val aug20 = com.example.data.model.parseFullDateTime("20/08/26 18:00")!!
|
val aug20 = com.example.data.model.parseFullDateTime("20/08/26 18:00")!!
|
||||||
val stateAug20 = viewModel.calculateAnalyticsState(activitiesList, emptyList(), referenceDateOverride = aug20)
|
val stateAug20 = viewModel.calculateAnalyticsState(activitiesList, emptyList(), referenceDateOverride = aug20)
|
||||||
val overdueAug20 = stateAug20.overdueBySector.sumOf { it.second }
|
val overdueAug20 = stateAug20.overdueBySector.sumOf { it.second }
|
||||||
assertTrue("Expected overdue activities on Aug 20, 2026, got: $overdueAug20", overdueAug20 > 0)
|
assertTrue("Expected overdue activities on Aug 20, 2026, got: $overdueAug20", overdueAug20 > 0.0)
|
||||||
|
|
||||||
// 3. Simulated Future Date (September 15, 2026): All incomplete activities in project are overdue
|
// 3. Simulated Future Date (September 15, 2026): All incomplete activities in project are overdue
|
||||||
val sep15 = com.example.data.model.parseFullDateTime("15/09/26 18:00")!!
|
val sep15 = com.example.data.model.parseFullDateTime("15/09/26 18:00")!!
|
||||||
val stateSep15 = viewModel.calculateAnalyticsState(activitiesList, emptyList(), referenceDateOverride = sep15)
|
val stateSep15 = viewModel.calculateAnalyticsState(activitiesList, emptyList(), referenceDateOverride = sep15)
|
||||||
val overdueSep15 = stateSep15.overdueBySector.sumOf { it.second }
|
val overdueSep15 = stateSep15.overdueBySector.sumOf { it.second }
|
||||||
assertTrue("Expected most CSV activities to be overdue on Sep 15, got: $overdueSep15", overdueSep15 > 400)
|
assertTrue("Expected most CSV activities to be overdue on Sep 15, got: $overdueSep15", overdueSep15 > 400.0)
|
||||||
|
|
||||||
val targetOs = db.maintenanceDao().getAllActivitiesList().firstOrNull()?.numeroOs ?: "1024"
|
val targetOs = db.maintenanceDao().getAllActivitiesList().firstOrNull()?.numeroOs ?: "1024"
|
||||||
repository.updateProgress(
|
repository.updateProgress(
|
||||||
|
|||||||
@@ -458,7 +458,78 @@ class ExampleUnitTest {
|
|||||||
assertEquals(100.0f, stateUtil.realizedProgressPoints.last(), 0.5f)
|
assertEquals(100.0f, stateUtil.realizedProgressPoints.last(), 0.5f)
|
||||||
assertEquals(0.0f, statePrep.realizedProgressPoints.last(), 0.5f)
|
assertEquals(0.0f, statePrep.realizedProgressPoints.last(), 0.5f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testSearchQueryFilteringByTag() {
|
||||||
|
val act1 = com.example.data.model.MaintenanceActivity(
|
||||||
|
numeroOs = "OS-100", descricao = "Troca de Motor", setor = "Geral", equipe = "Mecânica", recurso = "Sem Recurso",
|
||||||
|
dataInicio = "18/08/2026", dataFim = "22/08/2026", percentualExecucao = 0, tag = "TAG-VALVULA-01"
|
||||||
|
)
|
||||||
|
val act2 = com.example.data.model.MaintenanceActivity(
|
||||||
|
numeroOs = "OS-200", descricao = "Inspeção de Bomba", setor = "Geral", equipe = "Mecânica", recurso = "Sem Recurso",
|
||||||
|
dataInicio = "18/08/2026", dataFim = "22/08/2026", percentualExecucao = 0, tag = "TAG-BOMBA-02"
|
||||||
|
)
|
||||||
|
val activities = listOf(act1, act2)
|
||||||
|
|
||||||
|
val filterByTag = { query: String ->
|
||||||
|
activities.filter { activity ->
|
||||||
|
query.isBlank() ||
|
||||||
|
activity.numeroOs.contains(query, ignoreCase = true) ||
|
||||||
|
activity.descricao.contains(query, ignoreCase = true) ||
|
||||||
|
activity.recurso.contains(query, ignoreCase = true) ||
|
||||||
|
activity.tag.contains(query, ignoreCase = true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. Partial TAG match
|
||||||
|
val resultValvula = filterByTag("VALVULA")
|
||||||
|
assertEquals(1, resultValvula.size)
|
||||||
|
assertEquals("OS-100", resultValvula[0].numeroOs)
|
||||||
|
|
||||||
|
// 2. Case insensitive match
|
||||||
|
val resultBombaLower = filterByTag("bomba")
|
||||||
|
assertEquals(1, resultBombaLower.size)
|
||||||
|
assertEquals("OS-200", resultBombaLower[0].numeroOs)
|
||||||
|
|
||||||
|
// 3. Search query matching both or empty
|
||||||
|
val resultTagCommon = filterByTag("TAG")
|
||||||
|
assertEquals(2, resultTagCommon.size)
|
||||||
|
|
||||||
|
// 4. Search query matching nonexistent tag
|
||||||
|
val resultNotFound = filterByTag("TAG-INEXISTENTE")
|
||||||
|
assertEquals(0, resultNotFound.size)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testFormattedHorasAndDescriptionPrefix() {
|
||||||
|
val act8h = com.example.data.model.MaintenanceActivity(
|
||||||
|
numeroOs = "OS-1", descricao = "PARADA ANUAL 2026", setor = "Geral", equipe = "Mecânica", recurso = "Sem Recurso",
|
||||||
|
dataInicio = "18/08/2026", dataFim = "22/08/2026", percentualExecucao = 0, quantidadeHoras = 8.0
|
||||||
|
)
|
||||||
|
val actDecimal = com.example.data.model.MaintenanceActivity(
|
||||||
|
numeroOs = "OS-2", descricao = "SOLDA EIXO", setor = "Geral", equipe = "Mecânica", recurso = "Sem Recurso",
|
||||||
|
dataInicio = "18/08/2026", dataFim = "22/08/2026", percentualExecucao = 0, quantidadeHoras = 12.5
|
||||||
|
)
|
||||||
|
val actZero = com.example.data.model.MaintenanceActivity(
|
||||||
|
numeroOs = "OS-3", descricao = "INSPEÇÃO", setor = "Geral", equipe = "Mecânica", recurso = "Sem Recurso",
|
||||||
|
dataInicio = "18/08/2026", dataFim = "22/08/2026", percentualExecucao = 0, quantidadeHoras = 0.0
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals("8h", act8h.formattedHoras)
|
||||||
|
assertEquals("12.5h", actDecimal.formattedHoras)
|
||||||
|
assertEquals("0h", actZero.formattedHoras)
|
||||||
|
|
||||||
|
val getDisplayDesc = { activity: com.example.data.model.MaintenanceActivity ->
|
||||||
|
if (activity.quantidadeHoras > 0) "${activity.formattedHoras} - ${activity.descricao}" else activity.descricao
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals("8h - PARADA ANUAL 2026", getDisplayDesc(act8h))
|
||||||
|
assertEquals("12.5h - SOLDA EIXO", getDisplayDesc(actDecimal))
|
||||||
|
assertEquals("INSPEÇÃO", getDisplayDesc(actZero))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user