Skip to content

Commit

Permalink
fix: fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich committed Apr 8, 2024
1 parent 496686e commit d46da98
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
- uses: xanderhendriks/[email protected]
with:
project-path: '.'
project-target: './Debug'
project-target: '.'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# light-detector

[![Build](https://github.com/YarikRevich/ResourceTracker/actions/workflows/build.yml/badge.svg)](https://github.com/YarikRevich/ResourceTracker/actions/workflows/build.yml)
[![Build](https://github.com/YarikRevich/light-detector/actions/workflows/build.yml/badge.svg)](https://github.com/YarikRevich/light-detector/actions/workflows/build.yml)
![STM32](https://img.shields.io/badge/stm32-blue)
[![StandWithUkraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)

Expand Down
32 changes: 24 additions & 8 deletions Scripts/cli/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# CLI

[![Build](https://github.com/YarikRevich/ResourceTracker/actions/workflows/build.yml/badge.svg)](https://github.com/YarikRevich/ResourceTracker/actions/workflows/build.yml)
![Linux](https://img.shields.io/badge/Linux-FCC624?style=for-the-badge&logo=linux&logoColor=black)
![MacOS](https://img.shields.io/badge/MacOS-8773f5?style=for-the-badge&logo=macos&logoColor=black)
[![StandWithUkraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)
Expand Down Expand Up @@ -30,12 +29,12 @@ In order to build the project it's required to execute the following command. It
make install
```

# Use cases
# Use Cases

Most of the commands given below require **baud rate**. It is important to be the exact-supported value,
otherwise requests will be ignored(in the given examples baud rate is equal to **9600**).

## Get available devices
## Get Available Devices

The example below shows how to retrieve a set of all available devices, which can be used to perform other operations.
```shell
Expand All @@ -49,7 +48,7 @@ $ light-detector-cli get_available_devices
]
```

## Get info
## Get Info

The examples below show all the possible ways to retrieve metadata information from the board. Baud rate is important to be the exact-supported value,
otherwise requests will be ignored(in the given examples baud rate is equal to **9600**).
Expand All @@ -73,7 +72,7 @@ Available **gain** values:
* 32 - high
* 48 - max

### Integral time
### Integral Time

The next example shows how to retrieve the value of integral time metadata information from the board.
```shell
Expand All @@ -94,7 +93,7 @@ Available **integral time** values:
* 4 - 500ms
* 5 - 600ms

### Processed requests
### Processed Requests

The next example shows how to retrieve the value of processed requests(amount of successful incoming requests, different from nonce) metadata information from the board.
```shell
Expand All @@ -107,7 +106,7 @@ instance(RetrievedInfoDto):
value: 20
```

### Device available
### Device Available

The next example shows how to retrieve the value of device available metadata information from the board.
```shell
Expand Down Expand Up @@ -183,4 +182,21 @@ parameters.
$ light-detector-cli get_data --device="/dev/cu.usbmodem1203" --baud_rate="9600" --type="raw" --series=4 --export="./output" --figure="plot"

...
```
```

Available **figure** values:
* plot
* stairs
* scatter

#### Plot

![](./docs/examples/get-data-plot.png)

#### Stairs

![](./docs/examples/get-data-stairs.png)

#### Scatter

![](./docs/examples/get-data-scatter.png)
Binary file added Scripts/cli/docs/examples/get-data-plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Scripts/cli/docs/examples/get-data-scatter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Scripts/cli/docs/examples/get-data-stairs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Scripts/cli/src/command/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_data(device: str, baud_rate: int, type: str, series: int = 1, export: st
"""
Returns sensor data of selected type. The available data types are 'raw', 'full', 'infrared', 'visible'.
Allows to perform a series of measurements and export that data to a graph view. The available figure types are
'scatter' and 'bar'.
'scatter', 'plot', 'stairs' and 'bar'.
"""

GetDataCommand.handle(device, baud_rate, type, series, export, generate, figure)
Expand Down
12 changes: 8 additions & 4 deletions Scripts/cli/src/command/get_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from visualizer import Visualizer

from dto import RetrievedDataDto
from dto import VisualizerMetadataDto
from client import Client
from tools import print_output

Expand Down Expand Up @@ -50,18 +51,21 @@ def handle(device: str, baud_rate: int, type: str, series: int, export: str, gen
logging.info("Data has been successfully retrieved.")

if series > 1 and is_export_valid(export):
visualizer = Visualizer(export, data)
visualizer = Visualizer(
export,
data,
VisualizerMetadataDto(type, series))

match figure:
case Visualizer.SCATTER_FIGURE:
visualizer.select_scatter()

case Visualizer.BAR_FIGURE:
visualizer.select_bar()

case Visualizer.PLOT_FIGURE:
visualizer.select_plot()

case Visualizer.STAIRS_FIGURE:
visualizer.select_stairs()

case _:
logging.error("Given figure type is not valid.")
return
Expand Down
2 changes: 2 additions & 0 deletions Scripts/cli/src/dto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@

from .set_settings_dto import SettingsTypeCompound
from .set_settings_dto import SetSettingsDto

from .visualizer_metadata_dto import VisualizerMetadataDto
12 changes: 12 additions & 0 deletions Scripts/cli/src/dto/visualizer_metadata_dto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class VisualizerMetadataDto:
"""Represents dto used to hold the metadata for visualizer."""

# Represents data type of the received result.
data_type: str

# Represents series of measurements to receive the result.
series: int

def __init__(self, data_type: str, series: int):
self.data_type = data_type
self.series = series
3 changes: 3 additions & 0 deletions Scripts/cli/src/middleware/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def is_device_available(device: str) -> bool:
def is_export_valid(src: str) -> bool:
"""Checks if the given export path is valid and can be used for diagram generation."""

if src is None:
return False

return not os.path.isfile(src)


Expand Down
37 changes: 29 additions & 8 deletions Scripts/cli/src/visualizer/visualizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import matplotlib.pyplot as plt

from dto import RetrievedDataDto
from dto import VisualizerMetadataDto


class Visualizer:
Expand All @@ -9,44 +10,64 @@ class Visualizer:
# Represents 'scatter' type of plot.
SCATTER_FIGURE = "scatter"

# Represents 'bar' type of plot.
BAR_FIGURE = "bar"

# Represents 'plot' type of plot.
PLOT_FIGURE = "plot"

# Represents 'stairs' type of plot.
STAIRS_FIGURE = "stairs"

# Represents a path where generated visualization will be saved.
location: str

# Represents a collection of values used for visualization generation.
values: list[RetrievedDataDto]

# Represents metadata used for diagram drawing.
metadata: VisualizerMetadataDto

# Represents a base plot figure.
figure: plt.Figure

def __init__(self, location: str, values: list[RetrievedDataDto]):
def __init__(self, location: str, values: list[RetrievedDataDto], metadata: VisualizerMetadataDto):
self.location = location
self.values = values
self.metadata = metadata

self.figure = plt.figure()

def select_scatter(self) -> None:
"""Selects scatter figure as the output visualization type."""

pass
plot = self.figure.add_subplot(111)

data = [value.value for value in self.values]

plot.scatter(data[:-1], data[1:], s=100, alpha=0.5)

def select_bar(self) -> None:
"""Selects bar figure as the output visualization type."""
plt.title(f'series = {self.metadata.series}; data type = {self.metadata.data_type}')
plt.ylabel("Light value")
plt.xlabel("Light value")

pass
def select_stairs(self) -> None:
"""Selects stairs figure as the output visualization type."""

plot = self.figure.add_subplot(111)
plot.stairs([value.value for value in self.values], linewidth=1)

plt.title(f'series = {self.metadata.series}; data type = {self.metadata.data_type}')
plt.ylabel("Light value")
plt.xlabel("Amount of measurements")

def select_plot(self) -> None:
"""Selects plot figure as the output visualization type."""

plot = self.figure.add_subplot(111)
plot.plot([value.value for value in self.values])

plt.title(f'series = {self.metadata.series}; data type = {self.metadata.data_type}')
plt.ylabel("Light value")
plt.xlabel("Amount of measurements")

def save(self) -> None:
"""Saves select figure in the given location."""

Expand Down

0 comments on commit d46da98

Please sign in to comment.