Python 3.11.2 (main, Mar 24 2023, 00:16:47) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> import hygiene
+>>> from hygiene import Singleton
+>>> # Example JSON string
+>>> singletons = [
+ {"name": "John", "age": 30, "city": "New York"},
+ '{"name": "John", "age": 30, "city": "New York"}',
+ list({"name": "John", "age": 30, "city": "New York"}),
+ [{"name": "John", "age": 30, "city": "New York"}]
+ ]
+>>> milvus_payload_examples = [
+ {"count": 10, "sizes": [35, 36, 38]},
+ {"price": 11.99,"ratings": [9.1, 9.2, 9.4]},
+ {"is_delivered": True,"responses": [False, False, True, False]},
+ {"name": "Alice","friends": ["bob","eva","jack"]},
+ {"location": {"lon": 52.5200,"lat": 13.4050},
+ "cities": [
+ {"lon": 51.5072,"lat": 0.1276},
+ {"lon": 40.7128,"lat": 74.0060}
+ ]
+ }
+ ]
+>>> def calculate_ratio(string, json_obj):
+ string_size = len(string.encode('utf-8'))
+ json_size = len(json.dumps(json_obj).encode('utf-8'))
+ ratio = string_size / json_size
+ print(f'JSON->YAML bytes ratio: {ratio}')
+>>> boxing = Singleton.boxing()
+>>> for each in singletons:
+ package = boxing.Payload(data=each, fmt="yml")
+ payload = package.deliver()
+ print(payload)
+ calculate_ratio(payload, each)
+age: 30
+city: New York
+name: John
+
+JSON->YAML bytes ratio: 0.723404255319149
+age: 30
+city: New York
+name: John
+
+JSON->YAML bytes ratio: 0.576271186440678
+- name
+- age
+- city
+
+JSON->YAML bytes ratio: 0.8695652173913043
+- age: 30
+ city: New York
+ name: John
+
+JSON->YAML bytes ratio: 0.8163265306122449
+>>> for each in milvus_payload_examples:
+ package = boxing.Payload(data=each, fmt="yml")
+ payload = package.deliver()
+ print(payload)
+ calculate_ratio(payload, each)
+count: 10
+sizes:
+- 35
+- 36
+- 38
+
+JSON->YAML bytes ratio: 0.8888888888888888
+price: 11.99
+ratings:
+- 9.1
+- 9.2
+- 9.4
+
+JSON->YAML bytes ratio: 0.9090909090909091
+is_delivered: true
+responses:
+- false
+- false
+- true
+- false
+
+JSON->YAML bytes ratio: 0.953125
+friends:
+- bob
+- eva
+- jack
+name: Alice
+
+JSON->YAML bytes ratio: 0.7692307692307693
+cities:
+- lat: 0.1276
+ lon: 51.5072
+- lat: 74.006
+ lon: 40.7128
+location:
+ lat: 13.405
+ lon: 52.52
+
+JSON->YAML bytes ratio: 0.8512396694214877
+