-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
38 lines (24 loc) · 970 Bytes
/
model.py
File metadata and controls
38 lines (24 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""Model implementation for Matplotlib example."""
from enum import Enum
import numpy as np
from pydantic import BaseModel, Field
class FunctionOptions(str, Enum):
"""Enum defining a list of options for a Pydantic field."""
cosine = "cos"
sine = "sin"
class PlotData(BaseModel):
"""Pydantic model definition."""
data_points: int = Field(default=0, ge=0, title="Number of Data Points")
function: FunctionOptions = Field(default=FunctionOptions.cosine, title="Function")
class Model:
"""Model implementation for Matplotlib example."""
def __init__(self) -> None:
self.plot_data = PlotData()
def get_data(self) -> np.ndarray:
data = np.radians(np.mod(np.arange(self.plot_data.data_points), 360))
match self.plot_data.function:
case FunctionOptions.cosine:
return np.cos(data)
case FunctionOptions.sine:
return np.sin(data)
return data