我是 rxjava/rxkotlin/rxandroid 的初学者。
我需要按顺序处理三个不同的异步调用。问题是第一步返回 a Single<LocationResult>,第二步返回 a Completable,第三步返回 a Completable。
(单个 -> 可完成 -> 可完成)
现在的问题是最后一个Completable取决于第一个的数据Single
我当前的解决方案:
我认为这是一个糟糕的解决方案,但我不知道如何正确地做到这一点。
val ft = FenceTransaction(applicationContext, apiClient)
stream
.flatMap { locationResult ->
ft.removeAll()
return@flatMap ft.commit().toSingle({ return@toSingle locationResult })
}
.flatMapCompletable {
ft.recycle()
ft.setZone(it.location.longitude, it.location.latitude, ZONE_RADIUS)
val dots = DotFilter().getFilteredDots()
for (dot in dots) {
ft.addDot(dot)
}
return@flatMapCompletable ft.commit()
}
.subscribeBy(
onComplete = {
"transaction complete".logi(this)
},
onError = {
"transaction error".logi(this)
})
Run Code Online (Sandbox Code Playgroud)
这种方法是正确的方法吗?
我应该如何处置Completeables?一般我应该什么时候处置Observables?
为什么这段代码会产生如此奇怪的输出?
我希望图重叠,以便我可以看到重叠的数据点。
这些情节似乎是相互堆叠的。
def read_csv(name):
file = open(folder+name,newline='')
reader = csv.reader(file,delimiter=";")
data = []
for row in reader:
data.append(np.array(row[5:]))
file.close()
return data
def setup_plotting():
fig = plt.figure()
ax = fig.add_subplot(111)
ax.xaxis.set_major_locator(plt.MaxNLocator(10))
ax.yaxis.set_major_locator(plt.MaxNLocator(10))
return ax
acc_x = read_csv("acc_x.csv")
ax=setup_plotting()
for entry in acc_x:
ax.plot(entry)
Run Code Online (Sandbox Code Playgroud)
请帮我 :)
android ×1
data-science ×1
matplotlib ×1
plot ×1
python ×1
reactivex ×1
rx-java2 ×1
rx-kotlin ×1