Skip to content

Commit

Permalink
ecotaxa/ecotaxa_front#764 + Some nullity & calls clarification found …
Browse files Browse the repository at this point in the history
…out while trying last version of mypy.
  • Loading branch information
grololo06 committed Feb 7, 2023
1 parent 216f596 commit 473832c
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 16 deletions.
3 changes: 2 additions & 1 deletion py/API_models/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ class _AddedToProject(BaseModel):
process_free_cols: FreeColT = Field(title="Process free cols", description="Process free columns.", default={},
example={"nb_images": "t01"})
bodc_variables: Dict[str, Optional[str]] = Field(title="Expressions for computing standard BODC quantities.",
description="BODC quantities from columns. Only the 3 keys listed in example are valid.", default={},
description="BODC quantities from columns. Only the 3 keys listed in example are valid.",
default={},
example={"subsample_coef": "1/ssm.sub_part",
"total_water_volume": "sam.tot_vol/1000",
"individual_volume": "4.0/3.0*math.pi*(math.sqrt(obj.area/math.pi)*ssm.pixel_size)**3"})
Expand Down
1 change: 1 addition & 0 deletions py/API_models/helpers/DBtoModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def _sqlalchemy_to_pydantic(db_model: T, *,
not_null_cols = set()
# Build model from ORM fields
mapper = inspect(db_model)
assert mapper is not None
for attr in mapper.attrs:
if not isinstance(attr, ColumnProperty):
continue
Expand Down
2 changes: 1 addition & 1 deletion py/API_models/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TaxonModel(BaseModel):
id: int = Field(title="Id", description="The taxon/category IDs.", example=1)
renm_id: Optional[int] = Field(title="Renm id",
description="The advised replacement ID if the taxon/category is deprecated.",
example="null")
default=None, example="null")
name: str = Field(title="Name", description="The taxon/category verbatim name.", example="living")
type: str = Field(title="Type", description="The taxon/category type, 'M' for Morpho or 'P' for Phylo.",
example="P")
Expand Down
1 change: 1 addition & 0 deletions py/API_operations/Consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ def check_partial_time_space(self) -> List[str]:
"""
Objects which are partially located in time/space.
"""
return []
2 changes: 1 addition & 1 deletion py/API_operations/JsonDumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _find_what_to_dump(self) -> None:

with CodeTimer("Get IDs:", logger):
res: Result = self.session.execute(text(sql), params)
ids = [r['objid'] for r in res]
ids = [r['objid'] for r in res.mappings()]

logger.info("NB OBJIDS=%d", len(ids))

Expand Down
2 changes: 0 additions & 2 deletions py/API_operations/Prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from FS.MachineLearningModels import SavedModels
from FS.Vault import Vault
from helpers.DynamicLogs import get_logger, LogsSwitcher

# TODO: Move somewhere else
from .helpers.JobService import JobServiceBase, ArgsDict
from .helpers.Service import Service
Expand Down Expand Up @@ -54,7 +53,6 @@ def run(self, current_user_id: UserIDT) -> PredictionRsp:
return ret

def init_args(self, args: ArgsDict) -> ArgsDict:
super().init_args(args)
args["req"] = self.req.dict()
args["filters"] = self.filters
return args
Expand Down
3 changes: 2 additions & 1 deletion py/API_operations/exports/DarwinCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ def build_meta(self) -> Optional[EMLMeta]:

