|
|
|
@ -6,18 +6,17 @@ import io.realm.RealmConfiguration |
|
|
|
import io.realm.RealmResults |
|
|
|
import io.realm.RealmResults |
|
|
|
import io.realm.kotlin.where |
|
|
|
import io.realm.kotlin.where |
|
|
|
import net.pokeranalytics.android.model.Limit |
|
|
|
import net.pokeranalytics.android.model.Limit |
|
|
|
import net.pokeranalytics.android.model.realm.* |
|
|
|
import net.pokeranalytics.android.model.realm.Game |
|
|
|
import net.pokeranalytics.android.model.realm.Currency |
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
import net.pokeranalytics.android.model.utils.Seed |
|
|
|
import net.pokeranalytics.android.model.utils.Seed |
|
|
|
import net.pokeranalytics.android.util.PokerAnalyticsLogs |
|
|
|
import net.pokeranalytics.android.util.PokerAnalyticsLogs |
|
|
|
import net.pokeranalytics.android.util.Preferences |
|
|
|
|
|
|
|
import timber.log.Timber |
|
|
|
import timber.log.Timber |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PokerAnalyticsApplication : Application() { |
|
|
|
class PokerAnalyticsApplication : Application() { |
|
|
|
|
|
|
|
|
|
|
|
var sessions: RealmResults<Session>? = null |
|
|
|
var sessions: RealmResults<Session>? = null |
|
|
|
|
|
|
|
|
|
|
|
// private val listener: OrderedRealmCollectionChangeListener<RealmResults<Session>> = |
|
|
|
// private val listener: OrderedRealmCollectionChangeListener<RealmResults<Session>> = |
|
|
|
// OrderedRealmCollectionChangeListener() { realmResults: RealmResults<Session>, changeSet: OrderedCollectionChangeSet -> |
|
|
|
// OrderedRealmCollectionChangeListener() { realmResults: RealmResults<Session>, changeSet: OrderedCollectionChangeSet -> |
|
|
|
@ -33,120 +32,123 @@ class PokerAnalyticsApplication : Application() { |
|
|
|
// |
|
|
|
// |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreate() { |
|
|
|
override fun onCreate() { |
|
|
|
super.onCreate() |
|
|
|
super.onCreate() |
|
|
|
|
|
|
|
|
|
|
|
// Realm |
|
|
|
// Realm |
|
|
|
Realm.init(this) |
|
|
|
Realm.init(this) |
|
|
|
val realmConfiguration = RealmConfiguration.Builder() |
|
|
|
val realmConfiguration = RealmConfiguration.Builder() |
|
|
|
.name(Realm.DEFAULT_REALM_NAME) |
|
|
|
.name(Realm.DEFAULT_REALM_NAME) |
|
|
|
.deleteRealmIfMigrationNeeded() |
|
|
|
.deleteRealmIfMigrationNeeded() |
|
|
|
.initialData(Seed(this)) |
|
|
|
.initialData(Seed(this)) |
|
|
|
.build() |
|
|
|
.build() |
|
|
|
Realm.setDefaultConfiguration(realmConfiguration) |
|
|
|
Realm.setDefaultConfiguration(realmConfiguration) |
|
|
|
|
|
|
|
|
|
|
|
val realm: Realm = Realm.getDefaultInstance() |
|
|
|
val realm: Realm = Realm.getDefaultInstance() |
|
|
|
// Add observer on session time frame changes |
|
|
|
// Add observer on session time frame changes |
|
|
|
this.sessions = realm.where(Session::class.java).findAll() // monitor session deletions |
|
|
|
this.sessions = realm.where(Session::class.java).findAll() // monitor session deletions |
|
|
|
// this.endedSessions?.addChangeListener { _, changeSet -> |
|
|
|
// this.endedSessions?.addChangeListener { _, changeSet -> |
|
|
|
/* |
|
|
|
/* |
|
|
|
val deletedSessions = |
|
|
|
val deletedSessions = |
|
|
|
realm.where(Session::class.java).`in`("id", changeSet.deletions.toTypedArray()).findAll() |
|
|
|
realm.where(Session::class.java).`in`("id", changeSet.deletions.toTypedArray()).findAll() |
|
|
|
deletedSessions.forEach { it.cleanup() } |
|
|
|
deletedSessions.forEach { it.cleanup() } |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
if (BuildConfig.DEBUG) { |
|
|
|
if (BuildConfig.DEBUG) { |
|
|
|
// Logs |
|
|
|
// Logs |
|
|
|
Timber.plant(PokerAnalyticsLogs()) |
|
|
|
Timber.plant(PokerAnalyticsLogs()) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
//Fabric.with(this, Crashlytics()) |
|
|
|
//Fabric.with(this, Crashlytics()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (BuildConfig.DEBUG) { |
|
|
|
if (BuildConfig.DEBUG) { |
|
|
|
this.createFakeSessions() // debug |
|
|
|
this.createFakeSessions() // debug |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun createFakeSessions() { |
|
|
|
private fun createFakeSessions() { |
|
|
|
|
|
|
|
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
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 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// Test endedSessions |
|
|
|
Thread().run() { |
|
|
|
val sessions = realm.where<Session>().findAll() |
|
|
|
|
|
|
|
if (sessions.size < 10) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val numberOfSessions = 50 |
|
|
|
try { |
|
|
|
Timber.d("> Start creating ${numberOfSessions} fake sessions...") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val s = Date() |
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
|
|
|
val games = realm.where<Game>().findAll() |
|
|
|
|
|
|
|
|
|
|
|
for (index in 0..numberOfSessions) { |
|
|
|
// Test endedSessions |
|
|
|
|
|
|
|
val sessions = realm.where<Session>().findAll() |
|
|
|
|
|
|
|
if (sessions.size < 10) { |
|
|
|
|
|
|
|
|
|
|
|
realm.executeTransaction { |
|
|
|
val numberOfSessions = 10000 |
|
|
|
val session = Session.newInstance(realm, false) |
|
|
|
Timber.d("*** Start creating ${numberOfSessions} fake sessions...") |
|
|
|
// session.id = UUID.randomUUID().toString() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
val s = Date() |
|
|
|
calendar.set( |
|
|
|
|
|
|
|
(2017..2018).random(), |
|
|
|
|
|
|
|
(0..11).random(), |
|
|
|
|
|
|
|
(0..28).random(), |
|
|
|
|
|
|
|
(0..23).random(), |
|
|
|
|
|
|
|
(0..59).random() |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val startDate = calendar.time |
|
|
|
realm.beginTransaction() |
|
|
|
calendar.add(Calendar.HOUR_OF_DAY, (2..12).random()) |
|
|
|
|
|
|
|
calendar.add(Calendar.MINUTE, (0..59).random()) |
|
|
|
for (index in 0..numberOfSessions) { |
|
|
|
val endDate = calendar.time |
|
|
|
|
|
|
|
|
|
|
|
if (index % 1000 == 999) { |
|
|
|
|
|
|
|
Timber.d("****** committing at ${index} sessions...") |
|
|
|
|
|
|
|
realm.commitTransaction() |
|
|
|
|
|
|
|
realm.beginTransaction() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val session = Session.newInstance(realm, false) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
|
|
|
|
calendar.set( |
|
|
|
|
|
|
|
(2017..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 |
|
|
|
|
|
|
|
|
|
|
|
// val timeFrame = TimeFrame() |
|
|
|
// val timeFrame = TimeFrame() |
|
|
|
|
|
|
|
|
|
|
|
session.startDate = startDate |
|
|
|
session.startDate = startDate |
|
|
|
session.endDate = endDate |
|
|
|
session.endDate = endDate |
|
|
|
|
|
|
|
session.creationDate = startDate |
|
|
|
|
|
|
|
|
|
|
|
// session.timeFrame?.let { |
|
|
|
session.limit = Limit.values().random().ordinal |
|
|
|
// // it.startDate = startDate |
|
|
|
session.game = games.random() |
|
|
|
//// it.endDate = endDate |
|
|
|
|
|
|
|
// it.setDate(startDate, endDate) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// session.timeFrame = timeFrame |
|
|
|
session.result?.let { result -> |
|
|
|
session.creationDate = startDate |
|
|
|
result.buyin = buyinList.random() |
|
|
|
|
|
|
|
result.netResult = resultsList.random() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
session.limit = Limit.values().random().ordinal |
|
|
|
} |
|
|
|
session.game = realm.where<Game>().findAll().random() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
session.result?.let { result -> |
|
|
|
realm.commitTransaction() |
|
|
|
result.buyin = arrayListOf(100, 200, 300, 500, 1000, 2000).random().toDouble() |
|
|
|
|
|
|
|
result.netResult = arrayListOf( |
|
|
|
|
|
|
|
-2500.0, -2000.0, -1500.0, -1000.0, -500.0, 200.0, 1000.0, 1500.0, |
|
|
|
|
|
|
|
2500.0 |
|
|
|
|
|
|
|
).random() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
realm.copyToRealmOrUpdate(session) |
|
|
|
val e = Date() |
|
|
|
} |
|
|
|
val duration = (e.time - s.time) / 1000.0 |
|
|
|
} |
|
|
|
Timber.d("*** ended in ${duration} seconds") |
|
|
|
val e = Date() |
|
|
|
|
|
|
|
val duration = (e.time - s.time) / 1000.0 |
|
|
|
|
|
|
|
Timber.d("> ended in ${duration} seconds") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
realm.close() |
|
|
|
|
|
|
|
|
|
|
|
// val sets = realm.where(SessionSet::class.java).findAll() |
|
|
|
} catch (e: Exception) { |
|
|
|
// |
|
|
|
Timber.e(e) |
|
|
|
// Timber.d("sets = ${sets.size}") |
|
|
|
} |
|
|
|
// |
|
|
|
|
|
|
|
// sets.forEach { set -> |
|
|
|
|
|
|
|
// Timber.d("set sd = : ${set.timeFrame?.startDate}, ed = ${set.timeFrame?.endDate}") |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
realm.close() |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |