Fix issues, add readme
This commit is contained in:
parent
d85a56f97c
commit
ede1de68e3
22
README.md
Normal file
22
README.md
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Коллекция скриптов для ТВиМС
|
||||||
|
|
||||||
|
Запускать `main.py`
|
||||||
|
|
||||||
|
Пример:
|
||||||
|
```bash
|
||||||
|
./main.py --help
|
||||||
|
```
|
||||||
|
|
||||||
|
### random_table
|
||||||
|
Генерирует массив случайных чисел, создаёт таблицу Word и список для вставки в скрипт Python.
|
||||||
|
|
||||||
|
Генерировать массив из 200 случайных целых чисел, размер таблицы Word 20x10.
|
||||||
|
```bash
|
||||||
|
./main.py random_table
|
||||||
|
```
|
||||||
|
|
||||||
|
Генерировать массив из 17 случайных вещественных чисел от -5 до 5 включительно,
|
||||||
|
таблицу разбить на 10 столбцов
|
||||||
|
```bash
|
||||||
|
./main.py random_table --rtype float --min -5 --max 5 --cols 5 --count 17
|
||||||
|
```
|
||||||
12
main.py
12
main.py
@ -29,16 +29,16 @@ def cli():
|
|||||||
default="./result/table.docx")
|
default="./result/table.docx")
|
||||||
@click.option("--py", type=click.Path(dir_okay=False, writable=True, resolve_path=True, allow_dash=True),
|
@click.option("--py", type=click.Path(dir_okay=False, writable=True, resolve_path=True, allow_dash=True),
|
||||||
default="./result/table.py")
|
default="./result/table.py")
|
||||||
@click.argument("size", type=int, default=200)
|
@click.option("--count", type=int, default=200)
|
||||||
def random_table(rtype, seed, prec, min, max, cols, docx, py, size):
|
def random_table(rtype, seed, prec, min, max, cols, docx, py, count):
|
||||||
random.seed(seed)
|
random.seed(seed)
|
||||||
|
|
||||||
rows = size // cols
|
rows = count // cols
|
||||||
if size % cols > 0:
|
if count % cols > 0:
|
||||||
rows += 1
|
rows += 1
|
||||||
|
|
||||||
rfunc = RFUNC[rtype]
|
rfunc = RFUNC[rtype]
|
||||||
array = [round(rfunc(min, max), prec) for _ in range(size)]
|
array = [round(rfunc(min, max), prec) for _ in range(count)]
|
||||||
|
|
||||||
with click.open_file(py, "w") as f:
|
with click.open_file(py, "w") as f:
|
||||||
print(array, file=f)
|
print(array, file=f)
|
||||||
@ -48,6 +48,8 @@ def random_table(rtype, seed, prec, min, max, cols, docx, py, size):
|
|||||||
n = 0
|
n = 0
|
||||||
for i in range(rows):
|
for i in range(rows):
|
||||||
for j in range(cols):
|
for j in range(cols):
|
||||||
|
if n >= count:
|
||||||
|
break
|
||||||
table.rows[i].cells[j].text = str(array[n])
|
table.rows[i].cells[j].text = str(array[n])
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user