imio.pyutils 1.0.1__tar.gz → 1.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/CHANGES.rst +6 -0
  2. {imio.pyutils-1.0.1/imio.pyutils.egg-info → imio_pyutils-1.0.2}/PKG-INFO +10 -4
  3. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/imio/pyutils/tests.py +21 -0
  4. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/imio/pyutils/utils.py +53 -1
  5. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2/imio.pyutils.egg-info}/PKG-INFO +10 -4
  6. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/imio.pyutils.egg-info/SOURCES.txt +0 -1
  7. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/setup.py +1 -1
  8. imio.pyutils-1.0.1/imio.pyutils.egg-info/entry_points.txt +0 -3
  9. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/MANIFEST.in +0 -0
  10. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/Makefile +0 -0
  11. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/README.rst +0 -0
  12. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/imio/__init__.py +0 -0
  13. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/imio/pyutils/__init__.py +0 -0
  14. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/imio/pyutils/bs.py +0 -0
  15. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/imio/pyutils/postgres.py +0 -0
  16. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/imio/pyutils/system.py +0 -0
  17. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/imio.pyutils.egg-info/dependency_links.txt +0 -0
  18. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/imio.pyutils.egg-info/namespace_packages.txt +0 -0
  19. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/imio.pyutils.egg-info/not-zip-safe +0 -0
  20. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/imio.pyutils.egg-info/requires.txt +1 -1
  21. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/imio.pyutils.egg-info/top_level.txt +0 -0
  22. {imio.pyutils-1.0.1 → imio_pyutils-1.0.2}/setup.cfg +0 -0
@@ -1,6 +1,12 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ 1.0.2 (2024-05-15)
5
+ ------------------
6
+
7
+ - Added a new helper `utils.get_ordinal_clusters` to cluster ordinal numbers based on an offset.
8
+ [aduchene]
9
+
4
10
  1.0.1 (2024-04-08)
5
11
  ------------------
6
12
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: imio.pyutils
3
- Version: 1.0.1
3
+ Version: 1.0.2
4
4
  Summary: Some python useful methods
5
5
  Home-page: https://github.com/imio/imio.pyutils/
6
6
  Author: IMIO
@@ -9,13 +9,15 @@ License: GPL
9
9
  Project-URL: PyPI, https://pypi.python.org/pypi/imio.pyutils
10
10
  Project-URL: Source, https://github.com/imio/imio.pyutils
11
11
  Keywords: Python IMIO
12
- Platform: UNKNOWN
13
12
  Classifier: Development Status :: 5 - Production/Stable
14
13
  Classifier: License :: OSI Approved :: GNU General Public License (GPL)
15
14
  Classifier: Operating System :: OS Independent
16
15
  Classifier: Programming Language :: Python
17
16
  Classifier: Programming Language :: Python :: 2.7
18
17
  Classifier: Programming Language :: Python :: 3.10
18
+ Requires-Dist: setuptools
19
+ Requires-Dist: future
20
+ Requires-Dist: six>=1.16.0
19
21
 
20
22
  .. image:: https://github.com/IMIO/imio.pyutils/actions/workflows/main.yml/badge.svg?branch=master
21
23
  :target: https://github.com/IMIO/imio.pyutils/actions/workflows/main.yml
@@ -80,6 +82,12 @@ Can be run with: `bin/python -m unittest discover`
80
82
  Changelog
81
83
  =========
82
84
 
85
+ 1.0.2 (2024-05-15)
86
+ ------------------
87
+
88
+ - Added a new helper `utils.get_ordinal_clusters` to cluster ordinal numbers based on an offset.
89
+ [aduchene]
90
+
83
91
  1.0.1 (2024-04-08)
84
92
  ------------------
85
93
 
@@ -337,5 +345,3 @@ Changelog
337
345
 
338
346
  - Initial release.
339
347
  [sgeulette]
340
-
341
-
@@ -10,6 +10,7 @@ from imio.pyutils.system import read_recursive_dir
10
10
  from imio.pyutils.utils import all_of_dict_values
11
11
  from imio.pyutils.utils import append
12
12
  from imio.pyutils.utils import get_clusters
