1

I want to find an efficient way to represent the JSON objects below. I made an ERD diagram to represents the JSON objects. This diagram below is a small piece within a much larger structure. There will be at most 10 thousand rows in the main table (InteractiveGraphOptions), so it will not be a huge one.

My questions are:

  1. Is there a way to represent vectors in MySQL other than an individual table?

    Let me give the example of LineSegments. Within an interactive graph, there might be many line segments and each line segment is represented by x and y coordinates. For example, there can be three line segments with coordinates {[(-4, 3.5) (4, -0.5)], [(-5, 6.5) (4.5, 9)], [(-5, -5) (5, -5)]}, each point represents the beginning and end of a line segment and the order of the line segments is important (i.e. {[(-5, 6.5) (4.5, 9)], [(-4, 3.5) (4, -0.5)], [(-5, -5) (5, -5)]} should represent a different set of line segments). To represent these line segments, I created a new table with columns x, y, and coordOrder. So, I'll represent the three line segments above with 6 rows. Is there another way to save coordinates in MySQL reliably? Technically, I can save it as a string object and decompose it programmatically. But this method sounds somewhat prone to error.

  2. My second question is similar to the one above. Whenever I see a vector that has a fixed size I decompose it as columns. Is there a way to save vectors with fixed length?

    For example, labels is the label of the coordinate axes (generally a vector ["x", "y"]). Since all coordinates used here are two dimensional, it's size is fixed. My solution to this is to create two columns label_x and label_y in the main table (InteractiveGraphOptions). Is this the most sane method? Are there any other methods to save this labels variable into database?

    {"labels": [ "x", "y" ] }

  3. Related to the previous questions, is there any way to simplify the database structure below?

enter image description here

JSON object:

{
    "markings": "graph",                    
    "showProtractor": true,
    "showRuler": false,
    "showTooltips": false,
    "rulerLabel": "",
    "rulerTicks": 10,
    "step": [
        1,
        1
    ],
    "backgroundImage": {
        "url": null
    },
    "labels": [
        "x",
        "y"
    ],
    "range": [
        [
            -10,
            10
        ],
        [
            -10,
            10
        ]
    ],
    "gridStep": [
        1,
        1
    ],
    "snapStep": [
        0.5,
        0.5
    ],
    "graph": {
        "type": "polygon",
        "numSides": 5,
        "snapTo": "grid"
    },
    "correct": {
        "type": "polygon",
        "coords": [
            [
                5.5,
                -8
            ],
            [
                4,
                1
            ],
            [
                -4,
                -4.5
            ],
            [
                -6,
                8
            ],
            [
                -7.5,
                -7
            ]
        ],
        "numSides": 5,
        "snapTo": "grid"
    }
}


{
    "markings": "graph",
    "showProtractor": false,
    "showRuler": false,
    "showTooltips": true,
    "rulerLabel": "",
    "rulerTicks": 10,
    "step": [
        1,
        1
    ],
    "backgroundImage": {
        "url": null
    },
    "labels": [
        "x",
        "y"
    ],
    "range": [
        [
            -10,
            10
        ],
        [
            -10,
            10
        ]
    ],
    "gridStep": [
        1,
        1
    ],
    "snapStep": [
        0.5,
        0.5
    ],
    "graph": {
        "type": "quadratic"
    },
    "correct": {
        "type": "quadratic",
        "coords": [
            [
                -6,
                2.5
            ],
            [
                1.5,
                1
            ],
            [
                5,
                5
            ]
        ]
    }
}


{
    "markings": "grid",
    "showProtractor": false,
    "showRuler": true,
    "showTooltips": false,
    "rulerLabel": "",
    "rulerTicks": 10,
    "step": [
        1,
        1
    ],
    "backgroundImage": {
        "url": null
    },
    "labels": [
        "x",
        "y"
    ],
    "range": [
        [
            -10,
            10
        ],
        [
            -10,
            10
        ]
    ],
    "gridStep": [
        1,
        1
    ],
    "snapStep": [
        0.5,
        0.5
    ],
    "graph": {
        "type": "angle",
        "showAngles": true
    },
    "correct": {
        "type": "angle",
        "coords": [
            [
                0.8581143926302237,
                -0.6058011676632082
            ],
            [
                0,
                5.5
            ],
            [
                -7.245121074324528,
                5.753005202976288
            ]
        ],
        "showAngles": true,
        "match": "congruent"
    }
}


