Coverage for src/rok4_tools/tmsizer_utils/processors/processor.py: 88%
17 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-06 17:15 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-11-06 17:15 +0000
1"""Provide abstract class to define a unit processing data for tmsizer tool.
3The module contains the following classes:
5- `Processor` - Abstract class for all kinds of processor
6"""
8from typing import Dict, List, Tuple, Union, Iterator
10from rok4.tile_matrix_set import TileMatrixSet
12class Processor:
13 """Abstract class for a processor
15 A processor is a unit which treat data, item by item, and generate other items. An item could be a string, a tuple...
17 The output format define what the processor generate.
19 Attributes:
20 _processed (int): Count of input item processed
21 _format (str): Processor's output items' format
22 """
24 tms = None
25 """tms (TileMatrixSet): Pivot TMS for all processors"""
27 def __init__(self, format: str = "UNKNOWN") -> None:
28 """Constructor method
30 Set the output format and the processed count to 0.
32 Args:
33 format (str, optional): Processor's output items' format. Defaults to "UNKNOWN".
34 """
35 self._processed = 0
36 self._format = format
38 def process(self) -> Iterator:
39 """Abstract method for the processor's treatment function, as stream
41 Raises:
42 NotImplementedError: Subclasses have to implement this function
43 """
44 raise NotImplementedError("Subclasses have to implement this function")
46 @classmethod
47 def set_tms(cls, tms: TileMatrixSet):
48 """Set the pivot TMS for all processors
50 Args:
51 tms (TileMatrixSet): Pivot TMS for processings
52 """
53 cls.tms = tms
55 @property
56 def format(self) -> str:
57 """Get the output format
59 Returns:
60 str: Processor's output items' format
61 """
62 return self._format
64 def __str__(self) -> str:
65 return f"Processor : abstract class, only instance of subclasses can be used to treat data"