Skip to content

Commit

Permalink
preparing for v 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ducarme committed Feb 12, 2025
1 parent ed9dd57 commit 5e1d2ae
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 25 deletions.
Empty file added src/springable/data/__init__.py
Empty file.
Empty file.
Empty file.
44 changes: 21 additions & 23 deletions src/springable/discover.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
from .simulation import simulate_model
from .readwrite import fileio
from .data import examples_csv_models, gallery_csv_models
import os
import importlib.resources




def show_examples(filename=None):
save_dir = fileio.mkdir('examples_results')
folder = 'examples-spring-model-CSV-files'
filenames = os.listdir(folder)
example_data = importlib.resources.files(examples_csv_models)
filepaths = [file for file in example_data.iterdir() if file.suffix == '.csv']
filenames = [os.path.basename(filepath) for filepath in filepaths]

if filename is not None:
if filename in filenames:
Expand All @@ -17,49 +22,42 @@ def show_examples(filename=None):
print(filenames)
return

for i, model_filename in enumerate(filenames):
model_path = os.path.join(folder, model_filename)
simulate_model(model_path, os.path.join(save_dir, model_filename.split('.')[0]),print_model_file=True)

if i != len(filenames) - 1:
print()
for model_filename, model_path in zip(filenames, filepaths):
simulate_model(model_path, os.path.join(save_dir, model_filename.split('.')[0]), print_model_file=True)
print()

if len(filenames) > 1:
print()
print("You have seen all the basic examples.")
print()

print()
print("To run your own simulation, create your own CSV file and run:")
print("\timport springable.simulation as ss")
print("\tss.simulate_model('my_spring_model.csv')")


def show_gallery(filename):
def show_gallery(filename=None):
save_dir = fileio.mkdir('gallery_results')
folder = 'gallery-spring-model-CSV-files'
filenames = os.listdir(folder)
example_data = importlib.resources.files(gallery_csv_models)
filepaths = [file for file in example_data.iterdir() if file.suffix == '.csv']
filenames = [os.path.basename(filepath) for filepath in filepaths]

if filename is not None:
if filename in filenames:
filenames = [filename]
else:
print(f'The example "{filename}" is unknown.')
print('Please choose one among the available examples:')
print('Please choose one among the available gallery items:')
print(filenames)
return

for i, model_filename in enumerate(filenames):
model_path = os.path.join(folder, model_filename)
simulate_model(model_path, os.path.join(save_dir, model_filename.split('.')[0]),print_model_file=True)

if i != len(filenames) - 1:
print()
for model_filename, model_path in zip(filenames, filepaths):
simulate_model(model_path, os.path.join(save_dir, model_filename.split('.')[0]), print_model_file=True)
print()

if len(filenames) > 1:
print()
print("You have visited the entire gallery.")
print()

print()
print("Inspired? Create your own CSV file and run:")
print("\timport springable.simulation as ss")
print("\tss.simulate_model('my_spring_model.csv')")
print("\tss.simulate_model('my_spring_model.csv')")
4 changes: 2 additions & 2 deletions src/springable/utils/dataclass_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def update(self, **kwargs):
if (expected_type is float and type(value) is int) or isinstance(value, expected_type):
setattr(self, key, value)
else:
print(f'Value of {_camel_to_text(type(self).__name__).rstrip('s')}'
print(f'Value of {_camel_to_text(type(self).__name__).rstrip("s")}'
f' "{key}" is ignored.'
f' It should be a {expected_type.__name__}, not a {type(value).__name__} ({value})')
else:
print(f'Unknown {_camel_to_text(type(self).__name__).rstrip('s')} "{key}". Probably check spelling...')
print(f'Unknown {_camel_to_text(type(self).__name__).rstrip("s")} "{key}". Probably check spelling...')

0 comments on commit 5e1d2ae

Please sign in to comment.