我正在使用送货tracking number库,并希望添加对OnTrac的支持。
根据一些示例数字(例如C10999911320231
,C10999606576777
,C11001105367744
),格式似乎是C
后跟14位数,其中第一个数字是永远是1
。还有其他格式吗?
似乎还有一个校验和,因为Google只识别某些变体(例如C10999911320231
有效,但C10999911320232
没有)。我尝试了各种算法,但无法解决。如何计算校验和?
答案 0 :(得分:2)
跟踪号码是C
后跟14位数,其中最后一位是校验位。校验位计算与UPS相同,包括将C
转换为4
。感谢OnTrac的Danielle提供此信息。
答案 1 :(得分:0)
现在,OnTrac跟踪号也可能以import numpy as np
import scipy.special
import matplotlib.pyplot as plt
def calc_bezier_path(control_points, n_points=100):
"""
Compute bezier path (trajectory) given control points.
:param control_points: (numpy array)
:param n_points: (int) number of points in the trajectory
:return: (numpy array)
"""
traj = []
for t in np.linspace(0, 1, n_points):
traj.append(bezier(t, control_points))
return np.array(traj)
def bernstein_poly(n, i, t):
"""
Bernstein polynom.
:param n: (int) polynom degree
:param i: (int)
:param t: (float)
:return: (float)
"""
return scipy.special.comb(n, i) * t ** i * (1 - t) ** (n - i)
def bezier(t, control_points):
"""
Return one point on the bezier curve.
:param t: (float) number in [0, 1]
:param control_points: (numpy array)
:return: (numpy array) Coordinates of the point
"""
n = len(control_points) - 1
return np.sum([bernstein_poly(n, i, t) * control_points[i] for i in range(n + 1)], axis=0)
def line_bezier(visx, visy, control, mod="nothing"):
vis = np.column_stack((visx,visy))
path_x, path_y = np.array([]),np.array([])
setting = {"nothing":[len(vis)-2, 1, 1], "start":[len(vis)-1, 0, 0], "end":[len(vis)-1, 1, 0], "both":[len(vis), 0, -1]}
epoch = setting[mod][0]
start = setting[mod][1]
end = setting[mod][2]
line_collection=[]
if len(vis) > 2:
current_control = vis[0]
for x in range(epoch):
if x != (epoch-1):
for y in control:
if y == control[0]:
mid_control = [(vis[x+start,0]+(vis[x+(start+1),0]-vis[x+start,0])*y), (vis[x+start,1]+(vis[x+(start+1),1]-vis[x+start,1])*y)]
plt.annotate(f"M{x}", mid_control)
bezier_line = calc_bezier_path(np.array([current_control,vis[x+start], mid_control]))
path_x = np.append(path_x, bezier_line.T[0])
path_y = np.append(path_y, bezier_line.T[1])
line_collection.append(bezier_line)
current_control = mid_control
else:
mid_control = [(vis[x+start,0]+(vis[x+(start+1),0]-vis[x+start,0])*y), (vis[x+start,1]+(vis[x+(start+1),1]-vis[x+start,1])*y)]
plt.annotate(f"M{x}", mid_control)
bezier_line = calc_bezier_path(np.array([current_control, mid_control]))
path_x = np.append(path_x, bezier_line.T[0])
path_y = np.append(path_y, bezier_line.T[1])
line_collection.append(bezier_line)
current_control = mid_control
else:
if mod == "end" or mod == "both":
bezier_line = calc_bezier_path(np.array([current_control, vis[x+(end+1)]]))
else:
bezier_line = calc_bezier_path(np.array([current_control, vis[x+end], vis[x+(end+1)]]))
path_x = np.append(path_x, bezier_line.T[0])
path_y = np.append(path_y, bezier_line.T[1])
## append the segment to the list:
line_collection.append(bezier_line)
else:
path_x, path_y = visx, visy
return path_x, path_y, line_collection
visx, visy = [1,2,10,15,20,25,21], [0,5,1,4,2,3,3]
control = [0.5]
path_x, path_y, line_collection = line_bezier(visx, visy, control,mod="end") ## init the line_collection
## iterate over list elements
for line_seg in line_collection:
plt.plot(line_seg.T[0],line_seg.T[1],linestyle="solid",linewidth=5,alpha=.5,zorder=10, label="Quadratic Bezier cruve")
#plt.plot(path_x, path_y)
plt.plot(visx, visy, "--o", label="Control Points")
for xy in range(len(visx)):
plt.annotate(f"P{xy}", [visx[xy], visy[xy]])
plt.xlabel('X')
plt.ylabel('Y')
plt.grid(True)
plt.legend()
plt.show()
开头。要计算校验位,需要在计算校验位之前将D
替换为D
。