Skip to content

Commit

Permalink
feat(analyze): Filters similar screenshots to avoid noise and unneces…
Browse files Browse the repository at this point in the history
…sary data
  • Loading branch information
luistak committed Jan 27, 2025
1 parent b004395 commit 3746011
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import com.github.romankh3.image.comparison.ImageComparisonUtil
import java.nio.file.Files
import java.nio.file.Path
import java.util.stream.Collectors
Expand Down Expand Up @@ -89,13 +90,39 @@ class TestAnalysisManager(private val apiUrl: String, private val apiKey: String
}
}

val filteredScreenshots = filterSimilarScreenshots(screenshots)

return AnalysisDebugFiles(
logs = logs,
commands = commands,
screenshots = screenshots,
screenshots = filteredScreenshots,
)
}

private val screenshotsDifferenceThreshold = 5.0

private fun filterSimilarScreenshots(
screenshots: List<AnalysisScreenshot>
): List<AnalysisScreenshot> {
val uniqueScreenshots = mutableListOf<AnalysisScreenshot>()

for (screenshot in screenshots) {
val isSimilar = uniqueScreenshots.any { existingScreenshot ->
val diffPercent = ImageComparisonUtil.getDifferencePercent(
ImageComparisonUtil.readImageFromResources(existingScreenshot.path.toString()),
ImageComparisonUtil.readImageFromResources(screenshot.path.toString())
)
diffPercent <= screenshotsDifferenceThreshold
}

if (!isSimilar) {
uniqueScreenshots.add(screenshot)
}
}

return uniqueScreenshots
}

/**
* The Notification system for Test Analysis.
* - Uses configuration from $XDG_CONFIG_HOME/maestro/analyze-notification.json.
Expand Down

0 comments on commit 3746011

Please sign in to comment.