Skip to content

Commit

Permalink
ran black on code
Browse files Browse the repository at this point in the history
  • Loading branch information
cpmpercussion committed Jun 26, 2024
1 parent 4f2cefe commit 88c0fcd
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 51 deletions.
6 changes: 4 additions & 2 deletions impsy/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def transform_log_to_sequence_example(logfile: str, dimension: int):
return np.array(perf_df[["t"] + data_names])


def generate_dataset(dimension: int, source: str = "logs", destination: str = "datasets"):
def generate_dataset(
dimension: int, source: str = "logs", destination: str = "datasets"
):
"""Generate a dataset from .log files in the log directory."""
# Load up the performances
log_location = f"{source}/"
Expand Down Expand Up @@ -61,7 +63,7 @@ def generate_dataset(dimension: int, source: str = "logs", destination: str = "d
raw_perfs.append(raw)

if acc == 0:
click.secho("Zero values to add to dataset! aborting.", fg='red')
click.secho("Zero values to add to dataset! aborting.", fg="red")
return

click.secho(f"total number of values: {acc}", fg="blue")
Expand Down
13 changes: 7 additions & 6 deletions impsy/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@


def test_main_command():
runner = CliRunner()
result = runner.invoke(cli)
assert result.exit_code == 0
runner = CliRunner()
result = runner.invoke(cli)
assert result.exit_code == 0


def test_model_test_command():
runner = CliRunner()
result = runner.invoke(cli, ['test-mdrnn'])
# assert result.exit_code == 0
runner = CliRunner()
result = runner.invoke(cli, ["test-mdrnn"])
# assert result.exit_code == 0
70 changes: 37 additions & 33 deletions impsy/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,49 @@
import random


def create_test_log_files(location = "tests/logs", dimension = 4, number = 10, events = 50):
"""Creates some test log files for dataset testing."""
assert dimension > 1, "minimum dimension is 2"
os.makedirs(location, exist_ok=True)
log_files = []
for i in range(number):
test_log_file = f"{location}/2024-06-{i:02d}T12-00-00-4d-mdrnn.log"
with open(test_log_file, "w") as file:
for j in range(events):
nums = [random.random() for _ in range(dimension-1)]
num_string = ",".join(map(str, nums))
test_line = f"2024-06-01T12:00:{j:02d},interface,{num_string}\n"
file.write(test_line)
log_files.append(test_log_file)
return log_files
def create_test_log_files(location="tests/logs", dimension=4, number=10, events=50):
"""Creates some test log files for dataset testing."""
assert dimension > 1, "minimum dimension is 2"
os.makedirs(location, exist_ok=True)
log_files = []
for i in range(number):
test_log_file = f"{location}/2024-06-{i:02d}T12-00-00-4d-mdrnn.log"
with open(test_log_file, "w") as file:
for j in range(events):
nums = [random.random() for _ in range(dimension - 1)]
num_string = ",".join(map(str, nums))
test_line = f"2024-06-01T12:00:{j:02d},interface,{num_string}\n"
file.write(test_line)
log_files.append(test_log_file)
return log_files


def remove_test_log_files(log_files):
"""Deletes test log files"""
for f in log_files:
os.remove(f)
"""Deletes test log files"""
for f in log_files:
os.remove(f)


def test_log_to_examples():
"""Tests transform_log_to_sequence_example with a single example"""
dimension = 8
log_files = create_test_log_files(number = 1, dimension = dimension)
log = dataset.transform_log_to_sequence_example(log_files[0], dimension)
remove_test_log_files(log_files)
assert(isinstance(log, np.ndarray))
assert(len(log[0]) == dimension)
"""Tests transform_log_to_sequence_example with a single example"""
dimension = 8
log_files = create_test_log_files(number=1, dimension=dimension)
log = dataset.transform_log_to_sequence_example(log_files[0], dimension)
remove_test_log_files(log_files)
assert isinstance(log, np.ndarray)
assert len(log[0]) == dimension


def test_dataset_command():
"""Test the dataset command runs"""
test_log_area = "tests/logs"
test_dataset_area = "tests/datasets"
os.makedirs(test_dataset_area, exist_ok=True)
dimension = 4
log_files = create_test_log_files(location = test_log_area, dimension = dimension, number = 10)
dataset.generate_dataset(dimension=dimension, source="tests/logs", destination=test_dataset_area)
remove_test_log_files(log_files)
"""Test the dataset command runs"""
test_log_area = "tests/logs"
test_dataset_area = "tests/datasets"
os.makedirs(test_dataset_area, exist_ok=True)
dimension = 4
log_files = create_test_log_files(
location=test_log_area, dimension=dimension, number=10
)
dataset.generate_dataset(
dimension=dimension, source="tests/logs", destination=test_dataset_area
)
remove_test_log_files(log_files)
11 changes: 6 additions & 5 deletions impsy/tests/test_interaction.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from impsy import interaction


def test_interaction_server():
"""Just tests creation of an interaction server object"""
interaction_server = interaction.InteractionServer()
"""Just tests creation of an interaction server object"""
interaction_server = interaction.InteractionServer()

def test_logging():
"""Just sets up logging"""
interaction.setup_logging(2)

def test_logging():
"""Just sets up logging"""
interaction.setup_logging(2)
9 changes: 6 additions & 3 deletions impsy/tflite_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ def convert_tflite():
# setup converter
click.secho("Setup converter.")
converter = tf.lite.TFLiteConverter.from_keras_model(net.model)
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
converter.target_spec.supported_ops = [
tf.lite.OpsSet.TFLITE_BUILTINS,
tf.lite.OpsSet.SELECT_TF_OPS,
]
converter._experimental_lower_tensor_list_ops = False

click.secho("Do the conversion.")
tflite_model = converter.convert()

click.secho("Saving..")
tflite_model_name = f'{config["model"]["file"]}-lite.tflite'
with open(tflite_model_name, 'wb') as f:
f.write(tflite_model)
with open(tflite_model_name, "wb") as f:
f.write(tflite_model)
6 changes: 4 additions & 2 deletions impsy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import random


# MDRNN config
# MDRNN config


SIZE_TO_PARAMETERS = {
Expand Down Expand Up @@ -45,7 +45,9 @@ def generate_data(samples: int = 50000, dimension: int = 2):
print("Generating", str(NSAMPLE), "toy data samples.")
t_data = np.float32(np.array(range(NSAMPLE)) / 10.0)
t_interval = t_data[1] - t_data[0]
t_r_data = np.random.normal(0, t_interval / 20.0, size=NSAMPLE) ## fuzz up the time sampling
t_r_data = np.random.normal(
0, t_interval / 20.0, size=NSAMPLE
) ## fuzz up the time sampling
t_data = t_data + t_r_data
r_data = np.random.normal(size=NSAMPLE)
# x_data = np.sin(t_data) * 1.0 + (r_data * 0.05)
Expand Down

0 comments on commit 88c0fcd

Please sign in to comment.