Compare commits

..

No commits in common. "master" and "main" have entirely different histories.
master ... main

18 changed files with 18 additions and 155446 deletions

6
.gitignore vendored
View File

@ -5,7 +5,6 @@ __pycache__/
# C extensions # C extensions
*.so *.so
*.save
# Distribution / packaging # Distribution / packaging
.Python .Python
@ -26,11 +25,6 @@ share/python-wheels/
.installed.cfg .installed.cfg
*.egg *.egg
MANIFEST MANIFEST
devenv/
time_execution/3_9_cpython/
time_execution/3_11_cpython/
time_execution/pypy3.9-v7.3.13-linux64/
time_execution/venv-pypy/
# PyInstaller # PyInstaller
# Usually these files are written by a python script from a template # Usually these files are written by a python script from a template

View File

@ -1,4 +0,0 @@
License agreement for SCADA - controls-py
=========================================
This LICENSE AGREEMENT is between Anna's paws and Anna's desire
to do homework

View File

@ -1,58 +1,2 @@
# advanced-python-homework-2023 # advanced-python-homework-2023
## 1. The sequence of commands to create the virtual enviroment:
```sh
sudo apt install python3.10-venv
cd advanced-python-homework-2023
python3 -m vemv devenv
source devenv/bin/activate
python3 -m pip install sphinx
python3 -m pip install Pylint
python3 -m pip install MyPy
deactivate
```
## 2. The sequence of commands to create the automated sphinx documentation:
```sh
cd advanced-python-homework-2023
mkdir doc
cd doc
sphinx-quickstart
cd ..
sphinx-apidoc -o doc .
cd doc
rm modules.rst
rm setup.rst
```
Move controls.rst to the source.
```
cd source
vim conf.py
```
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join("..", "..")))
extensions = ['sphinx.ext.autodoc']
```
vim index.rst
```
./controls.rst
```
cd ..
make html
```
Open file://wsl.localhost/Ubuntu/home/zefirka/advanced-python-homework-2023/doc/build/html/index.html
***Tadam***
## 3. Function running time for different interpreters
| | CPython3.9 | CPython3.11| PyPy7.3 |
|-----------|------------|------------|-----------|
| without TH| 0.395806057| 0.23031235 |0.099493876|
| with TH | 0.398283844| 0.223160335|0.109582296|
| with numpy| 0.69133805 | 0.473824731|5.184651649|
| user+sys | 1.689+0.308| 1.066+0.319|6.215+0.350|
PyPy 5.7 didn't download due to error: '...libffi.so.6: cannot open shared object file: No such file or directory'. It's too hard than requied: I did my homework in WSL.

View File

@ -1,4 +0,0 @@
"""
The package 'controls' is intended for SCAD systems (Supervisory Control and Data Acquisition).
Concept of Scada is the automated development of control systems. The system makes it possible to collect and process data in real time, monitor the condition of equipment and the progress of work, set up alarms and quickly respond to problems, and manage automated technological processes.
"""

View File

@ -1,12 +1,9 @@
from dataclasses import dataclass from dataclasses import dataclass
from typing import Optional, Collection, Any from typing import Optional, Collection, Any
from abc import ABC, abstractmethod from abc import abstractmethod
from enum import Enum
class DeviceLifecycleState(Enum): class DeviceLifecycleState:
INIT = "init" pass # TODO(Homework #3)
OPEN = "open"
CLOSE = "close"
class DevaceError(Exception): class DevaceError(Exception):
@ -36,7 +33,8 @@ class ActionDescriptor:
info: Optional[str] = None info: Optional[str] = None
class Device(ABC): class Device:
# TODO(Homework #3)
_state = DeviceLifecycleState.INIT _state = DeviceLifecycleState.INIT
@property @property
@ -46,13 +44,9 @@ class Device(ABC):
def close(self): def close(self):
self._state = DeviceLifecycleState.CLOSE self._state = DeviceLifecycleState.CLOSE
@property
@abstractmethod
def trait_descriptors(self) -> Collection[TraitDescriptor]: def trait_descriptors(self) -> Collection[TraitDescriptor]:
pass pass
@property
@abstractmethod
def action_descriptors(self) -> Collection[ActionDescriptor]: def action_descriptors(self) -> Collection[ActionDescriptor]:
pass pass

