Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PL Graph Constructor #20

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b2a0c67
Initialize bugfix-ci-workflow-update
chris-rau Sep 30, 2024
320a187
Initial question for testing things
chris-rau Sep 30, 2024
c6c2f28
added element files
eldarh079 Oct 24, 2024
0d19b96
bug solved
eldarh079 Oct 24, 2024
798f667
Fixed fsm tool
chris-rau Oct 24, 2024
a9f023c
added DOT passing to backend (grade)
eldarh079 Oct 25, 2024
889b53e
Added configuration to code (not displayed correctly yet)
chris-rau Oct 28, 2024
2ee22f6
Fixed drawing of undirected and non-selflink graphs
chris-rau Oct 28, 2024
38e9001
added canvas clear for each session
eldarh079 Oct 28, 2024
cc30c6e
Added configurability via XML element
chris-rau Nov 3, 2024
a21c60a
Added configuration options for multigraphs and node marking
chris-rau Nov 3, 2024
1103b40
added autograding and new questions
eldarh079 Nov 4, 2024
05dd6ac
Fixed graph constuction bugs (no selflink; no direced edges in both d…
chris-rau Nov 10, 2024
774f19d
done
eldarh079 Nov 13, 2024
856d76c
assessment done
eldarh079 Nov 13, 2024
f7dfb94
instructions changed
eldarh079 Nov 16, 2024
710105e
Fixed bug for question 5 grading
chris-rau Nov 16, 2024
796bb16
Merge branch 'bugfix-ci-workflow-update' of github.com:chris-rau/star…
chris-rau Dec 6, 2024
589850a
Added clear button
chris-rau Dec 6, 2024
358bb2a
Added answers-name
chris-rau Dec 6, 2024
9f7cc1f
Made answers-name save graph in local storage
chris-rau Dec 6, 2024
99f8055
added grading helpers and parse attribute
eldarh079 Dec 7, 2024
8ea9845
cursor changes on shift now
eldarh079 Dec 7, 2024
75b5b9f
Moved new graph parsing function into helper function section
chris-rau Dec 7, 2024
8e5cf64
Added screenshots
chris-rau Dec 7, 2024
17d9ec6
Create README.md
eldarhasanov079 Dec 7, 2024
5eb5a65
resolved
eldarh079 Dec 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed clientFilesCourse/student_images/.002.png.icloud
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"uuid": "7046c3d0-567a-4e1d-a352-ce82d031f7ab",
"type": "Homework",
"title": "Graph Creation Examples",
"set": "Homework",
"number": "1",
"allowAccess": [],
"zones": [
{
"comment": "These are new questions created for the pl-interactive-graph element",
"questions": [

{
"id": "Graph-Construction-Q1",
"autoPoints": 1
},

{
"id": "Graph-Construction-Q2",
"autoPoints": 1
},

{
"id": "Graph-Construction-Q3",
"autoPoints": 1
},

{
"id": "Graph-Construction-Q4",
"autoPoints": 1
},

{
"id": "Graph-Construction-Q5",
"autoPoints": 1
}

]

}
]
}
18 changes: 18 additions & 0 deletions courseInstances/GraphConstructor/infoCourseInstance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"uuid": "A4C7C4DF-9FF6-493E-BA61-7EB054B97B64",
"longName": "Graph Constructor",
"allowAccess": [
{
"institution": "LTI",
"startDate": "2023-10-23T00:00:01",
"endDate": "2024-06-01T23:59:59"
},
{
"institution": "Any",
"startDate": "2023-10-23T00:00:01",
"endDate": "2024-06-01T23:59:59",
"uids": [
]
}
]
}
122 changes: 122 additions & 0 deletions elements/pl-graph-constructor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# pl-graph-constructor for PrairieLearn

## Overview
`pl-graph-constructor` is a custom interactive element for PrairieLearn which enables students to construct graphs in a drag-and-drop interface and converts the student-entered graph into a DOT-language form to facilitate autograding.

## Description
The element provides the student with an empty canvas in which they will construct a graph. This graph can either be graded using pre- or self-defined methods, or the canvas can serve as a sketching element for the student.

In either case, a student can create nodes simply by clicking on the location at which they want to create the node. Edges can be created by selecting the node at which the edge originates and dragging toward the next node. There is a detailed description of tool usage for students under each instance of the Graph Constructor.

## Usage

### 1. Include the Element in Your Question
Embed the custom element tag `<pl-graph-constructor>` in your question HTML file. The XML should look like this:

```xml
<pl-graph-constructor
answers-name="graph_input1"
directed="true"
allow-selflinks="true"
multigraph="true"
allow-nodemarking="true"
parser="dot">
</pl-graph-constructor>
```


### 2. Set Attributes
Customize the behavior and appearance of the element using XML attributes. The element supports a variety of attributes to cater to different question types and requirements:

