Add visualizer #29

Merged
maxime.batista merged 9 commits from visualizer into master 1 year ago

This pull request adds a visualizer.
WARNING: If you try to execute it on your phone, it could not work as the used tactic is hardcoded and comes from my local development.

You can build your own tactic on the web app and then change the value 21 with your desired tactic in the VisualizerPage invokation at MainActivity.App.

We need a pull request for the home page to be able to select the wanted tactic dynamically.

This pull request adds a visualizer. WARNING: If you try to execute it on your phone, it could not work as the used tactic is hardcoded and comes from my local development. You can build your own tactic on the web app and then change the value `21` with your desired tactic in the `VisualizerPage` invokation at MainActivity.App. We need a pull request for the home page to be able to select the wanted tactic dynamically.
maxime.batista added 4 commits 1 year ago
maxime.batista requested review from yanis.dahmane-bounoua 1 year ago
maxime.batista requested review from vivien.dufour 1 year ago
maxime.batista requested review from mael.daim 1 year ago
maxime.batista requested review from samuel.berion 1 year ago
maxime.batista added 1 commit 1 year ago
maxime.batista added 1 commit 1 year ago
clement.freville2 approved these changes 1 year ago
import java.net.URI
-import java.net.URI
-
```diff -import java.net.URI - ```
maxime.batista marked this conversation as resolved
for (i in segments.indices) {
val segment = segments[i]
-    for (i in segments.indices) {
-        val segment = segments[i]
+    for ((i, segment) in segments.withIndex()) {
```diff - for (i in segments.indices) { - val segment = segments[i] + for ((i, segment) in segments.withIndex()) { ```
maxime.batista marked this conversation as resolved
import com.iqball.app.model.tactic.StepContent
/**
* Converts the phantom's [PhantomPositioning] to a XY Position
- * Converts the phantom's [PhantomPositioning] to a XY Position
+ * Converts the phantom's [Positioning] to a XY Position
```diff - * Converts the phantom's [PhantomPositioning] to a XY Position + * Converts the phantom's [Positioning] to a XY Position ```
maxime.batista marked this conversation as resolved
JsonReader.Token.STRING -> JsonPrimitiveType.String
JsonReader.Token.NUMBER -> JsonPrimitiveType.Number
JsonReader.Token.BOOLEAN -> JsonPrimitiveType.Boolean
JsonReader.Token.NULL -> return null
-            JsonReader.Token.NULL -> return null
+            JsonReader.Token.NULL -> {
+                reader.nextNull<Any>()
+                return null
+            }
```diff - JsonReader.Token.NULL -> return null + JsonReader.Token.NULL -> { + reader.nextNull<Any>() + return null + } ```
maxime.batista marked this conversation as resolved
maxime.batista force-pushed visualizer from 2e41bd50d9 to a387d4e13f 1 year ago
maxime.batista force-pushed visualizer from a387d4e13f to 2e41bd50d9 1 year ago
maxime.batista added 1 commit 1 year ago
maxime.batista force-pushed visualizer from d35705b8bb to f035eb854b 1 year ago
maxime.batista force-pushed visualizer from f035eb854b to e41e3eb8f3 1 year ago
samuel.berion approved these changes 1 year ago
maxime.batista added 1 commit 1 year ago
maxime.batista requested review from clement.freville2 1 year ago
maxime.batista force-pushed visualizer from 11806e0132 to 22ed746ce3 1 year ago
clement.freville2 requested changes 1 year ago
clement.freville2 left a comment

A bit skeptical with all those runBlocking. Using the composable couroutineScope would be better.

A bit skeptical with all those `runBlocking`. Using the composable `couroutineScope` would be better.
import com.iqball.app.model.tactic.StepNodeInfo
fun getStepName(root: StepNodeInfo, step: Int): String {

The same cost applies here as in the web version. This algorithm may traverse the whole tree and is called for every node. The root node should not be necessary to get the name.

The tree is immutable here, so it relatively simple to a have a separated DTO class:

data class StepNodeInfo(val id: Int, val name: String, val parent: Int?, val children: List<StepNodeInfo>)

data class StepNodeDTO(val id: Int, val children: List<StepNodeDTO>) {
    val subTreeSize: Int
        get() = children.fold(1) { acc, child -> acc + child.subTreeSize }
}

class StepTreeAdapter {
    @FromJson
    fun fromJson(dto: StepNodeDTO): StepNodeInfo = fromJson(dto, null, 1)

    private fun fromJson(dto: StepNodeDTO, parent: Int?, nextName: Int): StepNodeInfo {
        var num = nextName
        return StepNodeInfo(dto.id, num.toString(), parent, dto.children.map {
            val node = fromJson(it, dto.id, num + 1)
            num += it.subTreeSize
            node
        })
    }
}
The same cost applies here as in the web version. This algorithm may traverse the whole tree and is called for every node. The root node should not be necessary to get the name. The tree is immutable here, so it relatively simple to a have a separated DTO class: ```kt data class StepNodeInfo(val id: Int, val name: String, val parent: Int?, val children: List<StepNodeInfo>) data class StepNodeDTO(val id: Int, val children: List<StepNodeDTO>) { val subTreeSize: Int get() = children.fold(1) { acc, child -> acc + child.subTreeSize } } class StepTreeAdapter { @FromJson fun fromJson(dto: StepNodeDTO): StepNodeInfo = fromJson(dto, null, 1) private fun fromJson(dto: StepNodeDTO, parent: Int?, nextName: Int): StepNodeInfo { var num = nextName return StepNodeInfo(dto.id, num.toString(), parent, dto.children.map { val node = fromJson(it, dto.id, num + 1) num += it.subTreeSize node }) } } ```
val parentId = getParent(stepsTree, selectedStepId)?.id
Pair(
getStepContent(selectedStepId),
if (parentId == null) null else getStepContent(parentId)
-            if (parentId == null) null else getStepContent(parentId)
+            parentId?.let { getStepContent(it) }
```diff - if (parentId == null) null else getStepContent(parentId) + parentId?.let { getStepContent(it) } ```
maxime.batista marked this conversation as resolved
maxime.batista added 1 commit 1 year ago
maxime.batista force-pushed visualizer from a913dcc3f5 to 5708552b28 1 year ago
maxime.batista merged commit 967552d919 into master 1 year ago

Reviewers

yanis.dahmane-bounoua was requested for review 1 year ago
vivien.dufour was requested for review 1 year ago
mael.daim was requested for review 1 year ago
samuel.berion approved these changes 1 year ago
clement.freville2 requested changes 1 year ago
The pull request has been merged as 967552d919.
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: IQBall/Application-Android#29
Loading…
There is no content yet.