我在Pymongo中发挥了拖曳功能,但是我想要的是与从功能中获得的不同想法有所不同?

发布于 2025-01-31 12:09:01 字数 850 浏览 1 评论 0原文

节省关闭,符号,时间范围

    def Save_(self,collection,symbol,price,TF):
    db = self.get_db('MTF')[collection]
    B = {'ts':time.time(),"Symbol":symbol,
                    "Price":price,'TimeFrame':TF}
    data = db.insert_one(B)
    return data

获取数据

def find_all(self,collection):
    db = self.get_db('MTF')[collection]
    Symbols ={}
    data = db.find({})
    for i in data:
        Symbols[i['Symbol']] = [i['Price'],i['TimeFrame']]
    return Symbols

功能的函数从mongodb [2]: https://i.sstatic.net/rltnz.png

功能 [1]: https://i.sstatic.net/atwsy.png

如果您看到的话函数B的图像仅在时间范围内给了我,但是功能保存有4个时间范围

Funtion that save Close,Symbol, Timeframe

    def Save_(self,collection,symbol,price,TF):
    db = self.get_db('MTF')[collection]
    B = {'ts':time.time(),"Symbol":symbol,
                    "Price":price,'TimeFrame':TF}
    data = db.insert_one(B)
    return data

Function to get data from mongodb

def find_all(self,collection):
    db = self.get_db('MTF')[collection]
    Symbols ={}
    data = db.find({})
    for i in data:
        Symbols[i['Symbol']] = [i['Price'],i['TimeFrame']]
    return Symbols

images from mongodb
[2]: https://i.sstatic.net/RLtnz.png

images from B Function
[1]: https://i.sstatic.net/AtwSy.png

if u see the image from Function B only gave me on timeframe but Function Save have 4 timeframe

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光的暖冬 2025-02-07 12:09:01

查看此循环:

for i in data:
    Symbols[i['Symbol']] = [i['Price'],i['TimeFrame']]

如果您的符号来自MongoDB,它将覆盖任何先前的值,因此您只会获得每个符号的最终值,这就是您所看到的。

要修复它,您有一些选项:您可以检查键并创建值或将值附加到符号;或者,您可以在汇总查询中使用$ push

Looking at this loop:

for i in data:
    Symbols[i['Symbol']] = [i['Price'],i['TimeFrame']]

If you have the same Symbol coming from MongoDB, it will overwrite any previous value, so you will only get the final value for each Symbol which is what you are seeing.

To fix it you have a few options: you could check the key and either create or append the values to Symbols; or you could use $push in an aggregate query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文