- `answers-name`: **String**. Specifies the name associated with the PL Graph Creator instance. This will be included as the graph name in the exported DOT-string. Therefore, only alphanumeric characters and underscores are allowed.
- `directed`: **Boolean**. Specify whether the graph a student draws is directed or undirected.
- `parser`: **String**. Specify how the student graph is received in the `server.py`. Defaults to:
- `"dot"`: Get the [DOT code](https://graphviz.org/doc/info/lang.html) of the submitted graph.
- `"dict"`: Receive a string version of a tuple dictionary, explaining the structure of the submitted graph. Example:
```python
dict_values(['A', 'B', 'C', 'B']), {('C', 'A', '2'), ('C', 'B', '3')}
```
- `allow-selflinks`: **Boolean**. Specifies whether the graph a student draws can have an edge (a link) between a node and itself. Default: `true`.
- `multigraph`: **Boolean**. Specifies whether the graph a student draws can have multiple edges (links) between the same two nodes. If true, this is allowed; if false, at most one edge can be between each pair of nodes. Default: `true`.
- `allow-nodemarking`: **Boolean**. Specifies whether students can mark nodes in the graph by double-clicking a node. These nodes will appear as having a doubled boundary. Default: `true`.

### 3. Add a `server.py` File
Determine how you want to grade the question.

- If you are using the `"dot"` parser, receive your graph's DOT code using:
```python
student_dot = data['submitted_answers'].get('graphData', '')
```
- If you choose to use the `"dict"` parser, you will already have a preprocessed version of the graph to work with.

We strongly recommend checking out our **"Study question 0: Tutorial"** in the `Graph-Construction-Q1` folder for the `server.py`. It contains two very useful helpers you can use in your grading:

#### 1. `parse_dot`
- A function that takes the DOT code of the graph and parses it into the `"dict"` form.
- This makes it easier to grade for specific structural parts of the graph or identify desired properties.

#### 2. `graph_distance`
- A function that takes two `"dict"`-formatted graphs and returns multiple useful difference metrics, such as:
- **`node_diff`**: Number of different nodes.
- **`edge_diff`**: Number of different edges.
- **`edge_mismatch`**: Number of edge label mismatches.
- **`node_label_mismatch`**: Number of node label mismatches.
- **`total_distance`**: Total of all differences between the two graphs (useful for evaluating overall similarity).

#### Recommended Use
- Use `parse_dot(student_dot)` or the direct `"dict"` form of the student’s graph alongside the `"dict"` form of the correct graph in `graph_distance` to calculate how far the student is from the correct answer.
- Alternatively, we recommend using the [NetworkX Python library](https://networkx.org/) or your preferred graph library for more complex grading schemes. Many libraries provide advanced tools to manipulate or evaluate graphs, catering to specific needs.

---

## Project Progress Slide Deck
For detailed updates on this tool's development, check out our [Project Progress Slide Deck](https://docs.google.com/presentation/d/1SkArctLa5vL14UhI9kjoltAFjjmip4KYLXfPLw8k4Ho/edit?usp=sharing).

---

## Potential Applications in UC Berkeley Courses
The PL Graph Creator is a versatile tool applicable to various graph-related topics in UC Berkeley's curriculum. Below are some classes and topics where this tool can provide significant value:

### CS 170 (Efficient Algorithms and Intractable Problems)
Dive into advanced topics like BFS, DFS, MSTs, planar graph analysis, graph coloring, strongly connected components (SCCs), network flows, and bipartite matching.

### CS 61B (Data Structures)
Explore foundational graph algorithms like Breadth-First Search (BFS), Depth-First Search (DFS), Minimum Spanning Trees (MSTs), and Weighted Quick Union.

### CS 70 (Discrete Mathematics and Probability Theory)
Facilitate graph proofs, study Markov Chains, analyze planar graphs, and construct hypercubes.

### CS 61C (Machine Structures)
Design Finite State Machines (FSMs) and Sequential Digital Systems (SDSs).

This list represents just a fraction of the potential applications. The PL Graph Creator is highly adaptable and can support any graph-like structures, making it a valuable tool for a wide range of scenarios.

---

## Example Questions
The `questions` folder includes a variety of example questions for reference:

- **Graph-Construction-QX**
A series of questions (`X` ranges from 1 to 5) used during our studies, showcasing the tool's core functionality.

- **SCC and Residual-Graph**
Advanced examples based on real CS 170 discussion questions, demonstrating the tool's application in complex scenarios such as strongly connected components (SCCs) and residual graph construction.

## Expected Outcome

Below is a screenshot demonstrating the expected outcome of running the `Graph-Construction-Q1`. This includes the following XML configuration:

```xml
<pl-graph-constructor
answers-name="graph_input1"
directed="true"
allow-selflinks="true"
multigraph="true"
allow-nodemarking="true">
</pl-graph-constructor>
```

[Expected Output](../../questions/Graph-Construction-Q1/Q1.png)



7 changes: 7 additions & 0 deletions elements/pl-graph-constructor/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"controller": "pl-graph-constructor.py",
"dependencies": {
"elementScripts": ["pl-graph-constructor.js"],
"elementStyles": ["pl-graph-constructor.css"]
}
}
11 changes: 11 additions & 0 deletions elements/pl-graph-constructor/pl-graph-constructor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#fsm-canvas {
border: 1px solid #ccc;
cursor: crosshair;
position: relative;
z-index: 0;
}

#clear-fsm {
position: relative;
z-index: 1;
}
Loading