ImperialCollegeLondon / ImperialCollegeLondon/ReCoDE-PythonGUI

New Feedback for Day 2

Open
#4 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2
Forks
1
PR merge metrics
No merged PRs in 30d

Description

#### Readme

Good explanations now of what is going on and what to expect. But:

- [x] You are using `numpy` but there are no explanations on how to install it.

#### Python_GUI_day2_simple.py

- [x] You use `numpy` yet you do not exploit its capabilities in the code. For example, the following is way shorter, cleaner and efficient that your loop when updating the series:

```python
def update_series(j):
"""Include explanation here"""
x = np.arange(500) / 1000
y = 0.5 + 0.5 * np.cos(50 * (x + j/1000))
dpg.set_value(SERIAL_TAG, [x, y])
dpg.set_item_label(SERIAL_TAG, "0.5 + 0.5 * cos(x)")
```

If, for some reason, `set_value` needs lists, just do `dpg.set_value(SERIAL_TAG, [list(x), list(y)])`.

- [x] `plt.plot` is a `matplotlib` command, but you do not mention this library at all. Either remove this comment or explain what `matplotlib` is about.
- [x] With `matplotlib` you can also create dynamic plots easily. Check [Animated line plot — Matplotlib 3.7.1 documentation](https://matplotlib.org/stable/gallery/animation/simple_anim.html#sphx-glr-gallery-animation-simple-anim-py)
- [x] There is code duplication, when creating the data. I would suggest to extract that function as something independent:

```python
def create_data(j=0):
"""Include explanation here"""
x = np.arange(500) / 1000
y = 0.5 + 0.5 * np.cos(50 * (x + j/1000))
return x, y
```

And then use it when updating the series and when creating the plot initially:

```python
def update_series(j):
"""Include explanation here"""
x, y = create_data(j)
dpg.set_value(SERIAL_TAG, [x, y])
dpg.set_item_label(SERIAL_TAG, "0.5 + 0.5 * cos(x)")
```

```python
def create_window():
"""Include explanation here"""
with dpg.window(label="Window1", tag="win"):
# create plot
with dpg.plot(label="Line Series", height=300, width=600):
# some extra code in here
...
x, y = create_data()
dpg.add_line_series(cosdatax, cosdatay, parent="y_axis", tag=SERIAL_TAG)
```

- [x] Breakdown the big function into smaller chunks, as done in the code for Day 1. I've already given you a few hints in the previous point.
- [x] The main loop should be in its own function, which will be the equivalent to `dpg.start_dearpygui`.

#### Python_GUI_day2_file.py

- [x] Use a context manager to load the data, which closes the file after reading it:

```python
with open(filename, 'rb') as datafile:
data = np.fromfile(datafile, np.dtype('int16'))
```

- [x] Use `numpy` properly, given that you have it. For example:
- [x] to select the data with appropriate indexing:`IPC = (data[2::3] + 5) / 84.0552`
- [x] to select the appropriate data in `update_series`
- [x] Breakdown the big function into smaller chunks, as done above

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the README, Python_GUI_day2_simple.py, and Python_GUI_day2_file.py, starting with their large functions, update_series, create_window, and the main loop. Done means the repeated data creation is extracted, NumPy operations and file context management are used as described, functions are split into smaller units, and the README explains NumPy and matplotlib.

Written by the indexing model from the issue text.

Assessment

Tech stack
matplotlib, numpy, python
Domain
data, desktop
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.