{
    "type": "interactive-graph",
    "alignment": "default",
    "static": false,
    "graded": true,
    "options": {
        "step": [
            1,
            1
        ],
        "backgroundImage": {
            "url": null
        },
        "markings": "graph",
        "labels": [
            "x",
            "y"
        ],
        "showProtractor": false,
        "showRuler": false,
        "showTooltips": false,
        "rulerLabel": "",
        "rulerTicks": 10,
        "range": [
            [
                -10,
                10
            ],
            [
                -10,
                10
            ]
        ],
        "graph": {
            "type": "circle"
        },
        "correct": {
            "type": "circle",
            "center": [
                -1.5,
                2
            ],
            "radius": 5
        }
    }
}


{
    "type": "interactive-graph",
    "alignment": "default",
    "static": false,
    "graded": true,
    "options": {
        "step": [
            1,
            1
        ],
        "backgroundImage": {
            "url": null
        },
        "markings": "graph",
        "labels": [
            "x",
            "y"
        ],
        "showProtractor": false,
        "showRuler": false,
        "showTooltips": false,
        "rulerLabel": "",
        "rulerTicks": 10,
        "range": [
            [
                -10,
                10
            ],
            [
                -10,
                10
            ]
        ],
        "graph": {
            "type": "ray"
        },
        "correct": {
            "type": "ray",
            "coords": [
                [
                    5.5,
                    -2.5
                ],
                [
                    -4.5,
                    5
                ]
            ]
        }
    }
}

{
    "type": "interactive-graph",
    "alignment": "default",
    "static": false,
    "graded": true,
    "options": {
        "step": [
            1,
            1
        ],
        "backgroundImage": {
            "url": null
        },
        "markings": "graph",
        "labels": [
            "x",
            "y"
        ],
        "showProtractor": false,
        "showRuler": false,
        "showTooltips": false,
        "rulerLabel": "",
        "rulerTicks": 10,
        "range": [
            [
                -10,
                10
            ],
            [
                -10,
                10
            ]
        ],
        "graph": {
            "type": "sinusoid"
        },
        "correct": {
            "type": "sinusoid",
            "coords": [
                [
                    0.5,
                    -2
                ],
                [
                    4.5,
                    3.5
                ]
            ]
        }
    }
}


{
    "type": "interactive-graph",
    "alignment": "default",
    "static": false,
    "graded": true,
    "options": {
        "step": [
            1,
            1
        ],
        "backgroundImage": {
            "url": null
        },
        "markings": "graph",
        "labels": [
            "x",
            "y"
        ],
        "showProtractor": false,
        "showRuler": false,
        "showTooltips": false,
        "rulerLabel": "",
        "rulerTicks": 10,
        "range": [
            [
                -10,
                10
            ],
            [
                -10,
                10
            ]
        ],
        "graph": {
            "type": "segment",
            "numSegments": 4
        },
        "correct": {
            "type": "segment",
            "numSegments": 4,
            "coords": [
                [
                    [
                        0.5,
                        -7.5
                    ],
                    [
                        6,
                        9
                    ]
                ],
                [
                    [
                        -5.5,
                        -9
                    ],
                    [
                        5,
                        2
                    ]
                ],
                [
                    [
                        -8,
                        -2.5
                    ],
                    [
                        -7,
                        -7
                    ]
                ],
                [
                    [
                        5.5,
                        -7.5
                    ],
                    [
                        7.5,
                        -5
                    ]
                ]
            ]
        }
    }
}   

When building an assessment test, these parameters will be send to the plugin here to construct a question. Later, student response from the plugin will be compared to the Coordinates in the database to determine whether the response is correct or not.

  • 1
    How is this data going to be searched? – Michael Kutz Sep 19 '18 at 21:28
  • The database model shown above will be a part of a larger AssessmentQuestion model. I've edited my question above to describe how it will be used at the end. (The plugin link was long and comment did not allow me to insert it). – HBat Sep 20 '18 at 14:14
  • Will the math be done in SQL? Or in some app language? Or the plugin? If the plugin, what structure does it require? – Rick James Oct 8 '18 at 2:34
  • ​​Math will be done in Python, for example, summarizing common mistakes​ or checking whether an answer is correct​. Some part of it will​/may​ be done by the plug-in, like checking whether an answer is correct​ but I haven't figured out how to do that using plugin yet. ​ – HBat Oct 8 '18 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.