这可能值得针对Cloud Pub / Sub服务出现问题。但是到目前为止,GCP支持并没有真正帮助,因此我将在此发布。
根据here,Pubsub消息应具有messageId属性,无论是来自pull还是push。
所以我试图查看消息的外观:(这里的事件是发布到云功能的pubsub消息)
exports.my_cloud_function = (event) => {
logger.debug(`Event: ${util.inspect(event)}`);
}
我所期望的:
{ '@type': 'type.googleapis.com/google.pubsub.v1.PubsubMessage', messageId:'111111111', publishTime: 'Oct 1st 2019, xxxx', attributes: { key1: 'value1', key2: 'value2' }, data: 'eLCJ=(some base 64)' }
实际上是什么:
{ '@type': 'type.googleapis.com/google.pubsub.v1.PubsubMessage', attributes: { key1: 'value1', key2: 'value2' }, data: 'eLCJ=(some base 64)' }
答案 0 :(得分:2)
如果我猜对了,那么您正在使用带事件触发器的Cloud Function。这是一个常见的陷阱(我在其中多次感到...)。
因此,在事件格式中,publishedTime和messageId在def FeatureNormalisation(X):
normalised_X = X.copy()
mu = []
sigma = []
for i in range(X.shape[1]):
mean = np.mean(X[:,i])
std = np.std(X[:,i])
normalised_X[:,i] = np.divide(X[:,i] - mean, std)
mu.append(mean)
sigma.append(std)
return normalised_X, np.asarray(mu), np.asarray(sigma)
def PCA(X):
m, n = X.shape
sigma = np.divide(np.matmul(X.T,X),m)
U, S, V = np.linalg.svd(sigma)
return U, S # Eigen vectors and Eigen values
def ProjectData(X, U, K):
return np.dot(U[:,:K].T, X.T)
def RecoverData(Z, U, K):
return (U[:,:K] * Z).T
X_norm, mu, sigma = FeatureNormalisation(X)
U, S = PCA(X_norm)
plt.figure()
plt.title("Original")
plt.scatter(X[:,0], X[:,1], edgecolors='blue', facecolors='none')
plt.quiver(*mu, U[:,0], U[:,1], color=['g', 'r'], scale=4)
plt.figure()
plt.title("Normalised")
origin = np.divide(np.sum(X_norm, axis=0),X_norm.shape[0])
plt.quiver(*origin, U[:,0], U[:,1], color=['g', 'r'], scale=4)
plt.scatter(X_norm[:,0], X_norm[:,1], edgecolors='red', facecolors='none')
K = 1
Z = ProjectData(X_norm, U, K)
X_recovered = RecoverData(Z, U, K)
plt.figure()
plt.title("Recovered data")
centre = np.divide(np.sum(X_recovered, axis=0),X_recovered.shape[0])
plt.quiver(*centre, U[:,0], U[:,1], color=['g', 'r'], scale=4)
plt.scatter(X_recovered[:,0], X_recovered[:,1], edgecolors='green', facecolors='none')
plt.show()
对象中,而不是在事件here中描述
在您的函数中,将上下文添加到param中,然后进行打印。应该可以。
plt.quiver()