mirror of
https://github.com/qurator-spk/modstool.git
synced 2025-06-26 03:59:55 +02:00
🤓 Add type annotations (and related changes)
This commit is contained in:
parent
d685454c52
commit
ebdded90d6
1 changed files with 11 additions and 9 deletions
|
@ -4,7 +4,7 @@ from itertools import groupby
|
||||||
import re
|
import re
|
||||||
import warnings
|
import warnings
|
||||||
import os
|
import os
|
||||||
from typing import List, Sequence, MutableMapping, Dict
|
from typing import Any, List, Sequence, MutableMapping, Dict
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
@ -229,12 +229,14 @@ class TagGroup:
|
||||||
Extract values using the given XPath expression, convert them to float and return descriptive
|
Extract values using the given XPath expression, convert them to float and return descriptive
|
||||||
statistics on the values.
|
statistics on the values.
|
||||||
"""
|
"""
|
||||||
|
def xpath_values():
|
||||||
values = []
|
values = []
|
||||||
for e in self.group:
|
for e in self.group:
|
||||||
r = e.xpath(xpath_expr, namespaces=namespaces)
|
r = e.xpath(xpath_expr, namespaces=namespaces)
|
||||||
values += r
|
values += r
|
||||||
values = np.array([float(v) for v in values])
|
return np.array([float(v) for v in values])
|
||||||
|
|
||||||
|
values = xpath_values()
|
||||||
statistics = {}
|
statistics = {}
|
||||||
if values.size > 0:
|
if values.size > 0:
|
||||||
statistics[f'{xpath_expr}-mean'] = np.mean(values)
|
statistics[f'{xpath_expr}-mean'] = np.mean(values)
|
||||||
|
@ -294,7 +296,7 @@ def flatten(d: MutableMapping, parent='', separator='_') -> dict:
|
||||||
|
|
||||||
It is assumed that d maps strings to either another dictionary (similarly structured) or some other value.
|
It is assumed that d maps strings to either another dictionary (similarly structured) or some other value.
|
||||||
"""
|
"""
|
||||||
items = []
|
items: list[Any] = []
|
||||||
|
|
||||||
for k, v in d.items():
|
for k, v in d.items():
|
||||||
if parent:
|
if parent:
|
||||||
|
@ -324,8 +326,8 @@ def column_names_csv(columns) -> str:
|
||||||
"""
|
"""
|
||||||
return ",".join('"' + c + '"' for c in columns)
|
return ",".join('"' + c + '"' for c in columns)
|
||||||
|
|
||||||
current_columns: defaultdict = defaultdict(list)
|
current_columns: dict[str, list] = defaultdict(list)
|
||||||
current_columns_types: dict[dict] = defaultdict(dict)
|
current_columns_types: dict[str, dict] = defaultdict(dict)
|
||||||
|
|
||||||
def insert_into_db(con, table, d: Dict):
|
def insert_into_db(con, table, d: Dict):
|
||||||
"""Insert the values from the dict into the table, creating columns if necessary"""
|
"""Insert the values from the dict into the table, creating columns if necessary"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue