- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
def loadDevices(list_devices, db_name, db_user, db_host, db_password):
"""Загрузка устройств из базы данных"""
psql = ClassPSQL(db_name, db_user, db_host, db_password, db_port)
for group in psql.get("SELECT * FROM user_groups"):
group_id, _, _, available_devices = group
if (group_id != 0) and (available_devices != None):
for device in parceDeviceStr(available_devices):
if (findDevice(list_devices, int(device)) == None):
local_res= psql.get("SELECT * FROM device WHERE logic_id=" + str(device))
if len(local_res):
dev_id, _, port = local_res[0]
list_devices.append(ClassDevice(int(device), str(dev_id), int(port)))
findDevice(list_devices, int(device)).addGroupID(int(group_id))
else:
findDevice(list_devices, int(device)).addGroupID(int(group_id))
for device in psql.get("SELECT * FROM sm_devs"):
dev_id, logic_id, port = device
if (findDevice(list_devices, int(logic_id)) == None):
list_devices.append(ClassDevice(int(logic_id), str(dev_id), int(port)))
list_devices = sorted(list_devices, key=lambda device: device.getLogicID())
return list_devices
------------------------------------------
class ClassGroupDevices(object):
... много методов ...
def save(self):
"""Сохранение группы устройств в postgres"""
str_logic_ids = ""
for logic_id in self.getLogicIDs():
if (len(str_logic_ids) > 0):
str_logic_ids += "," + str(logic_id)
else:
str_logic_ids = str(logic_id)
if (self._psql.get("SELECT subgroup_id FROM us_dev_sgr WHERE (group_id='%s' and name='%s')" % (str(self.getGroupID()), self.getName()))):
self._psql.set("UPDATE us_dev_sgr SET logic_ids='%s' WHERE (group_id='%s' and name='%s')"\
% (str_logic_ids, str(self.getGroupID()), self.getName()))
else:
self._psql.set("INSERT INTO us_dev_sgr (group_id, name, logic_ids) VALUES ('%s', '%s', '%s')"\
% (str(self.getGroupID()), self.getName(), str_logic_ids))
------------------------------------------
class ClassSchedule(object):
... много методов ...
def save(self, psql, list_devices:list, conf, timezone:int, schedule_id:int = 0):
assert(isinstance(psql, ClassPSQL))
assert(isinstance(list_devices, list))
# assert(isinstance(conf, INIConfigLoader))
assert(isinstance(timezone, int))
assert(isinstance(schedule_id, int))
for date in self._list_date:
for logic_id in self._list_devices:
local_device = findDevice(list_devices, logic_id)
local_port, local_value = local_device.liquidity(self._action, conf, psql)
date_time = datetime.datetime.strptime(date + " " + self._time, "%d.%m.%Y %H:%M") - datetime.timedelta(hours = timezone)
psql.set("INSERT INTO device_exec_schedule (logicid, time, subgroup, port, value, group_id, answer) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s')" %
(str(logic_id), date_time, schedule_id, str(local_port), str(local_value), str(self._groups_id), "0"))
Была дана задача сишнику не знавшему Python написать сайт на Django за 4 дня. Знаете что? Он написал. (Названия таблиц в коде изменены, но смысл сохранён). Поддерживать код дали мне. А этот код из недр
j123123 29.10.2020 22:44 # 0
oaoaoammm 30.10.2020 04:03 # −1
А говнокод в том, что сишник написал всё сам, хотя в джанге есть ОРМ? Ещё и на ошибки проверил, какой багор )))
bormand 30.10.2020 10:13 # −1
MAKAKA 30.10.2020 22:04 # −1