def get_taxo_coverage(self, project_ids: ProjectIDListT) -> List[EMLTaxonomicClassification]:
"""
Taxonomic coverage is the list of taxa which can be found in the projects.
Taxonomic coverage is the list of taxa which can be found in the projects, regardless
of their validation state.
"""
ret: List[EMLTaxonomicClassification] = []
# Fetch the used taxa in the projects
Expand Down
2 changes: 1 addition & 1 deletion py/BO/CommonObjectSets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# This file is part of Ecotaxa, see license.md in the application root directory for license informations.
# Copyright (C) 2015-2020 Picheral, Colin, Irisson (UPMC-CNRS)
# Copyright (C) 2015-2022 Picheral, Colin, Irisson (UPMC-CNRS)
#
from API_models.filters import ProjectFiltersDict
from BO.ObjectSet import DescribedObjectSet
Expand Down
2 changes: 1 addition & 1 deletion py/BO/Object.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def get_history(self) -> HistoricalClassificationListT:
ObjectsClassifHisto.objid == self.header.objid)
qry = qry.outerjoin(User)
qry = qry.outerjoin(Taxonomy, Taxonomy.id == och.classif_id)
ret = [HistoricalClassification(**rec) for rec in qry]
ret = [HistoricalClassification(**rec._mapping) for rec in qry]
return ret

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion py/BO/ObjectSetQueryPlus.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def get_row_source(self, ro_session: Session, wrn_fct: Optional[Callable[[str],
res = ro_session.execute(text(sql), params)
if self.sum_exp is None:
# Pure SQL, emit each row
for a_simple_row in res:
for a_simple_row in res.mappings():
yield dict(a_simple_row)
else:
assert self.grouping != ResultGrouping.NO_GROUPING
Expand Down
2 changes: 1 addition & 1 deletion py/BO/Taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def find_ids(session: Session, classif_id_seen: List):
" FROM taxonomy "
" WHERE id = ANY (:een)")
res: Result = session.execute(sql, {"een": list(classif_id_seen)})
return {int(r['id']) for r in res}
return {an_id for an_id, in res}

@staticmethod
def keep_phylo(session: Session, classif_id_seen: ClassifIDListT):
Expand Down
2 changes: 1 addition & 1 deletion py/DB/helpers/Core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# SQLAlchemy core imports, for re-export
#

from sqlalchemy.sql import select, Select
from sqlalchemy.sql import select, Select, delete, Delete, update, Update
3 changes: 1 addition & 2 deletions py/DB/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
# This file is part of Ecotaxa, see license.md in the application root directory for license informations.
# Copyright (C) 2015-2020 Picheral, Colin, Irisson (UPMC-CNRS)
#
from sqlalchemy.engine import Result # type: ignore
from sqlalchemy.orm import Session
from sqlalchemy.engine import Result, MappingResult # type: ignore
15 changes: 15 additions & 0 deletions py/formats/DarwinCore/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ class BasisOfRecordEnum(str, Enum):
livingSpecimen = 'LivingSpecimen'


class IdentificationVerificationEnum(str, Enum):
# for identifications generated by an algorithm and not validated by human.
predictedByMachine = 'PredictedByMachine'
# for identifications generated by an algorithm and verified to be correct by a
# human, this is also referred as validated data
validatedByHuman = 'ValidatedByHuman'


class OccurrenceStatusEnum(str, Enum):
present = 'present'
absent = 'absent'
Expand All @@ -108,6 +116,13 @@ class DwcOccurrence(BaseModel):
# Record-level fields
basisOfRecord: BasisOfRecordEnum = Field(term="http://rs.tdwg.org/dwc/terms/basisOfRecord")

# identified By # TODO

identificationVerificationStatus: Optional[IdentificationVerificationEnum] \
= Field(term="https://dwc.tdwg.org/list/#dwc_identificationVerificationStatus")
# identification References # TODO
# associated Media # TODO

# Identification fields
scientificName: str = Field(term="http://rs.tdwg.org/dwc/terms/scientificName")
# LSID from WoRMS for EMODnet
Expand Down
6 changes: 3 additions & 3 deletions py/helpers/fastApiUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class BearerOrCookieAuth(OAuth2):
def __init__(
self,
tokenUrl: str,
scheme_name: str = None,
scopes: dict = None,
scheme_name: Optional[str] = None,
scopes: Optional[dict] = None,
auto_error: bool = True,
):
if not scopes:
Expand All @@ -90,7 +90,7 @@ def __init__(
super().__init__(flows=flows, scheme_name=scheme_name, auto_error=auto_error)

async def __call__(self, request: Request) -> Optional[str]:
header_authorization: str = request.headers.get("Authorization")
header_authorization: Optional[str] = request.headers.get("Authorization")
session_cookie: Optional[str] = request.cookies.get("session")

header_scheme, header_param = get_authorization_scheme_param(
Expand Down

0 comments on commit 473832c

Please sign in to comment.