Skip to content
Snippets Groups Projects
Commit 4e9d33d1 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

MAINT: docs and string conversion only for specific types

parent cf37824d
No related branches found
No related tags found
2 merge requests!71REL: RElease v0.2.0,!59Fix hash function
Pipeline #29516 failed
...@@ -23,22 +23,30 @@ ...@@ -23,22 +23,30 @@
# ** end header # ** end header
# #
"""
stores identified records and is able to detect duplicates
"""
import caosdb as db
from hashlib import sha256
""" """
This module is a cache for Records where we checked the existence in a remote server using
identifiables. If the Record was found, this means that we identified the corresponding Record
in the remote server and the ID of the local object can be set.
To prevent querying the server again and again for the same objects, this cache allows storing
Records that were found on a remote server and those that were not (typically in separate caches).
The look up in the cache is done using a hash of a string representation.
TODO: We need a general review: TODO: We need a general review:
- How are entities identified with each other? - How are entities identified with each other?
- What happens if the identification fails? - What happens if the identification fails?
Checkout how this was done in the old crawler.
""" """
import caosdb as db
from hashlib import sha256
from datetime import datetime
def _value_representation(value): def _value_representation(value):
"""returns the string representation of property values to be used in the hash function """
# TODO: (for review) # TODO: (for review)
# This expansion of the hash function was introduced recently # This expansion of the hash function was introduced recently
...@@ -54,8 +62,11 @@ def _value_representation(value): ...@@ -54,8 +62,11 @@ def _value_representation(value):
return "PyID="+str(id(value)) return "PyID="+str(id(value))
elif isinstance(value, list): elif isinstance(value, list):
return "["+", ".join([_value_representation(el) for el in value])+"]" return "["+", ".join([_value_representation(el) for el in value])+"]"
else: elif (isinstance(value, str) or isinstance(value, int) or isinstance(value, float)
or isinstance(value, datetime)):
return str(value) return str(value)
else:
raise ValueError(f"Unknown datatype of the value: {value}")
def _create_hashable_string(identifiable: db.Record): def _create_hashable_string(identifiable: db.Record):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment