Загрузить файлы в «germany»

This commit is contained in:
2026-05-25 16:49:41 +03:00
parent 247147c6dc
commit d84f24ed43
5 changed files with 1335 additions and 0 deletions

1093
germany/app.py Normal file

File diff suppressed because it is too large Load Diff

36
germany/door2tlg.py Normal file
View File

@@ -0,0 +1,36 @@
import datetime
import argparse
import telebot
parser = argparse.ArgumentParser(description='send door status')
parser.add_argument('--did', type=str, default="1", help='door ID')
parser.add_argument('--ds', type=int, default=0, help='door status')
parser.add_argument('--dv', type=float, default=0, help='Vbat voltage')
parser.add_argument('--t', type=float, default=-1, help='Temperature')
parser.add_argument('--h', type=float, default=-1, help='Humidity')
parser.add_argument('--tgids', type=str, default="245058979", help='TG IDs list')
parser.add_argument('--tgtok', type=str, default="5563613923:AAFGYdokQYJfTTQYhJftGZy3KtMDSZg5p6Q", help='TG token')
args = parser.parse_args()
homebot = telebot.TeleBot(args.tgtok)
vbat = ''
if(float(args.dv)>=0):
vbat = " / Аккумулятор %.2fV" % args.dv
if(float(args.t)!=-1):
vbat = "%s / Температура %.2fV" % (vbat, args.t)
if(float(args.h)!=-1):
vbat = "%s / Влажность %.2fV" % (vbat, args.h)
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")
if(int(args.ds)==0):
msg = "Дверь %s. Открытие. %s%s" % (args.did, ts, vbat)
else:
msg = "Дверь %s. Закрытие. %s%s" % (args.did, ts, vbat)
uids = args.tgids.split(",")
for uid in uids:
homebot.send_message(uid, msg)

156
germany/make4axelsgraph.py Normal file
View File

@@ -0,0 +1,156 @@
import cv2
import numpy as np
datadir = "log"
logid = "2"
log = "/home/shurik/SmartBed/src/%s/sb_%s.log" % (datadir, logid)
axels4graph=[4, 7, 14, 37, 18]
maxaxels4graphcnt = 4
axels4graphcnt = min(maxaxels4graphcnt, len(axels4graph))
#print(axels4graphcnt)
scale = 5 # увеличение сигнала на графике
log_lines = 15
axel_cnt = 39 # количество акселерометров
steps = 10 # количество измерений в одной строке
pdCnt = 39 # кол-во датчиков давления
data_delta = 1 # пропускаем первое значение - таймер
pd_delta = steps * axel_cnt * 3 + data_delta
input_frm_rates = 17
log_recs_delta = 1.5 # интервал между записями в логе
pd = []
ax = [[[],[],[]] for n in range(axel_cnt)]
times = []
cc=0
# read data from system pipe
from subprocess import Popen, PIPE
databuf = Popen(["tail", "-n%i" % log_lines, log], stdout=PIPE, encoding='utf-8').communicate()[0]
#print(log)
#print("databuf:\n", databuf)
lines = [line.rstrip() for line in databuf.split("\n")]
for l in lines:
if len(l) <=1 :
break
times.append(l.split("\t")[0])
args = l.split("\t")[1].split(",")
#pd.append([int(args[pd_delta]), int(args[pd_delta+1]), int(args[pd_delta+2]), int(args[pd_delta+3]), int(args[pd_delta+4])])
for sn in range(steps):
dlt = sn * 3 * axel_cnt
for i in range(axel_cnt):
# если уберут первое значение (метку таймера), то прибавку надо начинать не с 1, а с 0
ax[i][0].append(int(args[dlt + i*3+1]) if int(args[dlt + i*3+1]) < 32768 else int(args[dlt + i*3+1]) - 65536)
ax[i][1].append(int(args[dlt + i*3+2]) if int(args[dlt + i*3+2]) < 32768 else int(args[dlt + i*3+2]) - 65536)
ax[i][2].append(int(args[dlt + i*3+3])-280 if int(args[dlt + i*3+3]) < 32768 else int(args[dlt + i*3+3]) - 65536)
cc+=1
#if cc == 2:
# print(ax)
ax_shape = np.shape(ax)
axMax = [[0, 0, 0] for n in range(axel_cnt)]
axMin = [[0, 0, 0] for n in range(axel_cnt)]
deltaMax = 0
for ai in range(axel_cnt):
for i in range(3):
axMax[ai][i] = max(ax[ai][i])
axMin[ai][i] = min(ax[ai][i])
if axMax[ai][i] == axMin[ai][i]:
axMax[ai][i] += 1
deltaMax = (axMax[ai][i] - axMin[ai][i]) if (axMax[ai][i] - axMin[ai][i]) > deltaMax else deltaMax
a1,a2,glen = np.shape(ax)
imH, imW = [1080, 1920]
image_shape = (imH, imW, 3)
image = np.zeros(image_shape, dtype=np.uint8)
gpoints = ax_shape[2]
gphalf = gpoints / 2
gdelta = 20 # смещение графика от левого/правого края
hStep = (imH - 10) / (4 / 2) - 10
wStep = (imW - gdelta*2) / gpoints /2
pdHStep = (imH - 40) / pdCnt
hpix = 2 # int(65000 / hStep) # вес одного вертикального пикселя
isClosed = False
c0 = (255, 0, 0)
c1 = (0, 255, 0)
c2 = (0, 0, 255)
thickness = 2
vline = [[imW/2, 20], [imW/2, imH-20]]
vline = np.array(vline, np.int32).reshape((-1, 1, 2))
hline = [[20, imH/2], [imW-20, imH/2]]
hline = np.array(hline, np.int32).reshape((-1, 1, 2))
radius = 20
color = [(0, 0, 225), (225, 225, 255)]
aiH = [1, 1, 0, 0]
aiW = [0, 1, 0, 1]
cnt = 0
fc = 0
pdcnt = 0
ret_val = True
printflag=True
gstep = 5
dsize = 20 # размер анализируемого на движение участка
msize = 3 # meter size / интервал измерения от текущей точки назад
body = ["nogi", "ruki", "telo"]
for istep in range(1):
image *= 0
image -=1
acnt = int(cnt / input_frm_rates * (steps / log_recs_delta) )
pdcnt = int(acnt/10)
dstart = acnt-dsize if acnt> dsize else 0
mstart = acnt-msize if acnt> msize else 0
gstart = 0 # int((acnt-gphalf) if (acnt>gphalf) else 0)
gstop = glen #int((acnt+gphalf) if (acnt<(glen-gphalf)) else glen)
chartlen = int(gstop - gstart)
ldelta = int(gdelta) #int(gdelta if (gstart>0) else gdelta + (gphalf - acnt)*wStep)
ax4ch = [[[],[],[]] for n in range(axels4graphcnt)]
j=0
for i in range(gstart, gstop):
Wval = [int(ldelta + wStep*j) , int(imW/2+ldelta + wStep*j)]
for ai in range(axels4graphcnt):
#print(ai)
ax4ch[ai][0].append([Wval[aiW[ai]], int((ax[axels4graph[ai]][0][i]*scale+80)/hpix + 10 + aiH[ai]*hStep+150)])
ax4ch[ai][1].append([Wval[aiW[ai]], int((ax[axels4graph[ai]][1][i]*scale+80)/hpix + 10 + aiH[ai]*hStep+150)])
ax4ch[ai][2].append([Wval[aiW[ai]], int((ax[axels4graph[ai]][2][i]*scale+80)/hpix + 10 + aiH[ai]*hStep+150)])
j += 1
for i in range(axels4graphcnt):
ax4ch[i][0] = np.array(ax4ch[i][0], np.int32).reshape((-1, 1, 2))
ax4ch[i][1] = np.array(ax4ch[i][1], np.int32).reshape((-1, 1, 2))
ax4ch[i][2] = np.array(ax4ch[i][2], np.int32).reshape((-1, 1, 2))
for i in range(axels4graphcnt):
image = cv2.polylines(image, [ax4ch[i][0]], isClosed, c0, thickness)
image = cv2.polylines(image, [ax4ch[i][1]], isClosed, c1, thickness)
image = cv2.polylines(image, [ax4ch[i][2]], isClosed, c2, thickness)
image = cv2.polylines(image, [vline], isClosed, (200, 200, 200), thickness)
image = cv2.polylines(image, [hline], isClosed, (200, 200, 200), thickness)
if acnt > 3 :
pdsum = np.sum(pd[pdcnt])
if pdsum < pdCnt :
# считаем, что тело лежит на кровати, т.е. (pdsum < 5)
inumax = 0
imark = 0
for iax in range(12):
anum = int (iax / 3) # номер акселя
aline = iax % 3 # три оси акселя
imin, imax, imean = (np.min(ax[anum][aline][mstart:acnt]), np.max(ax[anum][aline][mstart:acnt]), int(np.mean(ax[anum][aline][dstart:acnt])))
if abs(imax - imean) > sens or abs(imean - imin) > sens :
inumax += 1
imark |= (int(iax/6)+1)
for i in range(axels4graphcnt):
labH = int(50+imH*aiH[i]/2)
labW = int(20+imW*aiW[i]/2)
cv2.putText(image, "axel %i" % axels4graph[i], (labW, labH), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)
imH, imW
cv2.imwrite("4acsels_chart.png",image)

33
germany/mk_img.py Normal file
View File

@@ -0,0 +1,33 @@
import matplotlib.pyplot as plt
def make_plot(fname, id):
with open(fname, 'r') as f:
lines = [line.rstrip() for line in f]
ax1 = []
ax2 = []
ax3 = []
cnt = 0
for l in lines:
b = l.split("\t")
args = b[1].split(",")
ax1.append([cnt, args[0]])
ax2.append([cnt, args[1]])
ax3.append([cnt, args[2]])
cnt += 1
ax1 = [list(i) for i in zip(*ax1)]
ax2 = [list(i) for i in zip(*ax2)]
ax3 = [list(i) for i in zip(*ax3)]
plt.figure(figsize=(20,10))
plt.title("акселерометр кровати %s" % id, fontsize=20)
plt.plot(ax1[0], ax1[1],'g-')
plt.plot(ax2[0], ax2[1],'r-')
plt.plot(ax3[0], ax3[1],'b-')
img_name = "%s_chart.png" % fname
plt.savefig(img_name)
return(img_name)
fname = './tmp/sb_2'
id = 2
img_file = make_plot(fname, id)
print(img_file)

17
germany/uwsgi.ini Normal file
View File

@@ -0,0 +1,17 @@
[uwsgi]
master = true
chdir=/home/shurik/SmartBed/src
shared-socket = 0.0.0.0:443
uid = shurik
gid = shurik
https = =0,https/fullchain.pem,https/privkey.pem,HIGH
#http-to = /tmp/uwsgi.sock
http = 195.201.126.70:8080
buffer-size=32768
wsgi-file = app.py
callable = app
#module=app.py:application
static-map = /log=/home/shurik/SmartBed/src/log