Commit 3a3f81d3 authored by Tim Bleimehl's avatar Tim Bleimehl 🤸🏼
Browse files

init

parent 13637494
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
from neo_meta_logger.neo_meta_logger import NeoMetaLogger
\ No newline at end of file
from typing import Union, Dict, List
import time
import py2neo
class CapturePoint():
"""The state of a Neo4j database in terms of relationship and node count at a certain time"""
def __init__(self,labels:Dict[str,int],relations:Dict[str,int]):
self.timestamp:float = time.time()
self.labels = labels
self.relations = relations
class NeoMetaLogger():
def __init__(self,connection: Union[py2neo.Graph,Dict]):
self.capture_points:List[CapturePoint] = []
if isinstance(connection, dict):
self.graph: py2neo.Graph = py2neo.Graph(**connection)
elif isinstance(connection,py2neo.Graph):
self.graph = connection
else:
raise TypeError(f"Expected 'py2neo.Graph' or 'dict'. Got '{type(connection)}'")
def capture(self):
labels_count = self._count_labels()
relations_count = self._count_relations()
self.capture_points.append(CapturePoint(labels_count, relations_count))
def _count_labels(self) -> Dict[str,int]:
all_labels: List[str] = self.graph.run("CALL db.labels() yield label return collect(label) as res").data()[0]["res"]
labels_count: Dict[str,int] = {}
for label in all_labels:
query_label_count = f"""
MATCH (n:{label})
RETURN count(n) AS res
"""
labels_count[label] = self.graph.run(query_label_count).data()[0]["res"]
return labels_count
def _count_relations(self) -> Dict[str,int]:
pass
def get_last_changes(self) -> Dict[str,Dict[str,int]]:
"""Get changes, in terms of quantity, of labels and relations since the last capture compared to the current capture
Returns:
Dict[str,Dict[str,int]]: A base dictonary "{'labels':{...},'relation':{...}}" containing two dictoniries listing changes (in terms of quantity) for labels and relations.
"""
pass
def get_changes_since(self,capture:CapturePoint=None,capture_index:int=None,time:float=None) -> Dict[str,Dict[str,int]]:
"""Get changes, in terms of quantity, of labels and relations since the last capture compared to the current capture
Returns:
Dict[str,Dict[str,int]]: A base dictonary "{'labels':{...},'relation':{...}}" containing two dictoniries listing changes (in terms of quantity) for labels and relations.
"""
pass
py2neo
\ No newline at end of file
import sys
import os
if __name__ == "__main__":
SCRIPT_DIR = os.path.dirname(
os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__)))
)
SCRIPT_DIR = os.path.join(SCRIPT_DIR, "..")
print(os.path.normpath(SCRIPT_DIR))
sys.path.insert(0, os.path.normpath(SCRIPT_DIR))
from neo_meta_logger import NeoMetaLogger
mlog = NeoMetaLogger({})
mlog.capture()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment