def get(self, request, log_folder, time_point): log_folder = log_folder.replace("$", "/") data = common.retrieve_data_at_time( os.path.join(os.getcwd(), "logger", log_folder), float(time_point)) sanatized_data = {} for path, value in data.items(): if len(path) > 1: path = "." + path specials = get_special_paths(path, value, {}, RedisInterface().label_to_shipper) if type(value) == dict: new_val = copy_dictionary_without_paths( value, [path_to_key_sequence(p) for p, ship_id in specials]) for path, ship_id in specials: insert_into_dictionary( new_val, path, "###Numpy_{}${}${}".format(path, time_point, ship_id)) elif type(value).__module__ == np.__name__: new_val = "###Numpy_{}_{}".format(path, time_point) else: new_val = value sanatized_data[path] = new_val json_serialized = json.dumps(sanatized_data) return HttpResponse(json_serialized)
def overhead_testing_subscriber(test_name, timeout=10): times = [] interface = RedisInterface() subscriber = CallbackSubscriber("overhead_test", interface, append_time_to_list, {"times": times}) subscriber.listen() time.sleep(timeout) base = os.path.dirname(os.path.abspath(__file__)) save_dir = os.path.join(base, "logs", "overhead_test", test_name) save_path = os.path.join(save_dir, "subscriber_{}.txt".format(os.getpid())) if not os.path.exists(save_dir): os.makedirs(save_dir) with open(save_path, "w") as f: for t in times: f.write("{}\n".format(t))
from reem.datatypes import KeyValueStore, CallbackSubscriber from reem.connection import RedisInterface import time import logging # Logging Configuration logging.basicConfig( format= "%(asctime)20s %(filename)30s:%(lineno)3s %(funcName)20s() %(levelname)10s %(message)s", filename="controller_kvs.log", filemode='w') logger = logging.getLogger("script") logger.setLevel(logging.INFO) TIME_TO_RUN = 5.0 # seconds start_time = time.time() # --------------------------- Main ----------------------------------- interface = RedisInterface(host="localhost") kvs = KeyValueStore(interface=interface) set_frequency = 100 # Hz set_period = 1.0 / set_frequency while time.time() < start_time + TIME_TO_RUN: next_iteration = time.time() + set_period command = time.time() kvs["set_point"] = command logger.info("Wrote Set Point: {}".format(command)) time.sleep(max(0.0, next_iteration - time.time()))
from reem.datatypes import KeyValueStore import sys import csv import time import os from threading import Thread import logging FORMAT = "%(threadName)10s %(asctime)20s %(filename)30s:%(lineno)3s %(funcName)20s() %(levelname)10s %(message)s" logging.basicConfig(format=FORMAT) logger = logging.getLogger("reem.datatypes") logger.setLevel(logging.DEBUG) func, keyfile, outfolder = "log", "test_key_files/key1.txt", "test_data_log/test1" kvs = KeyValueStore(RedisInterface()) def path_to_keys(path): if "." in path: return path.split(".") return [path] def log_path(path, period, key_folder): key_sequence = path_to_keys(path) next_read = time.time() + period while True: logger.debug("Path : {}".format(path)) current = time.time() if current >= next_read:
def overhead_testing_publisher(): interface = RedisInterface() publisher = PublishSpace(interface) for i in range(TRIALS): publisher["overhead_test"] = {"timestamp": time.time()} time.sleep(PULSE_GAP)
import logging import time import os import shutil from redis import Redis from pottery import RedisDict base = os.path.dirname(os.path.abspath(__file__)) log_file_name = os.path.join(base, "logs/reem_testing_kvs_timed.log") FORMAT = "%(asctime)20s %(filename)30s:%(lineno)3s %(funcName)20s() %(levelname)10s %(message)s" logging.basicConfig(format=FORMAT, filename=log_file_name, filemode='w') logger = logging.getLogger("reem.datatypes") logger.setLevel(logging.DEBUG) interface = RedisInterface() kvs = KeyValueStore(interface) publisher = PublishSpace(interface) def set(keys, value): setter = kvs for k in keys[:-1]: setter = setter[k] setter[keys[-1]] = value def get(keys): setter = kvs for k in keys[:-1]: setter = setter[k]
from __future__ import print_function from reem.connection import RedisInterface from reem.datatypes import KeyValueStore import numpy as np interface = RedisInterface(host="localhost") interface.initialize() server = KeyValueStore(interface) # Set a key and read it and its subkeys server["foo"] = {"number": 100.0, "string": "REEM"} print("Reading Root : {}".format(server["foo"].read())) print("Reading Subkey: {}".format(server["foo"]["number"].read())) # Set a new key that didn't exist before to a numpy array server["foo"]["numpy"] = np.random.rand(3,4) print("Reading Root : {}".format(server["foo"].read())) print("Reading Subkey: {}".format(server["foo"]["numpy"].read()))
from reem.connection import RedisInterface from reem.datatypes import KeyValueStore intf = RedisInterface(host="192.168.0.110") kvs = KeyValueStore(intf) kvs["testdata"] = "9" print(kvs["testdata"].read())
from reem.connection import RedisInterface from reem.datatypes import KeyValueStore from scipy.misc import imread import os intf = RedisInterface() intf.initialize() kvs = KeyValueStore(intf) image_fname = os.path.join(os.path.dirname(os.path.abspath(__file__)), "redis_image.png") kvs["image_dict"] = {"image": imread(image_fname)}
# Logging Configuration log_file_name = "logs/reem_testing_kvs_timed.log" FORMAT = "%(asctime)20s %(filename)30s:%(lineno)3s %(funcName)20s() %(levelname)10s %(message)s" logging.basicConfig(format=FORMAT, filename=log_file_name, filemode='w') logger = logging.getLogger("reem.datatypes") logger.setLevel(logging.DEBUG) image_array = np.random.rand(640, 480, 3) flat_data = get_flat_data() nested_data = get_nested_data() image_dict = {"image": image_array} hundred_key_dict = single_level_dictionary() layered_dictionary = nested_level_dictionary(levels=20) interface = RedisInterface(host="localhost", ships=[ships.NumpyShip()]) interface.initialize() server = KeyValueStore(interface) def test_write_hundred_key_dict(): for i in range(100): server["hundred_key_dict"] = hundred_key_dict logger.debug("\n") def test_write_multilevel_dict(): for i in range(100): server["layered_dict"] = layered_dictionary logger.debug("\n")
from django.shortcuts import render, reverse from django.views import View from django.conf import settings from reem.connection import RedisInterface from reem.datatypes import KeyValueStore import numpy as np from PIL import Image import io import base64 # Create your views here. interface = RedisInterface(settings.REEM_HOSTNAME) interface.initialize() kvs = KeyValueStore(interface) def get_content(path): try: keys = [path] if "." in path: keys = path.split(".") pfinder = kvs for k in keys: pfinder = pfinder[k] val = pfinder.read() except Exception: val = "Could not find entry matching {}".format(path) return val
# Logging Configuration log_file_name = "logs/reem_testing_kvs_timed.log" FORMAT = "%(asctime)20s %(filename)30s:%(lineno)3s %(funcName)20s() %(levelname)10s %(message)s" logging.basicConfig(format=FORMAT, filename=log_file_name, filemode='w') logger = logging.getLogger("reem.datatypes") logger.setLevel(logging.DEBUG) image_array = np.random.rand(640, 480, 3) flat_data = get_flat_data() nested_data = get_nested_data() image_dict = {"image": image_array} hundred_key_dict = single_level_dictionary() layered_dictionary = nested_level_dictionary(levels=20) interface = RedisInterface(host="localhost", marshallers=[marshalling.NumpyMarshaller()]) interface.initialize() server = KeyValueStore(interface) def test_write_hundred_key_dict(): for i in range(100): server["hundred_key_dict"] = hundred_key_dict logger.debug("\n") def test_write_multilevel_dict(): for i in range(100): server["layered_dict"] = layered_dictionary logger.debug("\n")