Skip to content

Commit

Permalink
Improve logging. Improve sphinx index.
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Nov 29, 2021
1 parent 41b6b9f commit ded0749
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## Unreleased

### Changes
- Some log levels have been adjusted ([#689](../../pull/689))

## Version 1.8.7

### Improvements
Expand Down
3 changes: 2 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = []
html_static_path = ['static']
html_css_files = ['custom.css']

autoclass_content = 'both'
1 change: 0 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ Indices and tables

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
10 changes: 10 additions & 0 deletions docs/source/static/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.indextable.genindextable td {
padding-right: 10px
}
.indextable.genindextable li {
word-break: break-word;
}
.indextable.genindextable a:before {
content: "\2022\00A0";
}

Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ def _similarElementStructure(self, a, b, parentKey=None): # noqa
return True

def validate(self, doc):
starttime = time.time()
startTime = lastTime = time.time()
try:
# This block could just use the json validator:
# jsonschema.validate(doc.get('annotation'),
Expand All @@ -951,7 +951,7 @@ def validate(self, doc):
annot['elements'] = []
self.validatorAnnotation.validate(annot)
lastValidatedElement = None
for element in elements:
for idx, element in enumerate(elements):
if isinstance(element.get('id'), ObjectId):
element['id'] = str(element['id'])
# Handle elements with large arrays by checking that a
Expand All @@ -972,10 +972,15 @@ def validate(self, doc):
lastValidatedElement = element
if key:
element[key] = keydata
if time.time() - lastTime > 10:
logger.info('Validated %s of %d elements in %5.3fs',
idx + 1, len(elements), time.time() - startTime)
lastTime = time.time()
annot['elements'] = elements
except jsonschema.ValidationError as exp:
raise ValidationException(exp)
logger.debug('Validated in %5.3fs' % (time.time() - starttime))
if time.time() - startTime > 10:
logger.info('Validated in %5.3fs' % (time.time() - startTime))
elementIds = [entry['id'] for entry in
doc['annotation'].get('elements', []) if 'id' in entry]
if len(set(elementIds)) != len(elementIds):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def updateElements(self, annotation):
:param annotation: the annotation to save elements for. Modified.
"""
startTime = time.time()
startTime = lastTime = time.time()
elements = annotation['annotation'].get('elements', [])
if not len(elements):
return
Expand All @@ -464,10 +464,11 @@ def updateElements(self, annotation):
if 'id' not in entry['element']:
entry['element']['id'] = str(res.inserted_ids[pos])
# If the whole insert is slow, log information about it.
if time.time() - startTime > 10:
if time.time() - lastTime > 10:
logger.info('insert %d elements in %4.2fs (prep time %4.2fs), done %d/%d' % (
len(entries), time.time() - chunkStartTime, prepTime,
chunk + len(entries), len(elements)))
lastTime = time.time()
if time.time() - startTime > 10:
logger.info('inserted %d elements in %4.2fs' % (
len(elements), time.time() - startTime))
Expand Down

0 comments on commit ded0749

Please sign in to comment.