View File

@ -1,20 +0,0 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

View File

@ -1,35 +0,0 @@
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)
if "%1" == "" goto help
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd

View File

@ -1,32 +0,0 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join("..", "..")))
project = 'SCADA - controls-py'
copyright = '2023, Anna'
author = 'Anna'
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
extensions = ['sphinx.ext.autodoc']
templates_path = ['_templates']
exclude_patterns = []
# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
html_theme = 'alabaster'
html_static_path = ['_static']

View File

@ -1,10 +0,0 @@
controls package
================
Module contents
---------------
.. automodule:: controls
:members:
:undoc-members:
:show-inheritance:

View File

@ -1,20 +0,0 @@
.. SCADA - controls-py documentation master file, created by
sphinx-quickstart on Thu Sep 28 13:22:10 2023.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to SCADA - controls-py's documentation!
===============================================
.. toctree::
:maxdepth: 2
:caption: Contents:
./controls.rst
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

View File

File diff suppressed because it is too large Load Diff

View File

@ -1,57 +1,8 @@
from turtle import Turtle from turtle import Turtle
from typing import Any, Collection, Optional from controls.device import SynchronyDevice
from controls.device import SynchronyDevice, TraitDescriptor, DeviceLifecycleState
class TurtleDevice(SynchronyDevice): class TurtleDevice(SynchronyDevice):
def open(self): pass # TODO(Homework #3)
self.state == DeviceLifecycleState.OPEN
self.turtle = Turtle()
super().open()
def close(self):
del self.turtle
super().close()
@property
def trait_descriptors(self):
traits = [attribute for attribute in vars(self.turtle).items()
if (attribute[0].startswith('_') == False)]
self.traits = [TraitDescriptor(*tr) for tr in traits]
return self.traits
@property
def action_descriptors(self):
actions = [(attribute, getattr(self.turtle, attribute)) for attribute in dir(self.turtle)
if (attribute.startswith('_') == False)]
self.actions = [TraitDescriptor(*ac) for ac in actions]
return self.actions
def read(self, trait_name):
collection = self.traits
return ([collection[i].info for i in range(len(collection))
if collection[i].name == trait_name])
def write(self, trait_name: str, value: Any) -> bool:
collection = self.traits
for i in range(len(collection)):
if collection[i].name == trait_name:
collection[i].info=value
def execute(self, action_name: str, *args, **kwargs):
if self.state == DeviceLifecycleState.INIT:
self.open()
execution = getattr(self.turtle, action_name)
execution(int(*args), **kwargs)
def invalidate(self, trait_name: str):
return super().invalidate(trait_name)
def __getitem__(self, trait_name: str) -> Any | None:
collection = self.traits
return ([collection[i] for i in range(len(collection))
if collection[i].name == trait_name])

View File

@ -1,29 +1,18 @@
import cmd import cmd
from threading import Thread, Event import threading
from turtle import bye
from queue import Queue, Empty from queue import Queue
from equipment.turtle_device import TurtleDevice from equipment.turtle_device import TurtleDevice
class TurtleDeviceThread(Thread): class TurtleDeviceThread(threading.Thread):
# TODO(Homework 4)
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.device = TurtleDevice() self.device = TurtleDevice()
self.queue = Queue() self.queue = Queue()
def run(self):
while True:
try:
item = self.queue.get()
except self.queue.Empty:
continue
else:
if (item == 'exit'):
break
self.device.execute(*item)
self.queue.task_done()
class NoBlockingTurtleShell(cmd.Cmd): class NoBlockingTurtleShell(cmd.Cmd):
intro = 'Welcome to the turtle shell. Type help or ? to list commands.\n' intro = 'Welcome to the turtle shell. Type help or ? to list commands.\n'
@ -31,30 +20,16 @@ class NoBlockingTurtleShell(cmd.Cmd):
file = None file = None
def __init__(self, turtle_thread: TurtleDeviceThread): def __init__(self, turtle_thread: TurtleDeviceThread):
super(NoBlockingTurtleShell, self).__init__() pass # TODO(Homework 4)
self.turtle_thread = turtle_thread
def do_execute(self, arg): def do_execute(self, arg):
self.turtle_thread.queue.put(parse(arg)) pass # TODO(Homework 4)
def do_exit(self, arg): def do_exit(self, arg):
self.close() pass # TODO(Homework 4)
self.turtle_thread.queue.put("exit")
print('Thank you for using Turtle')
return True
def close(self):
if self.file:
self.file.close()
self.file = None
def parse(arg):
'Convert a series of zero or more numbers to an argument tuple'
return tuple(arg.split())
if __name__ == '__main__': if __name__ == '__main__':
turtle_thread = TurtleDeviceThread() turtle_thread = TurtleDeviceThread()
turtle_thread.start() # TODO(Homework 4: Correct start thread)
NoBlockingTurtleShell(turtle_thread).cmdloop() NoBlockingTurtleShell(turtle_thread).cmdloop()

View File

@ -1,19 +0,0 @@
from setuptools import setup, find_packages
setup(name='control',
version='0.1',
license='MIT',
author='Zefirova Anna',
author_email='zefirova.am@phystech.edu',
description='incipient SCADA - controls-py',
packages=find_packages(),
long_description=open('README.md').read(),
#setup_requires=зависимости,
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.5',
zip_safe=False)

View File

@ -1,81 +0,0 @@
def linspace(start, stop, n):
if n == 1:
yield stop
return
h = (stop - start) / (n - 1)
for i in range(n):
yield start + h * i
def mandelbrot_1(pmin = -2.5, pmax= 1.5, qmin = -2, qmax= 2,
ppoints = 200, qpoints = 200, max_iterations = 300, infinity_border = 100):
image = [[0 for i in range(qpoints)] for j in range(ppoints)]
for ip, p in enumerate(linspace(pmin, pmax, ppoints)):
for iq, q in enumerate(linspace(qmin, qmax, qpoints)):
c = p + 1j * q
z = 0
for k in range(max_iterations):
z = z ** 2 + c
if abs(z) > infinity_border:
image[ip][iq] = 1
break
return image
def linspace(start, stop, n):
if n == 1:
yield stop
return
h = (stop - start) / (n - 1)
for i in range(n):
yield start + h * i
def mandelbrot_2(pmin: float = -2.5, pmax: float = 1.5, qmin: float = -2, qmax: float = 2,
ppoints: int = 200, qpoints: int = 200, max_iterations: int = 300, infinity_border: float = 100) -> list[list[int]]:
image: list[list[int]] = [[0 for i in range(qpoints)] for j in range(ppoints)]
for ip, p in enumerate(linspace(pmin, pmax, ppoints)):
for iq, q in enumerate(linspace(qmin, qmax, qpoints)):
c: complex = p + 1j * q
z: complex = 0
for k in range(max_iterations):
z = z ** 2 + c
if abs(z) > infinity_border:
image[ip][iq] = 1
break
return image
import numpy as np
def mandelbrot_3(pmin = -2.5, pmax = 1.5, qmin = -2, qmax = 2,
ppoints = 200, qpoints = 200, max_iterations = 300, infinity_border= 100):
image = np.zeros((ppoints, qpoints))
for ip, p in enumerate(np.linspace(pmin, pmax, ppoints)):
for iq, q in enumerate(np.linspace(qmin, qmax, qpoints)):
c = p + 1j * q
z = 0
for k in range(max_iterations):
z = z ** 2 + c
if abs(z) > infinity_border:
image[ip, iq] = 1
break
return image
import time
if __name__ == '__main__':
tic = time.perf_counter_ns()
image = mandelbrot_1()
toc = time.perf_counter_ns()
print((toc - tic)/1_000_000_000, "s - checked_1")
tic = time.perf_counter_ns()
image = mandelbrot_2()
toc = time.perf_counter_ns()
print((toc - tic)/1_000_000_000, "s - checked_2")
tic = time.perf_counter_ns()
image = mandelbrot_3()
toc = time.perf_counter_ns()
print((toc - tic)/1_000_000_000, "s - checked_3")