-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogic.py
136 lines (124 loc) · 6.76 KB
/
logic.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
from graphic_explan.dictonary import dictonary
from math import *
from mathematics.price import PriceCalculator
from mathematics.UFG import UFG
from mathematics.calculators import cutting_mode, angle_decimal
from mathematics.dxf import TextEngraving
user = {}
class User():
def __init__(self, user_id):
self.user_id = user_id
self.number_dict = {"number": -1}
self.conditions = {'cycle_calc': []}
self.variable = dict()
self.document = "% \nO0001 \n"
self.workpiece = {"profile": None, "alloy": None,
"size": None, "length": None,
"wall_thickness": float()}
self.text_engraving = {"fonts": 0, "text_content": None, "text_position": (0, 0),
"text_alignments": 1, "text_size": 3, "angle": 0,
"shag": 1, 'oblique': 15, "text_circle" : 0}
def data_generator(user_id, cicle, argument):
"""Функция получает от пользователя необходимые данные для дальнейшей работы с ними"""
"""И отправляет результат пользователю"""
if cicle == "engraving":
user[user_id].number_dict['number']+=1
number = user[user_id].number_dict['number']
if number < len(dictonary[cicle])+1:
if number < len(dictonary[cicle]):
user[user_id].text_engraving[list(user[user_id].text_engraving)[number-1]] = argument
if number <= len(dictonary[cicle])-1:
return dictonary[cicle][number][0], dictonary[cicle][number][1]
elif number == len(dictonary[cicle]):
graving = TextEngraving(user[user_id].text_engraving)
with open("O0001.nc", "w") as file:
file.write(str(graving))
return f'Проверьте результат, Перенесите этот файл на флешку 👆', 2
else:
return "Цикл завершен, выберите следующий цикл! 👍", None
if cicle in list(dictonary["part_price"]):
user[user_id].number_dict['number']+=1
number = user[user_id].number_dict['number']
if number < len(dictonary["part_price"][cicle])+1:
if number == 0:
user[user_id].workpiece[list(user[user_id].workpiece)[number]] = cicle
elif number > 0:
user[user_id].workpiece[list(user[user_id].workpiece)[number]] = argument
if number <= len(dictonary["part_price"][cicle])-1:
return dictonary["part_price"][cicle][number][0], dictonary["part_price"][cicle][number][1]
elif number == len(dictonary["part_price"][cicle]):
price = PriceCalculator(user[user_id].workpiece["profile"],
user[user_id].workpiece["alloy"],
user[user_id].workpiece["size"],
user[user_id].workpiece["length"],
user[user_id].workpiece["wall_thickness"])
return f'{price}', None
else:
return "Цикл завершен, выберите следующий цикл! 👍", None
else:
try:
float(argument)
except:
return 'Введите число! 🤯', None
user[user_id].number_dict['number']+=1
number = user[user_id].number_dict['number']
if number > 0:
user[user_id].variable.update({f'#{number}': float(argument)})
if len(dictonary[cicle]) -1 >= user[user_id].number_dict['number']:
if len(dictonary[cicle][number]) == 2:
return dictonary[cicle][number][0], dictonary[cicle][number][1]
else:
return dictonary[cicle][number], None
elif len(dictonary[cicle]) == user[user_id].number_dict['number']:
if cicle == "cutting_mode":
den = cutting_mode(user[user_id].variable["#1"],
user[user_id].variable["#2"],
user[user_id].variable["#3"],
user[user_id].variable["#4"])
return f'{den}', None
elif cicle == "degrees_decimal":
den = angle_decimal(user[user_id].variable["#1"],
user[user_id].variable["#2"],
user[user_id].variable["#3"],
user[user_id].variable["#4"])
return f'{den}', None
elif cicle == "UFG":
den = UFG(float(user[user_id].variable["#1"]),
float(user[user_id].variable["#2"]))
return f"{den}", None
elif (cicle == "round_pocket"
) or (cicle == "rectangular_pocket"
) or (cicle == "radius_pocket"
) or (cicle == "milling _plane"
) or (cicle == "conical_thread"
) or (cicle == "finishing_rectangular_pocket"
) or (cicle == "finishing_round_pocket"
) or (cicle == "thread_milling"):
for key, value in user[user_id].variable.items():
user[user_id].document += f'{key} = {value} \n'
if cicle == "round_pocket":
action = "KK"
elif cicle == "rectangular_pocket":
action = "PK"
elif cicle == "radius_pocket":
action = "RK"
elif cicle == "milling _plane":
action = "FP"
elif cicle == "conical_thread":
action = "KR"
elif cicle == "finishing_rectangular_pocket":
action = "SHPK"
elif cicle == "finishing_round_pocket" :
action = "SHKK"
elif cicle == "thread_milling" :
action = "FR"
with open(f"telegram_bot/file_document/{action}.txt", "r", encoding="utf-8") as pk:
info = pk.read()
new_code = open("O0001.nc", "w")
new_code.write(user[user_id].document)
with open("O0001.nc", "a") as new_code:
new_code.write(info)
user[user_id].document
return f'Перенесите этот файл на флешку 👆', 1
else:
return "Цикл завершен, выберите следующий цикл! 👍", None