From 390760598266ecb7e32e96e125bd1dcbb01a6c1d Mon Sep 17 00:00:00 2001 From: Alan Gibson Date: Wed, 13 Nov 2024 17:01:25 -0500 Subject: [PATCH] Black run fixes --- onair/data_handling/redis_adapter.py | 1 - redis-experiment-publisher-multi-server.py | 73 ++++++++++++---------- 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/onair/data_handling/redis_adapter.py b/onair/data_handling/redis_adapter.py index 0057bbeb..c1295624 100644 --- a/onair/data_handling/redis_adapter.py +++ b/onair/data_handling/redis_adapter.py @@ -32,7 +32,6 @@ from onair.data_handling.parser_util import extract_meta_data_handle_ss_breakdown - class DataSource(OnAirDataSource): """Implements OnAirDataSource interface for receiving data from REDIS servers. diff --git a/redis-experiment-publisher-multi-server.py b/redis-experiment-publisher-multi-server.py index 7c20576d..cdb5509a 100644 --- a/redis-experiment-publisher-multi-server.py +++ b/redis-experiment-publisher-multi-server.py @@ -8,10 +8,9 @@ # When your Redis server requires a password, fill it in here redis_password = "" # Connect to Redis -r1 = redis.Redis(host=redis_host, - port=redis_port, - password=redis_password, - decode_responses=True) +r1 = redis.Redis( + host=redis_host, port=redis_port, password=redis_password, decode_responses=True +) # Initialize the Redis connection for server #1 redis_host = "localhost" @@ -19,14 +18,15 @@ # When your Redis server requires a password, fill it in here redis_password = "" # Connect to Redis -r2 = redis.Redis(host=redis_host, - port=redis_port, - password=redis_password, - decode_responses=True) - +r2 = redis.Redis( + host=redis_host, port=redis_port, password=redis_password, decode_responses=True +) + # List of channel names -server1_channels = ['state_0'] -server2_channels = ['state_1', 'state_2'] +server1_channels = ["state_0"] +server2_channels = ["state_1", "state_2"] + + # Publish messages on each channel in random order def publish_messages(): loop_count = 0 @@ -35,36 +35,45 @@ def publish_messages(): while loop_count < max_loops: random.shuffle(server1_channels) for channel in server1_channels: - r1.publish(channel, f'{{"time":{inner_loop_count}, ' \ - f'"x":{inner_loop_count+0.1}, ' \ - f'"y":{inner_loop_count+0.2}}}') - - print(f"Published data to {channel}, " \ - f"[{inner_loop_count}, " \ - f"{inner_loop_count+0.1}, " \ - f"{inner_loop_count+0.2}]") - + r1.publish( + channel, + f'{{"time":{inner_loop_count}, ' + f'"x":{inner_loop_count+0.1}, ' + f'"y":{inner_loop_count+0.2}}}', + ) + + print( + f"Published data to {channel}, " + f"[{inner_loop_count}, " + f"{inner_loop_count+0.1}, " + f"{inner_loop_count+0.2}]" + ) + inner_loop_count += 1 time.sleep(2) - + random.shuffle(server2_channels) - for channel in server2_channels: - r2.publish(channel, f'{{"time":{inner_loop_count}, ' \ - f'"x":{inner_loop_count+0.1}, ' \ - f'"y":{inner_loop_count+0.2}}}') - - print(f"Published data to {channel}, " \ - f"[{inner_loop_count}, " \ - f"{inner_loop_count+0.1}, " \ - f"{inner_loop_count+0.2}]") + for channel in server2_channels: + r2.publish( + channel, + f'{{"time":{inner_loop_count}, ' + f'"x":{inner_loop_count+0.1}, ' + f'"y":{inner_loop_count+0.2}}}', + ) + + print( + f"Published data to {channel}, " + f"[{inner_loop_count}, " + f"{inner_loop_count+0.1}, " + f"{inner_loop_count+0.2}]" + ) inner_loop_count += 1 time.sleep(2) - + loop_count += 1 print(f"Completed {loop_count} loops") - if __name__ == "__main__": publish_messages()