13
+ from imio.pyutils.utils import get_ordinal_clusters
13
14
  from imio.pyutils.utils import insert_in_ordereddict
14
15
  from imio.pyutils.utils import iterable_as_list_of_list
15
16
  from imio.pyutils.utils import letters_sequence
@@ -55,6 +56,26 @@ class TestUtils(unittest.TestCase):
55
56
  self.assertEqual(get_clusters([1, 2, 4, 5, 15], separator="|"),
56
57
  '1-2|4-5|15')
57
58
 
59
+ def test_get_ordinal_clusters(self):
60
+ self.assertEqual(get_ordinal_clusters([100, 200, 300, 500, 600, 800, 1000, 1500]),
61
+ '1-3, 5-6, 8, 10, 15')
62
+ self.assertEqual(get_ordinal_clusters([100, 200, 300, 500, 501, 503, 600, 700, 1000, 1500]),
63
+ '1-3, 5-5.1, 5.3, 6-7, 10, 15')
64
+ self.assertEqual(
65
+ get_ordinal_clusters(
66
+ [100, 200, 300, 400, 500, 501, 502, 521, 522, 540, 550, 1200, 1300], separator="|"),
67
+ '1-5.2|5.21-5.22|5.40|5.50|12-13')
68
+ self.assertEqual(
69
+ get_ordinal_clusters(
70
+ [100, 200, 300, 301, 302, 321, 322, 340, 1199, 1200, 1300], cluster_format="from {} to {}"),
71
+ 'from 1 to 3.2, from 3.21 to 3.22, 3.40, 11.99, from 12 to 13')
72
+ self.assertEqual(get_ordinal_clusters([100, 200, 250, 400, 700], single_cluster_format="({})"),
73
+ '1-2, (2.50), (4), (7)')
74
+ self.assertEqual(get_ordinal_clusters([10, 20, 30, 31, 32, 110, 112, 130], offset=10),
75
+ '1-3.2, 11, 11.2, 13')
76
+ self.assertListEqual(get_ordinal_clusters([100, 200, 250, 400, 700], as_str=False),
77
+ [[100, 200], [250], [400], [700]])
78
+
58
79
  def test_insert_in_ordered_dict(self):
59
80
  dic = OrderedDict([('a', 1), ('b', 2)])
60
81
  self.assertEqual(insert_in_ordereddict(dic, ('bad', 3)), None)
@@ -63,6 +63,58 @@ def get_clusters(numbers=[], separator=", "):
63
63
  return separator.join(res)
64
64
 
65
65
 
