Created
March 24, 2019 20:27
-
-
Save filipecosta90/09770e866a6c6d5ba9a0e63b6dbbf124 to your computer and use it in GitHub Desktop.
Snippet with the most relevant part of the complete file, specifically the usage of the Redis command TS.RANGE.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# snippet from https://github.com/redis-porto/redistimeseries-airquality/blob/master/plot.py | |
#(...) | |
#(...) | |
# redis setup | |
redis_obj = redis.Redis(host=args.host, port=args.port, password=args.password) | |
temperature_key = "ts:temperature" | |
temperature_description = "Temperature in °C variation" | |
temperature_y_label = "°C" | |
carbon_monoxide_key = "ts:carbon_monoxide" | |
carbon_monoxide_description = ( | |
"True averaged concentration CO in mg/m^3 (reference analyzer)" | |
) | |
carbon_monoxide_y_label = "mg/m^3" | |
relative_humidity_key = "ts:relative_humidity" | |
relative_humidity_description = "Relative Humidity (%) variation" | |
relative_humidity_y_label = "Relative Humidity (%)" | |
if args.dataset_serie == "temperature": | |
y_label = temperature_y_label | |
title = temperature_description | |
if args.dataset_serie == "carbon_monoxide": | |
y_label = carbon_monoxide_y_label | |
title = carbon_monoxide_description | |
if args.dataset_serie == "relative_humidity": | |
y_label = relative_humidity_y_label | |
title = relative_humidity_description | |
used_key = "ts:{0}".format(args.dataset_serie) | |
if args.agg_type == "none" or args.agg_type == "None": | |
baseline_values = redis_obj.execute_command( | |
"TS.RANGE", used_key, baseline_date_unix_ts, baseline_end_date_unix_ts | |
) | |
if comparison_date_unix_ts is not None: | |
comparison_values = redis_obj.execute_command( | |
"TS.RANGE", used_key, comparison_date_unix_ts, comparison_end_date_unix_ts | |
) | |
else: | |
agg_string = "" | |
if args.agg_type == "avg": | |
agg_string = "average" | |
elif args.agg_type == "max": | |
agg_string = "maximum" | |
elif args.agg_type == "min": | |
agg_string = "minimum" | |
elif args.agg_type == "range": | |
agg_string = "range" | |
title = "{0} - aggregated by function {1} with buckets of {2} seconds".format( | |
title, agg_string, args.bucket_size_seconds | |
) | |
baseline_values = redis_obj.execute_command( | |
"TS.RANGE", | |
used_key, | |
baseline_date_unix_ts, | |
baseline_end_date_unix_ts, | |
"AGGREGATION", | |
args.agg_type, | |
args.bucket_size_seconds, | |
) | |
if comparison_date_unix_ts is not None: | |
comparison_values = redis_obj.execute_command( | |
"TS.RANGE", | |
used_key, | |
comparison_date_unix_ts, | |
comparison_end_date_unix_ts, | |
"AGGREGATION", | |
args.agg_type, | |
args.bucket_size_seconds, | |
) | |
#(...) | |
#(...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment