Fixing an issue when session set did not split

od
Laurent 6 years ago
parent 39a27c011d
commit 2dd87b1484
  1. 49
      app/src/androidTest/java/net/pokeranalytics/android/unitTests/StatsInstrumentedUnitTest.kt
  2. 40
      app/src/main/java/net/pokeranalytics/android/model/utils/SessionSetManager.kt

@ -506,6 +506,55 @@ class StatsInstrumentedUnitTest : SessionInstrumentedUnitTest() {
}
@Test
fun testSessionSetCount3() {
val realm = this.mockRealm
realm.executeTransaction {
val s1 = newSessionInstance(realm)
val s2 = newSessionInstance(realm)
val sdf = SimpleDateFormat("dd/M/yyyy hh:mm")
val sd1 = sdf.parse("02/1/2019 09:00")
val ed1 = sdf.parse("02/1/2019 10:00")
val sd2 = sdf.parse("01/1/2019 09:00")
val ed2 = sdf.parse("03/1/2019 10:00")
s1.startDate = sd1
s1.endDate = ed1
s2.startDate = sd2
s2.endDate = ed2
val ed22 = sdf.parse("01/1/2019 10:00")
s2.endDate = ed22
}
val sets = realm.where(SessionSet::class.java).findAll()
assertEquals(2, sets.size)
val group = ComputableGroup(Query(), listOf(Stat.NUMBER_OF_GAMES, Stat.NUMBER_OF_SETS, Stat.HOURLY_DURATION))
val options = Calculator.Options()
val results: ComputedResults = Calculator.compute(realm, group, options)
results.computedStat(Stat.NUMBER_OF_GAMES)?.let {
assertEquals(2, it.value.toInt())
}
results.computedStat(Stat.NUMBER_OF_SETS)?.let {
assertEquals(2, it.value.toInt())
}
results.computedStat(Stat.HOURLY_DURATION)?.let {
assertEquals(2.0, it.value, 0.001)
}
}
@Test
fun testSessionRestartInOverlappingSessions() {

@ -33,10 +33,17 @@ class SessionSetManager {
if (session.endDate == null) {
throw ModelException("End date should never be null here")
}
val endDate = session.endDate!! // tested above
val startDate = session.startDate!!
val sessionSets = this.matchingSets(session)
cleanupSessionSets(session, sessionSets)
}
private fun matchingSets(session: Session) : RealmResults<SessionSet> {
val realm = session.realm
val endDate = session.endDate!! // tested above
val startDate = session.startDate!!
val query: RealmQuery<SessionSet> = realm.where(SessionSet::class.java)
@ -50,12 +57,37 @@ class SessionSetManager {
.greaterThanOrEqualTo("startDate", startDate)
.lessThanOrEqualTo("endDate", endDate)
val sessionGroups = query.findAll()
return query.findAll()
}
/**
* Multiple session sets update:
* Merges or splits session sets
* Does that by deleting then recreating
*/
private fun cleanupSessionSets(session: Session, sessionSets: RealmResults<SessionSet>) {
// get all endedSessions from sets
val allImpactedSessions = mutableSetOf<Session>()
sessionSets.forEach { set ->
set.sessions?.asIterable()?.let { allImpactedSessions.addAll(it) }
}
allImpactedSessions.add(session)
// delete all sets
sessionSets.deleteAllFromRealm()
allImpactedSessions.forEach { session ->
val sets = matchingSets(session)
this.updateTimeFrames(sets, session)
// updateTimeline(session)
}
this.updateTimeFrames(sessionGroups, session)
// Timber.d("netDuration 3 = : ${set.timeFrame?.netDuration}")
}
/**
* Update the global timeline using the impacted [sessionSets] and the updated [session]
*/

Loading…
Cancel
Save