commit
594ba3c444
@ -0,0 +1,72 @@ |
|||||||
|
package net.pokeranalytics.android |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import androidx.test.core.app.ApplicationProvider |
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4 |
||||||
|
import net.pokeranalytics.android.calculus.Calculator |
||||||
|
import net.pokeranalytics.android.calculus.ComputableGroup |
||||||
|
import net.pokeranalytics.android.calculus.ComputedResults |
||||||
|
import net.pokeranalytics.android.calculus.Stat |
||||||
|
import net.pokeranalytics.android.model.realm.ComputableResult |
||||||
|
import net.pokeranalytics.android.model.realm.Session |
||||||
|
import net.pokeranalytics.android.model.realm.SessionSet |
||||||
|
import net.pokeranalytics.android.model.utils.Seed |
||||||
|
import net.pokeranalytics.android.util.FakeDataManager |
||||||
|
import org.junit.Test |
||||||
|
import org.junit.runner.RunWith |
||||||
|
import timber.log.Timber |
||||||
|
|
||||||
|
/** |
||||||
|
* Instrumented test, which will execute on an Android device. |
||||||
|
* |
||||||
|
* See [testing documentation](http://d.android.com/tools/testing). |
||||||
|
*/ |
||||||
|
@RunWith(AndroidJUnit4::class) |
||||||
|
class PerfsInstrumentedUnitTest : RealmInstrumentedUnitTest() { |
||||||
|
|
||||||
|
@Test |
||||||
|
fun testGlobalPerfs() { |
||||||
|
|
||||||
|
Timber.d("*** start global perfs ") |
||||||
|
|
||||||
|
|
||||||
|
val realm = mockRealm |
||||||
|
val app: Context = ApplicationProvider.getApplicationContext() |
||||||
|
|
||||||
|
realm.beginTransaction() |
||||||
|
Seed(app).execute(realm) |
||||||
|
realm.commitTransaction() |
||||||
|
|
||||||
|
|
||||||
|
FakeDataManager.createFakeSessions(2000) {success -> |
||||||
|
|
||||||
|
if (success) { |
||||||
|
|
||||||
|
val start = System.currentTimeMillis() |
||||||
|
|
||||||
|
val sessions = realm.where(Session::class.java).findAll() |
||||||
|
val computableResults = realm.where(ComputableResult::class.java).findAll() |
||||||
|
val sets = realm.where(SessionSet::class.java).findAll() |
||||||
|
|
||||||
|
Timber.d("sessions: ${sessions.size}") |
||||||
|
Timber.d("computableResults: ${computableResults.size}") |
||||||
|
Timber.d("sets: ${sets.size}") |
||||||
|
|
||||||
|
val stats: List<Stat> = listOf(Stat.NETRESULT, Stat.AVERAGE) |
||||||
|
val group = ComputableGroup("test", computableResults, sets, stats) |
||||||
|
|
||||||
|
val options = Calculator.Options() |
||||||
|
options.displayedStats = listOf(Stat.STANDARD_DEVIATION_BB_PER_100_HANDS, Stat.STANDARD_DEVIATION) |
||||||
|
|
||||||
|
val results: ComputedResults = Calculator.compute(group, options) |
||||||
|
|
||||||
|
Timber.d("*** ended in ${System.currentTimeMillis() - start} milliseconds") |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,101 @@ |
|||||||
|
package net.pokeranalytics.android.util |
||||||
|
|
||||||
|
import io.realm.Realm |
||||||
|
import io.realm.kotlin.where |
||||||
|
import net.pokeranalytics.android.model.Limit |
||||||
|
import net.pokeranalytics.android.model.realm.Bankroll |
||||||
|
import net.pokeranalytics.android.model.realm.Game |
||||||
|
import net.pokeranalytics.android.model.realm.Session |
||||||
|
import timber.log.Timber |
||||||
|
import java.util.* |
||||||
|
|
||||||
|
class FakeDataManager { |
||||||
|
|
||||||
|
companion object { |
||||||
|
|
||||||
|
/** |
||||||
|
* Create the given number of fake sessions |
||||||
|
*/ |
||||||
|
fun createFakeSessions(numberOfSessions: Int = 1000, callback: ((success: Boolean) -> Unit)? = null) { |
||||||
|
|
||||||
|
val buyinList = arrayListOf(100.0, 200.0, 300.0, 500.0, 1000.0, 2000.0) |
||||||
|
val resultsList = arrayListOf( |
||||||
|
-2500.0, -2000.0, -1500.0, -1000.0, -500.0, 200.0, 1000.0, 1500.0, 2500.0 |
||||||
|
) |
||||||
|
|
||||||
|
val commitFrequency = 100 |
||||||
|
|
||||||
|
try { |
||||||
|
|
||||||
|
val realm = Realm.getDefaultInstance() |
||||||
|
val games = realm.where<Game>().findAll() |
||||||
|
val bankroll = realm.where<Bankroll>().findAll().firstOrNull() |
||||||
|
|
||||||
|
// Test endedSessions |
||||||
|
|
||||||
|
Timber.d("*** Start creating ${numberOfSessions} fake computables...") |
||||||
|
|
||||||
|
val s = Date() |
||||||
|
|
||||||
|
realm.beginTransaction() |
||||||
|
|
||||||
|
for (index in 0..numberOfSessions) { |
||||||
|
|
||||||
|
if (index % commitFrequency == 0) { |
||||||
|
Timber.d("****** committing at ${index} computables...") |
||||||
|
realm.commitTransaction() |
||||||
|
realm.beginTransaction() |
||||||
|
} |
||||||
|
|
||||||
|
val session = Session.newInstance(realm, Math.random() > 0.5, bankroll) |
||||||
|
|
||||||
|
val bigBlind = arrayListOf(1.0, 2.0, 4.0).random() |
||||||
|
session.cgBigBlind = bigBlind |
||||||
|
session.cgSmallBlind = bigBlind / 2.0 |
||||||
|
|
||||||
|
val calendar = Calendar.getInstance() |
||||||
|
calendar.set( |
||||||
|
(2016..2018).random(), |
||||||
|
(0..11).random(), |
||||||
|
(0..28).random(), |
||||||
|
(0..23).random(), |
||||||
|
(0..59).random() |
||||||
|
) |
||||||
|
|
||||||
|
val startDate = calendar.time |
||||||
|
calendar.add(Calendar.HOUR_OF_DAY, (2..12).random()) |
||||||
|
calendar.add(Calendar.MINUTE, (0..59).random()) |
||||||
|
val endDate = calendar.time |
||||||
|
|
||||||
|
session.startDate = startDate |
||||||
|
session.endDate = endDate |
||||||
|
session.creationDate = startDate |
||||||
|
|
||||||
|
session.limit = Limit.values().random().ordinal |
||||||
|
session.game = games.random() |
||||||
|
|
||||||
|
session.result?.let { result -> |
||||||
|
result.buyin = buyinList.random() |
||||||
|
result.netResult = resultsList.random() |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
realm.commitTransaction() |
||||||
|
|
||||||
|
val e = Date() |
||||||
|
val duration = (e.time - s.time) / 1000.0 |
||||||
|
Timber.d("*** ended in ${duration} seconds") |
||||||
|
|
||||||
|
realm.close() |
||||||
|
|
||||||
|
callback?.invoke(true) |
||||||
|
|
||||||
|
} catch (e: Exception) { |
||||||
|
Timber.e(e) |
||||||
|
callback?.invoke(true) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue