remote-run-everything 2.0.7__py3-none-any.whl → 2.0.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  from remote_run_everything.deploy.by_http import ByHttp
2
2
  from remote_run_everything.deploy.by_sftp import BySftp
3
+ from remote_run_everything.deploy.process_manage import ProcessManage
3
4
 
4
5
  from remote_run_everything.db.crude_duck import CrudeDuck
5
6
  from remote_run_everything.db.crud_sqlalchemy import Crud
@@ -14,3 +15,4 @@ from remote_run_everything.nosql.no_sql import Nosql
14
15
  from remote_run_everything.nosql.no_sql_pg import NosqlPg
15
16
  from remote_run_everything.nosql.no_sql_mysql import NosqlMysql
16
17
  from remote_run_everything.vsconf.core import VsConf
18
+ from remote_run_everything.binocular.relative_pos import RelativePos
@@ -0,0 +1,72 @@
1
+ import numpy as np
2
+ from remote_run_everything.binocular.back_tool import BackTool
3
+ from remote_run_everything.binocular.front_tool import FrontTool
4
+ from remote_run_everything.binocular.cam_tool import CamTool
5
+
6
+ # 4.213158 0.669677 -3.907534 -0.750835 60 0 -60
7
+ # 内方位元素:f,x0,y0 单位mm
8
+
9
+ class BaFront:
10
+ def __init__(self, f1, f2, s1, s2, angle1, angle2, u1, v1, u2, v2):
11
+ # 内方位元素:f,x0,y0 单位mm
12
+ self.f1 = f1
13
+ self.f2 = f2
14
+ # 左右像片外方位元素 单位mm
15
+ self.S1 = s1
16
+ self.S2 = s2
17
+ self.angle1 = angle1
18
+ self.angle2 = angle2
19
+ self.u1 = u1
20
+ self.v1 = v1
21
+ self.u2 = u2
22
+ self.v2 = v2
23
+ self.ftool = FrontTool()
24
+ self.btool1 = BackTool(self.f1, u1, v1)
25
+ self.btool2 = BackTool(self.f2, u2, v2)
26
+ self.max_step = 1000000
27
+
28
+ def first_cpt(self):
29
+ # 计算基线分量,L.R为左右像片线元素
30
+ B = self.S2 - self.S1
31
+ R1 = CamTool().calcR(*self.angle1)
32
+ R2 = CamTool().calcR(*self.angle2)
33
+ XYZ1 = self.ftool.coordinate(R1, self.u1, self.v1, self.f1) # 左片像空间辅助坐标
34
+ XYZ2 = self.ftool.coordinate(R2, self.u2, self.v2, self.f2) # 右片像空间辅助坐标
35
+ N = self.ftool.genN(B, XYZ1, XYZ2)
36
+ XYZ = self.ftool.xyz(self.S1, XYZ1, N)
37
+ # CamTool().view_pcd(gp)
38
+ return XYZ
39
+
40
+ def refine(self, XYZ, which):
41
+ X = XYZ[:, 0]
42
+ Y = XYZ[:, 1]
43
+ Z = XYZ[:, 2]
44
+ if which == 1:
45
+ btool = self.btool1
46
+ X0, Y0, Z0 = self.S1.tolist()
47
+ phi, omega, kappa = self.angle1
48
+ else:
49
+ btool = self.btool2
50
+ X0, Y0, Z0 = self.S2.tolist()
51
+ phi, omega, kappa = self.angle2
52
+ for i in range(self.max_step):
53
+ L = btool.genL(X, Y, Z, phi, omega, kappa, X0, Y0, Z0)
54
+ A, B = btool.genAB(X, Y, Z, phi, omega, kappa, X0, Y0, Z0)
55
+ dxyz = btool.genDxyz(B, L)
56
+
57
+ # ex[dxs,dys,dzs,dphi,domega,dkappa]
58
+ X += dxyz[0]
59
+ Y += dxyz[1]
60
+ Z += dxyz[2]
61
+
62
+ limit = 0.00001
63
+ if np.abs(dxyz[0]) < limit or np.abs(dxyz[1]) < limit or np.abs(dxyz[2]) < limit:
64
+ err = np.mean(np.abs(dxyz))
65
+ return XYZ, err
66
+
67
+ def refine_all(self, XYZ):
68
+ xyz1, err1 = self.refine(XYZ, 1)
69
+ xyz2, err2 = self.refine(XYZ, 2)
70
+ xyz = (xyz1 + xyz2) / 2
71
+ return xyz, (err1 + err2) / 2
72
+
@@ -0,0 +1,123 @@
1
+ """
2
+ 后方交会代码
3
+ 作者:Dash
4
+ version:0.1
5
+ without any optimization
6
+ """
7
+ import numpy as np
8
+
9
+
10
+ class BackTool(object):
11
+ def __init__(self, f, u, v):
12
+ self.f = f
13
+ self.u = u
14
+ self.v = v
15
+ self.max_step = 1000000
16
+
17
+ def init_param(self, X, Y, Z, scale):
18
+ n = len(X)
19
+ # initial line paras
20
+ Z0 = scale * self.f + (1 / n) * np.sum(Z)
21
+ X0 = (1 / n) * np.sum(X)
22
+ Y0 = (1 / n) * np.sum(Y)
23
+ return X0, Y0, Z0
24
+
25
+ def genL(self, X, Y, Z, phi, omega, kappa, X0, Y0, Z0):
26
+ R = CamTool().calcR(phi, omega, kappa)
27
+ a1, a2, a3, b1, b2, b3, c1, c2, c3 = [i for l in R.tolist() for i in l]
28
+ L = []
29
+ for j in range(len(self.u)):
30
+ numerator_x = self.f * (a1 * (X[j] - X0) + b1 * (Y[j] - Y0) + c1 * (Z[j] - Z0))
31
+ numerator_y = self.f * (a2 * (X[j] - X0) + b2 * (Y[j] - Y0) + c2 * (Z[j] - Z0))
32
+ denomanator = (a3 * (X[j] - X0) + b3 * (Y[j] - Y0) + c3 * (Z[j] - Z0))
33
+ lx = self.u[j] + numerator_x / denomanator
34
+ ly = self.v[j] + numerator_y / denomanator
35
+ L.append(lx)
36
+ L.append(ly)
37
+ L = np.array(L,dtype=np.float32)
38
+ return L
39
+
40
+ def genAB(self, X, Y, Z, phi, omega, kappa, X0, Y0, Z0):
41
+ R = CamTool().calcR(phi, omega, kappa)
42
+ a1, a2, a3, b1, b2, b3, c1, c2, c3 = [i for l in R.tolist() for i in l]
43
+ num_of_samples = len(self.u)
44
+
45
+ a11 = np.zeros(num_of_samples, dtype=np.float32)
46
+ a12 = np.zeros(num_of_samples, dtype=np.float32)
47
+ a13 = np.zeros(num_of_samples, dtype=np.float32)
48
+
49
+ a14 = np.zeros(num_of_samples, dtype=np.float32)
50
+ a15 = np.zeros(num_of_samples, dtype=np.float32)
51
+ a16 = np.zeros(num_of_samples, dtype=np.float32)
52
+
53
+ a21 = np.zeros(num_of_samples, dtype=np.float32)
54
+ a22 = np.zeros(num_of_samples, dtype=np.float32)
55
+ a23 = np.zeros(num_of_samples, dtype=np.float32)
56
+ a24 = np.zeros(num_of_samples, dtype=np.float32)
57
+ a25 = np.zeros(num_of_samples, dtype=np.float32)
58
+ a26 = np.zeros(num_of_samples, dtype=np.float32)
59
+
60
+ for j in range(num_of_samples):
61
+ z_bar = a3 * (X[j] - X0) + b3 * (Y[j] - Y0) + c3 * (Z[j] - Z0)
62
+ a11[j] = (a1 * self.f + a3 * self.u[j]) / z_bar
63
+ a12[j] = (b1 * self.f + b3 * self.u[j]) / z_bar
64
+ a13[j] = (c1 * self.f + c3 * self.u[j]) / z_bar
65
+ a14[j] = (self.v[j] * np.sin(omega)) - (self.u[j] * (
66
+ self.u[j] * np.cos(kappa) - self.v[j] * np.sin(kappa)) / self.f + self.f * np.cos(
67
+ kappa)) * np.cos(omega)
68
+ a15[j] = -self.f * np.sin(kappa) - (self.u[j] / self.f) * (
69
+ self.u[j] * np.sin(kappa) + self.v[j] * np.cos(kappa))
70
+ a16[j] = self.v[j]
71
+
72
+ a21[j] = (a2 * self.f + a3 * self.v[j]) / z_bar
73
+ a22[j] = (b2 * self.f + b3 * self.v[j]) / z_bar
74
+ a23[j] = (c2 * self.f + c3 * self.v[j]) / z_bar
75
+ a24[j] = -self.u[j] * np.sin(omega) - (self.v[j] / self.f) * (
76
+ (self.u[j] * np.cos(kappa) - self.v[j] * np.sin(kappa)) - self.f * np.sin(
77
+ kappa)) * np.cos(omega)
78
+ a25[j] = -self.f * np.cos(kappa) - (self.v[j] / self.f) * (
79
+ self.u[j] * np.sin(kappa) + self.v[j] * np.cos(kappa))
80
+ a26[j] = -self.u[j]
81
+
82
+ A = np.zeros((2 * num_of_samples, 6), dtype=np.float32)
83
+ B = np.zeros((2 * num_of_samples, 3), dtype=np.float32)
84
+ for j in range(num_of_samples):
85
+ A[2 * j:2 * j + 2, :] = np.array([
86
+ [a11[j], a12[j], a13[j], a14[j], a15[j], a16[j]],
87
+ [a21[j], a22[j], a23[j], a24[j], a25[j], a26[j]]
88
+ ], dtype=np.float32)
89
+ B[2 * j:2 * j + 2, :] = np.array([
90
+ [-a11[j], -a12[j], -a13[j]],
91
+ [-a21[j], -a22[j], -a23[j]]
92
+ ], dtype=np.float32)
93
+ return A, B
94
+
95
+ def genT_noba(self, A, L):
96
+
97
+ AtA = np.dot(A.T, A)
98
+ inverse_AtA = np.linalg.inv(AtA)
99
+ print(333, inverse_AtA)
100
+ combine = np.dot(inverse_AtA, A.T)
101
+ X = np.dot(combine, L)
102
+ return X
103
+
104
+ def genT(self, A, B, L):
105
+ N11 = A.T @ A
106
+ N12 = A.T @ B
107
+ N21 = B.T @ A
108
+ N22 = B.T @ B
109
+ M1 = A.T @ L
110
+ M2 = B.T @ L
111
+ right = M1 - N12 @ np.linalg.inv(N22) @ M2
112
+ left = N11 - N12 @ np.linalg.inv(N22) @ N21
113
+ print("begin inv")
114
+ left_inv = np.linalg.inv(left)
115
+ print("inv", left_inv)
116
+ t = np.dot(left_inv, right)
117
+ return t
118
+
119
+ def genDxyz(self, B, L):
120
+ inverse_BtB = np.linalg.inv(np.dot(B.T, B))
121
+ combine = np.dot(inverse_BtB, B.T)
122
+ X = np.dot(combine, L)
123
+ return X
@@ -0,0 +1,26 @@
1
+ import os
2
+ import numpy as np
3
+
4
+ class CamTool:
5
+ def calcR(self, phi, omega, kappa):
6
+ a1 = np.cos(phi) * np.cos(kappa) - np.sin(phi) * np.sin(omega) * np.sin(kappa)
7
+ a2 = -np.cos(phi) * np.sin(kappa) - np.sin(phi) * np.sin(omega) * np.cos(kappa)
8
+ a3 = -np.sin(phi) * np.cos(omega)
9
+ b1 = np.cos(omega) * np.sin(kappa)
10
+ b2 = np.cos(omega) * np.cos(kappa)
11
+ b3 = -np.sin(omega)
12
+ c1 = np.sin(phi) * np.cos(kappa) + np.cos(phi) * np.sin(omega) * np.sin(kappa)
13
+ c2 = -np.sin(phi) * np.sin(kappa) + np.cos(phi) * np.sin(omega) * np.cos(kappa)
14
+ c3 = np.cos(phi) * np.cos(omega)
15
+ arr = np.array([[a1, a2, a3], [b1, b2, b3], [c1, c2, c3]])
16
+ return arr
17
+
18
+ def intrisinc(self,path):
19
+ path=os.path.abspath(path)
20
+ return np.loadtxt(path, delimiter=',')
21
+ def cx_cy(self,path):
22
+ ins=self.intrisinc(path)
23
+ return ins[0, 2],ins[1, 2]
24
+ def fx(self,path):
25
+ ins=self.intrisinc(path)
26
+ return ins[0,0]
@@ -0,0 +1,39 @@
1
+ import numpy as np
2
+
3
+
4
+ # 4.213158 0.669677 -3.907534 -0.750835 60 0 -60
5
+ # 内方位元素:f,x0,y0 单位mm
6
+
7
+ class FrontTool:
8
+ def coordinate(self, R, u, v, f): # 计算所求点的像空间辅助坐标系,xyz--> XYZ,R为旋转矩阵,P所求点像空间坐标,f为主距
9
+ XYZ = []
10
+ for i in range(len(u)):
11
+ xyz = np.array([[u[i]], [v[i]], [-f]])
12
+ XYZ.append(np.dot(R, xyz))
13
+ return XYZ
14
+
15
+ def projection_index(self, B, XYZ1, XYZ2): # 投影系数计算
16
+ bu = B[0]
17
+ bw = B[2]
18
+ u1 = XYZ1[0]
19
+ w1 = XYZ1[2]
20
+ u2 = XYZ2[0]
21
+ w2 = XYZ2[2]
22
+ N1 = (bu * w2 - bw * u2) / (u1 * w2 - u2 * w1)
23
+ N2 = (bu * w1 - bw * u1) / (u1 * w2 - u2 * w1)
24
+ return [N1[0], N2[0]]
25
+
26
+ def genN(self, B, XYZ1, XYZ2):
27
+ N = []
28
+ for i in range(len(XYZ1)):
29
+ N.append(self.projection_index(B, XYZ1[i], XYZ2[i]))
30
+ return N
31
+
32
+ def xyz(self, S1, XYZ1, N):
33
+ l = []
34
+ for i in range(len(XYZ1)):
35
+ XYZ = XYZ1[i].reshape((3,))
36
+ # 地面控制点坐标计算
37
+ res = S1 + N[i][0] * XYZ
38
+ l.append(res)
39
+ return np.array(l)
@@ -0,0 +1,142 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Fri Apr 24 12:23:35 2020
4
+ @author: 陨星落云
5
+ """
6
+ import numpy as np
7
+ from numpy import linalg
8
+ from remote_run_everything.binocular.cam_tool import CamTool
9
+ import copy
10
+ from remote_run_everything.binocular.ba_front import BaFront
11
+
12
+
13
+ class RelativePos:
14
+ def __init__(self, pathl,pathr,unitl,unitr):
15
+ self.pathl=pathl
16
+ self.pathr=pathr
17
+ self.unitl=unitl
18
+ self.unitr=unitr
19
+ self.cam=CamTool()
20
+ self.f=self.cam.fx(self.pathl)*self.unitl
21
+ self.fi = 0
22
+ self.omega = 0
23
+ self.kapa = 0
24
+ self.u_bv = 0
25
+ self.r_bw = 0
26
+
27
+
28
+ def rel_one(self, l0, r0):
29
+ cxcyl = self.cam.cx_cy(self.pathl)
30
+ cxcyr = self.cam.cx_cy(self.pathr)
31
+ # 像素坐标换相平面坐标 输入同名像素点 [(u,v),]
32
+ l = self.uv_process(self.unitl, cxcyl[0], cxcyl[1], copy.deepcopy(l0))
33
+ r = self.uv_process(self.unitr, cxcyr[0], cxcyr[1], copy.deepcopy(r0))
34
+ # 后方交汇 改写右边-->左边的旋角,u,v,返回使用到的像素点index
35
+ new_match = self.back_intersect(l, r)
36
+ if new_match is None:
37
+ print("can not solve relative pos")
38
+ return None
39
+ a1 = [0, 0, 0]
40
+ a2 = [self.fi, self.omega, self.kapa]
41
+ S1 = np.array([0., 0., 0.])
42
+ S2 = np.array([1, self.u_bv, self.r_bw])
43
+ l = l[new_match, :]
44
+ r = r[new_match, :]
45
+ fl=self.cam.fx(self.pathl)*self.unitl
46
+ fr=self.cam.fx(self.pathr)*self.unitr
47
+ f = BaFront(fl, fr, S1, S2, a1, a2, l[:, 0], l[:, 1], r[:, 0],
48
+ r[:, 1])
49
+ # 前方交汇
50
+ pcd = f.first_cpt()
51
+ d = {"pcd": pcd, "T": S2, "angle": a2, "match": new_match
52
+ # "match": np.concatenate([i['l'][new_match, :], i['r'][new_match, :]], axis=1),
53
+ }
54
+ return d
55
+
56
+ def uv_process(self, unit, cx, cy, l):
57
+ l[:, 0] = unit * (l[:, 0] - cx)
58
+ l[:, 1] = unit * (cy - l[:, 1])
59
+ return l
60
+
61
+ def cptaq(self, i, l, r):
62
+ # 计算旋转矩阵
63
+ R = CamTool().calcR(self.fi, self.omega, self.kapa)
64
+ # 比例尺 怎么都无所谓
65
+ bu = l[0][0] - r[0][0]
66
+ bv = bu * self.u_bv
67
+ bw = bu * self.r_bw
68
+ # 左片相对摄影测量坐标
69
+ u1 = l[i][0]
70
+ v1 = l[i][1]
71
+ w1 = -self.f
72
+ # 计算相对摄影测量坐标
73
+ mr = np.dot(R, np.array([r[i][0], r[i][1], -self.f]))
74
+ # 右片相对摄影测量坐标
75
+ u2 = mr[0]
76
+ v2 = mr[1]
77
+ w2 = mr[2]
78
+ # 计算N1,N2
79
+ N1 = (bu * w2 - bw * u2) / (u1 * w2 - u2 * w1)
80
+ N2 = (bu * w1 - bw * u1) / (u1 * w2 - u2 * w1)
81
+ # 计算每个点Q
82
+ Q = N1 * v1 - N2 * v2 - bv
83
+ a = -u2 * v2 * N2 / w2
84
+ b = -N2 * (w2 + v2 * v2 / w2)
85
+ c = u2 * N2
86
+ d = bu
87
+ e = -v2 * bu / w2
88
+ return np.array([a, b, c, d, e]), Q
89
+
90
+ def back_intersect(self, l, r):
91
+ n = l.shape[0]
92
+ countx, countj = (0, 0)
93
+ # 误差方程参数
94
+ # 右片相对相空间坐标,相对摄影测量坐标
95
+ # 迭代运算
96
+ while True:
97
+ Al = []
98
+ Ll = []
99
+ new_match = []
100
+
101
+ # 计算每个点参数,组成法方程矩阵
102
+ for i in range(n):
103
+ ai, Q = self.cptaq(i, l, r)
104
+ if np.isnan(Q):
105
+ continue
106
+ new_match.append(i)
107
+ Al.append(ai)
108
+ Ll.append(Q)
109
+ # A[i, :] = ai
110
+ # L[i] = Q
111
+ # 求解X
112
+ A = np.array(Al)
113
+ L = np.array(Ll)
114
+ try:
115
+ inv = linalg.inv(np.dot(A.T, A))
116
+ except:
117
+ return None
118
+ X = np.dot(np.dot(inv, A.T), L)
119
+ # 累加五参数
120
+ self.fi += X[0]
121
+ self.omega += X[1]
122
+ self.kapa += X[2]
123
+ self.u_bv += X[3]
124
+ self.r_bw += X[4]
125
+ # 循环次数+
126
+ countx += 1
127
+ # 判断是否收敛
128
+ if countx > 1000:
129
+ return None
130
+
131
+ if (np.abs(X) < 0.00003).all():
132
+ print("五参数", self.fi, self.omega, self.kapa, self.u_bv, self.r_bw)
133
+ # 精度评定
134
+ V = np.dot(A, X.T) - L
135
+ c1 = np.sqrt(np.dot(V.T, V) / n)
136
+ print("相对定向精度:", c1)
137
+ print("相对定向迭代次数:", countx)
138
+ print("新的配对长度:", len(new_match))
139
+ return new_match
140
+
141
+
142
+
@@ -0,0 +1,46 @@
1
+ import os, signal
2
+ import subprocess, sys
3
+ class ProcessManage:
4
+ def is_process_running(self,pid):
5
+ import psutil
6
+ try:
7
+ process = psutil.Process(pid)
8
+ # Check if process is still running
9
+ return process.is_running()
10
+ except psutil.NoSuchProcess:
11
+ return False
12
+ except psutil.AccessDenied:
13
+ # Process exists but we don't have permission to access it
14
+ print(f"Access denied to process {pid}")
15
+ return True
16
+ def read_pid_file(self,pidfile):
17
+ if os.path.exists(pidfile):
18
+ with open(pidfile, "rb") as f:
19
+ pid = f.read().decode()
20
+ return pid
21
+ return None
22
+
23
+ # 只需要在程序中引入这个函数,启动后会把 os.getpid()存入,然后有了pid,结合psutil,什么都有了
24
+ def write_pid_file(self,pidfile,pid):
25
+ with open(pidfile, "wb") as f:
26
+ s = str(pid).encode()
27
+ f.write(s)
28
+
29
+ def kill_by_pid(self,pid):
30
+ try:
31
+ os.kill(int(pid), signal.SIGTERM)
32
+ except Exception as e:
33
+ print("kill err==", e)
34
+
35
+ def popen_with_pid(self, workdir, app):
36
+ os.chdir(workdir)
37
+ process = subprocess.Popen(app, creationflags=subprocess.CREATE_NEW_CONSOLE)
38
+ pid= process.pid
39
+ print("new pid====",pid)
40
+ return pid
41
+ # sys.exit()
42
+
43
+ def restart_windows(self):
44
+ os.system("shutdown -t 0 -r -f")
45
+
46
+
@@ -1,11 +1,7 @@
1
- import jinja2, requests, os
2
- import pandas as pd
3
1
  import socket, os, tomllib
4
- import base64
5
- import os, signal
6
- import subprocess, sys
7
2
  from remote_run_everything.tools.common1 import Common1
8
-
3
+ import pandas as pd
4
+ import jinja2, os,base64,struct, glob, arrow, uuid, hashlib
9
5
 
10
6
  class Common(Common1):
11
7
  @property
@@ -25,31 +21,102 @@ class Common(Common1):
25
21
  data = tomllib.load(f)
26
22
  return data
27
23
 
28
- def kill_by_pidfile(self, pidfile):
29
- if os.path.exists(pidfile):
30
- with open(pidfile, "rb") as f:
31
- pid = f.read().decode()
32
- print("exist pid===", pid)
33
- try:
34
- os.kill(int(pid), signal.SIGTERM)
35
- except Exception as e:
36
- print("kill err==", e)
37
-
38
- def start_with_pidfile(self, workdir, pidfile, app):
39
- os.chdir(workdir)
40
- process = subprocess.Popen(app, creationflags=subprocess.CREATE_NEW_CONSOLE)
41
- print("new pid====", process.pid)
42
- with open(pidfile, "wb") as f:
43
- s = str(process.pid).encode()
44
- f.write(s)
45
- sys.exit()
46
-
47
- def supervise(self, pidfile, app, workdir=None):
48
- if workdir is None:
49
- workdir = os.path.dirname(pidfile)
50
- self.kill_by_pidfile(pidfile)
51
- self.start_with_pidfile(workdir, pidfile, app)
24
+ def table_search(self, data, search):
25
+ res = []
26
+ for i in data:
27
+ if search == "":
28
+ res.append(i)
29
+ elif search != "" and search in str(i):
30
+ res.append(i)
31
+ return res
32
+
33
+ def split_page(self, numPerPage, cur, search, data):
34
+ data = self.table_search(data, search)
35
+ if data is None or len(data) == 0:
36
+ return {"total": 0, "data": []}
37
+ cur = int(cur)
38
+ res = {"total": len(data)}
39
+ n = int(numPerPage)
40
+ total = len(data)
41
+ start = (cur - 1) * n
42
+ end = cur * n
43
+ if start > total - 1:
44
+ res['data'] = []
45
+ elif end > total - 1:
46
+ remainder = total % numPerPage
47
+ if remainder == 0:
48
+ res['data'] = data[-numPerPage:]
49
+ else:
50
+ res['data'] = data[-remainder:]
51
+ else:
52
+ res['data'] = data[start:end]
53
+ return res
54
+
55
+ def render(self, dir, html, data):
56
+ env = jinja2.Environment(loader=jinja2.FileSystemLoader(f'{dir}/templates'))
57
+ template = env.get_template(html)
58
+ outputText = template.render(data=data) # this is where to put args
59
+ return outputText
60
+
61
+ def inven_everyday(self, df, begin, end):
62
+ df1 = df.groupby(by=['id', 'date']).sum()
63
+ # 可以把复合index重新拆分成columns
64
+ trades = df1.reset_index()
65
+ trades['id'] = trades['id']
66
+ trades['date'] = trades['date']
67
+ # create a range of dates for the merged dataframe pd.datetime.today()
68
+ if not begin:
69
+ begin = df['date'].min()
70
+ if not end:
71
+ end = df['date'].max()
72
+ index_of_dates = pd.date_range(begin, end).to_frame().reset_index(drop=True).rename(columns={0: 'date'}).astype(
73
+ str)
74
+ # create a merged dataframe with columns date / stock / stock_Tr.
75
+ merged = pd.merge(index_of_dates, trades, how='left', on='date')
76
+ # create a pivottable showing the shares_TR of each stock for each date
77
+ shares_tr = merged.pivot(index='date', columns='id', values='q')
78
+ shares_tr = shares_tr.dropna(axis=1, how='all').fillna(0)
79
+ cumShares = shares_tr.cumsum()
80
+ cumShares.index = cumShares.index.astype(str)
81
+ return cumShares
82
+
83
+ def writeb64(self, path, b64):
84
+ dir = os.path.dirname(path)
85
+ if not os.path.exists(dir):
86
+ os.makedirs(dir, exist_ok=True)
87
+ content = base64.b64decode(b64)
88
+ with open(path, "wb") as f:
89
+ f.write(content)
90
+ os.chmod(path, 0o777)
91
+
92
+ def readb64(self, f):
93
+ with open(f, "rb") as file:
94
+ encoded_string = base64.b64encode(file.read())
95
+ return encoded_string.decode()
96
+
97
+ def prefix_zero(self, n, d):
98
+ if len(str(d)) >= n: return str(d)[-n:]
99
+ l = ["0"] * (n - len(str(d)))
100
+ zeros = "".join(l)
101
+ return f"{zeros}{d}"
102
+
103
+ def ascii2hex(self,l):
104
+ tu = [i.replace("0x", "") for i in l]
105
+ tu = [self.prefix_zero(2, i) for i in tu]
106
+ return "".join(tu)
107
+
108
+ def ascii2int(self,l,big):
109
+ s=self.ascii2hex(l)
110
+ b = bytes.fromhex(s)
111
+ if big:
112
+ return int.from_bytes(b, byteorder='big')
113
+ return int.from_bytes(b, byteorder='little')
52
114
 
115
+ def ascii2float(self,l,big):
116
+ s=self.ascii2hex(l)
117
+ if big:
118
+ return struct.unpack('>f', bytes.fromhex(s))[0]
119
+ return struct.unpack('<f', bytes.fromhex(s))[0]
53
120
 
54
121
  if __name__ == '__main__':
55
122
  g = Common()
@@ -1,90 +1,8 @@
1
- import jinja2, requests, os
2
- import pandas as pd
3
- import base64
4
- import os, signal, glob, arrow, uuid, hashlib
1
+ import jinja2, os,base64,struct, glob, arrow, uuid, hashlib
5
2
 
6
3
 
7
4
  class Common1:
8
5
 
9
- def table_search(self, data, search):
10
- res = []
11
- for i in data:
12
- if search == "":
13
- res.append(i)
14
- elif search != "" and search in str(i):
15
- res.append(i)
16
- return res
17
-
18
- def split_page(self, numPerPage, cur, search, data):
19
- data = self.table_search(data, search)
20
- if data is None or len(data) == 0:
21
- return {"total": 0, "data": []}
22
- cur = int(cur)
23
- res = {"total": len(data)}
24
- n = int(numPerPage)
25
- total = len(data)
26
- start = (cur - 1) * n
27
- end = cur * n
28
- if start > total - 1:
29
- res['data'] = []
30
- elif end > total - 1:
31
- remainder = total % numPerPage
32
- if remainder == 0:
33
- res['data'] = data[-numPerPage:]
34
- else:
35
- res['data'] = data[-remainder:]
36
- else:
37
- res['data'] = data[start:end]
38
- return res
39
-
40
- def render(self, dir, html, data):
41
- env = jinja2.Environment(loader=jinja2.FileSystemLoader(f'{dir}/templates'))
42
- template = env.get_template(html)
43
- outputText = template.render(data=data) # this is where to put args
44
- return outputText
45
-
46
- def inven_everyday(self, df, begin, end):
47
- df1 = df.groupby(by=['id', 'date']).sum()
48
- # 可以把复合index重新拆分成columns
49
- trades = df1.reset_index()
50
- trades['id'] = trades['id']
51
- trades['date'] = trades['date']
52
- # create a range of dates for the merged dataframe pd.datetime.today()
53
- if not begin:
54
- begin = df['date'].min()
55
- if not end:
56
- end = df['date'].max()
57
- index_of_dates = pd.date_range(begin, end).to_frame().reset_index(drop=True).rename(columns={0: 'date'}).astype(
58
- str)
59
- # create a merged dataframe with columns date / stock / stock_Tr.
60
- merged = pd.merge(index_of_dates, trades, how='left', on='date')
61
- # create a pivottable showing the shares_TR of each stock for each date
62
- shares_tr = merged.pivot(index='date', columns='id', values='q')
63
- shares_tr = shares_tr.dropna(axis=1, how='all').fillna(0)
64
- cumShares = shares_tr.cumsum()
65
- cumShares.index = cumShares.index.astype(str)
66
- return cumShares
67
-
68
- def writeb64(self, path, b64):
69
- dir = os.path.dirname(path)
70
- if not os.path.exists(dir):
71
- os.makedirs(dir, exist_ok=True)
72
- content = base64.b64decode(b64)
73
- with open(path, "wb") as f:
74
- f.write(content)
75
- os.chmod(path, 0o777)
76
-
77
- def readb64(self, f):
78
- with open(f, "rb") as file:
79
- encoded_string = base64.b64encode(file.read())
80
- return encoded_string.decode()
81
-
82
- def prefix_zero(self, n, d):
83
- if len(str(d)) >= n: return str(d)[-n:]
84
- l = ["0"] * (n - len(str(d)))
85
- zeros = "".join(l)
86
- return f"{zeros}{d}"
87
-
88
6
  def clear_by_days(self, root, n):
89
7
  files = glob.glob(f"{root}/*/*.*", recursive=True)
90
8
  now = arrow.now()
@@ -99,6 +17,9 @@ class Common1:
99
17
  return str(uuid.UUID(hex=hex_string))
100
18
 
101
19
 
20
+
21
+
22
+
23
+
102
24
  if __name__ == '__main__':
103
25
  g = Common1()
104
- a = g.prefix_zero(5, 111)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: remote_run_everything
3
- Version: 2.0.7
3
+ Version: 2.0.9
4
4
  Summary: Deploy Tools
5
5
  Author-email: Wang Qi <wangmarkqi@gmail.com>
6
6
  License-Expression: MIT
@@ -27,7 +27,7 @@ from remote_run_everything import cherrypy_in_daemon,ByHttpServer
27
27
  cherrypy_in_daemon(ByHttpServer,8888,"/deploy")
28
28
 
29
29
  # 上推代码
30
- from remote_run_everything import ByHttp
30
+ from remote_run_everything import ByHttp ,BySftp
31
31
  def test_up():
32
32
  host = "http://x.x.x.x:8888/deploy"
33
33
  local = "D://project/demand/shop"
@@ -35,6 +35,13 @@ def test_up():
35
35
  db = "D://wq/temp/shop.db"
36
36
  bh = ByHttp(host, local, remote, db)
37
37
  bh.up(['node_modules', ".pyc", ".idea"])
38
+ def test_up2():
39
+ host = "http://x.x.x.x:8888/deploy"
40
+ local = "D://project/demand/shop"
41
+ remote = "/data/mypy/shop"
42
+ db = "D://wq/temp/shop.db"
43
+ by=BySftp(host,22,'root','pwd',local,remote,db)
44
+ by.up(['node_modules', ".pyc", ".idea", ".pdf", ".docx", ".pickle", ".png", ".jpg",".venv","target","dist","build"])
38
45
 
39
46
  # 下拉代码
40
47
  def test_down():
@@ -92,18 +99,35 @@ q = {"a": 2,"b":{"$gt":1}}
92
99
  print(col.find(q))
93
100
  db.drop_db()
94
101
  ```
95
- ## 进程管理
102
+
103
+
104
+ ## 缓存装饰器
96
105
  ```python
97
- class ProcessManage:
98
- # nosql is instance of Nosql or Nosqlmysql or Nqsqlpg
99
- def __init__(self, nosql):
100
- self.db = nosql
101
- self.col = self.db['pid']
106
+ from remote_run_everything import cache_by_1starg,cache_by_name,cache_by_rkey,cache_by_nth_arg
107
+ @cache_by_name("asdf", 1)
108
+ def test_dec():
109
+ print("运行了函数!!!!!!!!!!!!!!!!")
110
+ return {"a": "adaf"}
111
+
102
112
 
103
- # 只需要在程序中引入这个函数,启动后会把pid存入数据库,然后有了pid,结合psutil,什么都有了
104
- def save_pid(self, name, cmd):
105
- dic = {"name": name, "cmd": cmd, "pid": os.getpid()}
106
- print("save pid", dic)
107
- self.col.insert_one(dic)
113
+ ```
108
114
 
115
+ ## 关系型 数据库
116
+ ```python
117
+ from remote_run_everything import Crud,CrudeDuck
118
+ # 详情参见类方法
119
+ ```
120
+
121
+ ## 双目测距
122
+ ```python
123
+ from remote_run_everything.binocular.relative_pos import RelativePos,CamTool
124
+ import numpy as np
125
+ unit=0.006240084611316764
126
+ l=[[3838.36767578125, 50.56350326538086], [2636.24072265625, 88.38832092285156], [511.72705078125, 95.95327758789062], [2303.57666015625, 107.30072784423828], [2159.92626953125, 111.08320617675781], [2001.15478515625, 114.86569213867188], ]
127
+ r=[[3743.86083984375, 31.651092529296875], [2424.54541015625, 65.69342803955078], [231.98681640625, 69.47590637207031], [2076.76025390625, 84.6058349609375], [1921.76904296875, 88.38832092285156], [1759.21728515625, 92.1707992553711]]
128
+ l=np.array(l)
129
+ r=np.array(r)
130
+ path="./nik_insinc.txt"
131
+ dic = RelativePos(path,path,unit,unit).rel_one(l, r)
132
+ print (dic)
109
133
  ```
@@ -1,4 +1,9 @@
1
- remote_run_everything/__init__.py,sha256=N8ReYbyAgZw7CjFrJMcC5ulqiJmchGcTEMD_nNPDfks,817
1
+ remote_run_everything/__init__.py,sha256=C4YH1LMe1BFN3ZXe1w09LW53iH-GTAFCRHPlVjXMKIs,956
2
+ remote_run_everything/binocular/ba_front.py,sha256=wDCW5tycvaCAEau_vxhoyUEuB_9HhUMibbxr1c1SoNk,2592
3
+ remote_run_everything/binocular/back_tool.py,sha256=eUGdkwE4TMm-hmjs4puVM-iy_iyJJuPEqdZWQxKvOGc,4873
4
+ remote_run_everything/binocular/cam_tool.py,sha256=ASZ2opsrnjhlvV7N6hn9axUjWIeQskR3t44a8oRpppw,1032
5
+ remote_run_everything/binocular/front_tool.py,sha256=lDFSvD0LBayfQLp08llhpBHwxNdCX6fypWz0dMdq6qs,1236
6
+ remote_run_everything/binocular/relative_pos.py,sha256=FX6pwXgK_JViPa1cjbHOYEYG3JFzorSNocHe7FG45JI,4732
2
7
  remote_run_everything/db/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
8
  remote_run_everything/db/backup.py,sha256=_mDUNQo1q6Gc75-diwadrooZsdV89KGG9mIcS4rmcBQ,1152
4
9
  remote_run_everything/db/crud_sqlalchemy.py,sha256=cDyDGHwE-1TUBZrXMVDTjIa4Z0ZUQvM9m9sk-eIwaSM,5192
@@ -8,6 +13,7 @@ remote_run_everything/deploy/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NM
8
13
  remote_run_everything/deploy/by_http.py,sha256=QWL3XqLTbp9O2WadPX59uR1fGJdgd9xzg1Pv8CuxfbQ,2661
9
14
  remote_run_everything/deploy/by_http_tool.py,sha256=H_-OvpayNVGG9e93Qnq5SCT0CsDbCEVtiA2kF2XVQ8U,3166
10
15
  remote_run_everything/deploy/by_sftp.py,sha256=dGb8SmhTlFntL_wRFRSubNziSy9xrd-Uzm5AdGHgHB4,2688
16
+ remote_run_everything/deploy/process_manage.py,sha256=kOf4rEH9yxyZldP_xvGSbfpUVhOxU0Jbl5jEcp5XIio,1511
11
17
  remote_run_everything/deploy/record_mod.py,sha256=29L-RTnvANpjbWRND7GGz5sdCzbz1Ba9QxdS858bdAY,725
12
18
  remote_run_everything/nosql/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
19
  remote_run_everything/nosql/no_sql.py,sha256=1-dT6LhrayQqLqZ4ES2tmWfXYCEXOnqwNzKgyXWYRG4,2343
@@ -15,14 +21,14 @@ remote_run_everything/nosql/no_sql_mysql.py,sha256=agpXc5UcevN_uojexD9pNG6xAR099
15
21
  remote_run_everything/nosql/no_sql_pg.py,sha256=XCrEnHKp5RVHPOyPOMICY2PnvNMkkIIDijTVKjk-ENc,2209
16
22
  remote_run_everything/nosql/no_sql_tool.py,sha256=xRu7vsDgr3JQNSo6CLNTtNNxlg4fl-Q7_vw4y9lklWI,2590
17
23
  remote_run_everything/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
- remote_run_everything/tools/common.py,sha256=UozWsdBwf7mGnvv5hLiaIfalhDaSaMjDOBjky8mo2w8,1747
19
- remote_run_everything/tools/common1.py,sha256=ffDHzjiLCc9vc8slaHOmH8xlzXOAtLdtVjIRkBcN7y4,3659
24
+ remote_run_everything/tools/common.py,sha256=Pk2L8J-hVqglZocwN2IOEaF3zdQQGw-ne0uRLAu40bM,4397
25
+ remote_run_everything/tools/common1.py,sha256=_x2ONfG8NrCalZ0_MPJxGH2JH3M1azBbMXPRVuPU4F4,576
20
26
  remote_run_everything/tools/decorators.py,sha256=SIacNAs7afgkU0D09J-s-YscCVnxSG8Qj9vSL4VzCHw,1988
21
27
  remote_run_everything/tools/sqlacodegen_go_struct.py,sha256=0xWJVCjFyEF2VjC1aGo6DmIqEQQ0Q46CfBAb9FSCUuE,3237
22
28
  remote_run_everything/vsconf/conf_txt.py,sha256=nhFuKLlts-sCIBmfr0IKv1pP-qPUvQQrsRRg21q5Gd4,2418
23
29
  remote_run_everything/vsconf/core.py,sha256=HmSEzXjGPY7R64rwfAV024YxMHwmBkLin6lGace4U0M,833
24
- remote_run_everything-2.0.7.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
25
- remote_run_everything-2.0.7.dist-info/METADATA,sha256=2Av2tYYjdbY14CFNFa8xGsRX0Jy_heVQRDiTUPG6ads,3121
26
- remote_run_everything-2.0.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
- remote_run_everything-2.0.7.dist-info/top_level.txt,sha256=1TUcAqPgSwiVBqUHz-1pZFXvRpr9cudEYlmfw_mztRY,22
28
- remote_run_everything-2.0.7.dist-info/RECORD,,
30
+ remote_run_everything-2.0.9.dist-info/licenses/LICENSE,sha256=6kbiFSfobTZ7beWiKnHpN902HgBx-Jzgcme0SvKqhKY,1091
31
+ remote_run_everything-2.0.9.dist-info/METADATA,sha256=0cpnt8-CRRNlR4i5lyWZJ5MtZ_l01Fufc_OkMiQn6hw,4099
32
+ remote_run_everything-2.0.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
33
+ remote_run_everything-2.0.9.dist-info/top_level.txt,sha256=1TUcAqPgSwiVBqUHz-1pZFXvRpr9cudEYlmfw_mztRY,22
34
+ remote_run_everything-2.0.9.dist-info/RECORD,,