Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Can';似乎无法使CodernityDB索引正常工作_Python_Codernity - Fatal编程技术网

Python Can';似乎无法使CodernityDB索引正常工作

Python Can';似乎无法使CodernityDB索引正常工作,python,codernity,Python,Codernity,我正在我的一个项目中试用CodernityDB。我运行了minitwit示例,但是在我的项目中尝试一些示例代码似乎不起作用。我似乎错过了什么 from CodernityDB.database_thread_safe import ThreadSafeDatabase from CodernityDB.hash_index import HashIndex import uuid class PumpIndex(HashIndex): def __init__(self, *arg

我正在我的一个项目中试用CodernityDB。我运行了minitwit示例,但是在我的项目中尝试一些示例代码似乎不起作用。我似乎错过了什么

from CodernityDB.database_thread_safe import ThreadSafeDatabase
from CodernityDB.hash_index import HashIndex

import uuid

class PumpIndex(HashIndex):

    def __init__(self, *args, **kwargs):
        kwargs['key_format'] = '32s'
        super(PumpIndex, self).__init__(*args, **kwargs)

    def make_key_value(self, data):
        if data['t'] == 'pump':
            id = data['id']
            # if not isinstance(login, basestring):
            #     login = str(login)
            return id, {'name': data['name']}

    def make_key(self, key):
        return key

    def run_all(self, db):
        it = db.get_many(self.name, with_doc=True)
        for curr in it:
            curr['id'] = curr['doc']['id']
            curr['name'] = curr['doc']['name']
            curr['hardware_type'] = curr['doc']['hardware_type']
            curr['onboard_pump_id'] = curr['doc']['onboard_pump_id']
            curr['pressure_sensor_id'] = curr['doc']['pressure_sensor_id']
            curr['pressure_min'] = curr['doc']['pressure_min']
            curr['pressure_max'] = curr['doc']['pressure_max']
            curr['ignore_errors'] = curr['doc']['ignore_errors']
            curr['simultaneous_zones'] = curr['doc']['simultaneous_zones']
            del curr['doc']
            yield curr

db = ThreadSafeDatabase('~/Desktop/test')

if db.exists():
    db.open()
    db.reindex()
else:

    db.create()
    db.add_index(PumpIndex(db.path, 'pump'))

for x in range(0,10):
    id = uuid.uuid4().hex
    name = 'Test %d' % x
    db.insert(dict(
                t='pump',
                id=id,
                name=name,
                hardware_type="onboard",
                onboard_pump_id=None,
                pressure_sensor_id=None,
                pressure_min=None,
                pressure_max=None,
                ignore_errors=None,
                simultaneous_zones=None
            ))

print int(db.count(db.get_many, 'pump'))
print int(len(list(db.run('pump', 'all'))))
我得到的控制台输出:

{'status': 'o', 'start': 100, 'self': <CodernityDB.storage.IU_Storage object at 0x10bb1ed50>, 'size': 204}
{'status': 'o', 'start': 304, 'self': <CodernityDB.storage.IU_Storage object at 0x10bb1ed50>, 'size': 204}
{'status': 'o', 'start': 508, 'self': <CodernityDB.storage.IU_Storage object at 0x10bb1ed50>, 'size': 204}
{'status': 'o', 'start': 712, 'self': <CodernityDB.storage.IU_Storage object at 0x10bb1ed50>, 'size': 204}
{'status': 'o', 'start': 916, 'self': <CodernityDB.storage.IU_Storage object at 0x10bb1ed50>, 'size': 204}
{'status': 'o', 'start': 1120, 'self': <CodernityDB.storage.IU_Storage object at 0x10bb1ed50>, 'size': 204}
{'status': 'o', 'start': 1324, 'self': <CodernityDB.storage.IU_Storage object at 0x10bb1ed50>, 'size': 204}
{'status': 'o', 'start': 1528, 'self': <CodernityDB.storage.IU_Storage object at 0x10bb1ed50>, 'size': 204}
{'status': 'o', 'start': 1732, 'self': <CodernityDB.storage.IU_Storage object at 0x10bb1ed50>, 'size': 204}
{'status': 'o', 'start': 1936, 'self': <CodernityDB.storage.IU_Storage object at 0x10bb1ed50>, 'size': 204}
0
0
{'status':'o','start':100,'self':,'size':204}
{'status':'o','start':304,'self':,'size':204}
{'status':'o','start':508,'self':,'size':204}
{'status':'o','start':712,'self':,'size':204}
{'status':'o','start':916,'self':,'size':204}
{'status':'o','start':1120,'self':,'size':204}
{'status':'o','start':1324,'self':,'size':204}
{'status':'o','start':1528,'self':,'size':204}
{'status':'o','start':1732,'self':,'size':204}
{'status':'o','start':1936,'self':,'size':204}
0
0

另一个问题,是否有可能无法获得Codernity的状态输出?它对开发很有用,但对生产却不太有用。

似乎方法
get\u many
on为给定的键返回多个数据。因此,它不会返回所有数据。改用
all
方法

db.count(db.all, 'pump')

经过一点打猎,我发现了这个假指纹

CodernityDB\storage.py::135中,
get()
方法打印局部变量:


在不编辑网站包的情况下,我用自己的方法修补了该方法。

您发现如何删除控制台打印输出了吗?
    def get(self, start, size, status='c'):
       if status == 'd':
           return None
       else:
           print locals()
           self._f.seek(start)
           return self.data_from(self._f.read(size))