1111
1212
1313def mean_compressor (sequence : list [T ], target_size : int ) -> list [T ]:
14+ """
15+ A compression method that reduces data memory usage by averaging adjacent numbers and merging them.
16+ :param sequence: the sequence to compress
17+ :param target_size: expected size
18+ :return: the compressed sequence
19+ """
1420 chunk_size = int (len (sequence ) / target_size )
1521 if chunk_size < 2 :
1622 return sequence
@@ -22,6 +28,11 @@ def mean_compressor(sequence: list[T], target_size: int) -> list[T]:
2228
2329
2430def csv_stringifier (element : T ) -> str :
31+ """
32+ Dump an element as a CSV string.
33+ :param element: the element to stringify
34+ :return: CSV string
35+ """
2536 return str (element ) + ","
2637
2738
@@ -32,6 +43,13 @@ def __init__(self,
3243 chunk_scale : int = 1 ,
3344 compressor : Compressor = mean_compressor ,
3445 stringifier : Stringifier = csv_stringifier ) -> None :
46+ """
47+ :param file: the file into which the data is written
48+ :param max_size: maximum cached size
49+ :param chunk_scale: chunk scaling factor (compression)
50+ :param compressor: compressor interface
51+ :param stringifier: stringifier interface
52+ """
3553 self ._file : _TextIO = open (file , "a" ) if isinstance (file , str ) else file
3654 self ._max_size : int = max_size
3755 self ._chunk_scale : int = chunk_scale
0 commit comments