66
+ def display_offset_number(number, offset):
67
+ """Display a number with an offset. For example when p_number=123 and offset=100, it returns '1.23'"""
68
+ if number % offset == 0:
69
+ return str(int(number / offset))
70
+ return '{}.{}'.format(number // offset, number % offset)
71
+
72
+
73
+ def get_ordinal_clusters(
74
+ numbers=[],
75
+ cluster_format="{0}-{1}",
76
+ single_cluster_format="{0}",
77
+ separator=", ",
78
+ offset=100,
79
+ as_str=True):
80
+ """Return given p_numbers by clusters while taking care of the offset (used for sub numering).
81
+ p_offset should be a power of 10, it doesn't make any sense otherwise.
82
+ When p_numbers=[100,200,300,400,500,501,502,521,522,540,550,700,1200,1300] and p_offset=100,
83
+ the result is '1-5.2, 5.21-5.22, 5.40, 5.50, 7, 12-13'."""
84
+
85
+ def _is_in_cluster(number, cluster, offset):
86
+ """Check if a number is in a cluster.
87
+ A number is in a cluster if it follows directly the last number according to the offset"""
88
+ if len(cluster) > 0:
89
+ if number % offset == 0:
90
+ return number - cluster[-1] == offset
91
+ return number - cluster[-1] == 1
92
+ return True
93
+
94
+ # Initialize the first group
95
+ clusters = []
96
+ current_cluster = [numbers[0]]
97
+ for num in numbers[1:]:
98
+ if _is_in_cluster(num, current_cluster, offset):
99
+ current_cluster.append(num)
100
+ else: # we'll start a new cluster
101
+ clusters.append(current_cluster)
102
+ current_cluster = [num]
103
+ clusters.append(current_cluster) # Add the last one
104
+
105
+ if not as_str:
106
+ return clusters
107
+
108
+ res = []
109
+ for cluster in clusters:
110
+ if len(cluster) > 1:
111
+ res.append(cluster_format.format(display_offset_number(cluster[0], offset),
112
+ display_offset_number(cluster[-1], offset)))
113
+ else:
114
+ res.append(single_cluster_format.format(display_offset_number(cluster[0], offset)))
115
+ return separator.join(res)
116
+
117
+
66
118
  def insert_in_ordereddict(dic, value, after_key='', at_position=None):
67
119
  """Insert a tuple in an new Ordereddict.
68
120
 
@@ -180,7 +232,7 @@ def radix_like_starting_1(n, base, L=[]): # noqa
180
232
  L.reverse()
181
233
  return L
182
234
  else:
183
- return radix_like_starting_1((n % base) and (n // base) or (n // base) -1 , base, L + [(n % base) or base])
235
+ return radix_like_starting_1((n % base) and (n // base) or (n // base) - 1, base, L + [(n % base) or base])
184
236
 
185
237
 
186
238
  def replace_in_list(lst, value, replacement, generator=False):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: imio.pyutils
3
- Version: 1.0.1
3
+ Version: 1.0.2
4
4
  Summary: Some python useful methods
5
5
  Home-page: https://github.com/imio/imio.pyutils/
6
6
  Author: IMIO
@@ -9,13 +9,15 @@ License: GPL
9
9
  Project-URL: PyPI, https://pypi.python.org/pypi/imio.pyutils
10
10
  Project-URL: Source, https://github.com/imio/imio.pyutils
11
11
  Keywords: Python IMIO
12
- Platform: UNKNOWN
13
12
  Classifier: Development Status :: 5 - Production/Stable
14
13
  Classifier: License :: OSI Approved :: GNU General Public License (GPL)
15
14
  Classifier: Operating System :: OS Independent
16
15
  Classifier: Programming Language :: Python
17
16
  Classifier: Programming Language :: Python :: 2.7
18
17
  Classifier: Programming Language :: Python :: 3.10
18
+ Requires-Dist: setuptools
19
+ Requires-Dist: future
20
+ Requires-Dist: six>=1.16.0
19
21
 
20
22
  .. image:: https://github.com/IMIO/imio.pyutils/actions/workflows/main.yml/badge.svg?branch=master
21
23
  :target: https://github.com/IMIO/imio.pyutils/actions/workflows/main.yml
@@ -80,6 +82,12 @@ Can be run with: `bin/python -m unittest discover`
80
82
  Changelog
81
83
  =========
82
84
 
85
+ 1.0.2 (2024-05-15)
86
+ ------------------
87
+
88
+ - Added a new helper `utils.get_ordinal_clusters` to cluster ordinal numbers based on an offset.
89
+ [aduchene]
90
+
83
91
  1.0.1 (2024-04-08)
84
92
  ------------------
85
93
 
@@ -337,5 +345,3 @@ Changelog
337
345
 
338
346
  - Initial release.
339
347
  [sgeulette]
340
-
341
-
@@ -7,7 +7,6 @@ imio/__init__.py
7
7
  imio.pyutils.egg-info/PKG-INFO
8
8
  imio.pyutils.egg-info/SOURCES.txt
9
9
  imio.pyutils.egg-info/dependency_links.txt
10
- imio.pyutils.egg-info/entry_points.txt
11
10
  imio.pyutils.egg-info/namespace_packages.txt
12
11
  imio.pyutils.egg-info/not-zip-safe
13
12
  imio.pyutils.egg-info/requires.txt
@@ -1,6 +1,6 @@
1
1
  from setuptools import setup, find_packages
2
2
 
3
- version = '1.0.1'
3
+ version = '1.0.2'
4
4
 
5
5
  setup(name='imio.pyutils',
6
6
  version=version,
@@ -1,3 +0,0 @@
1
-
2
- # -*- Entry points: -*-
3
-
File without changes
File without changes
File without changes
@@ -1,3 +1,3 @@
1
- future
2
1
  setuptools
2
+ future
3
3
  six>=1.16.0
File without changes