Git Product home page Git Product logo

be-helpers's Introduction

BE Helpers

Downloads Release Python License: MIT codecov

Custom brainelectronics python helper modules


General

Collection of custom brainelectronics specific python helper modules.

Installation

pip install be-helpers

Usage

from be_helpers import ModuleHelper
import time
from pathlib import Path

# default name is 'be_helpers.module_helper'
my_logger = ModuleHelper.create_logger()

# set logger level to INFO
ModuleHelper.set_logger_verbose_level(logger=my_logger, verbose_level=3)

# check 'a' to be an option of ['a', 'b', 'c'], result will be True
result = ModuleHelper.check_option_values(options=['a', 'b', 'c'], option='a')
print('"a" is an option of ["a", "b", "c"]: {}'.format(result))
# "a" is an option of ["a", "b", "c"]: True

# get current unix timestamp and format it
now = ModuleHelper.get_unix_timestamp()
time_format = "%H:%M:%S"
print('{}'.format(ModuleHelper.format_timestamp(timestamp=now, format=time_format)))
# 11:30:01

# create a random character number string of length 10
print('{}'.format(ModuleHelper.get_random_string(length=10)))
# 235LS5AY6BPC

# convert a string to a "uint16_t" list, useful for Modbus communications
result = ModuleHelper.convert_string_to_uint16t(content="test")
print('"test" as uint16_t: {}'.format(result))
# "test" as uint16_t: [29797, 29556]

# check for valid files or folders
here = ModuleHelper.get_full_path('.')
ModuleHelper.check_file(here / 'README.md', '.md')
# True

ModuleHelper.check_folder(here)
# True

# load YAML or JSON files as dictionaries
config = ModuleHelper.load_dict_from_file(here / 'tests/data/valid.json')
config = ModuleHelper.load_dict_from_file(here / 'tests/data/valid.yaml')
# {'key': 'val', 'key2': {'key_nested': 'val_nested'}, 'key3': ['asdf', 123, {'key4': 'val4'}]}

# save dictionaries as JSON or YAML files
ModuleHelper.save_dict_to_file(path=here / 'example/cfg.json', content=config)
ModuleHelper.save_dict_to_file(path=here / 'example/cfg.yaml', content=config)
# True

Contributing

Unittests

Run the unittests locally with the following command after installing this package in a virtual environment

# run all tests
nose2 --config tests/unittest.cfg

# run only one specific tests
nose2 tests.test_module_helper.TestModuleHelper.test_set_logger_verbose_level

Generate the coverage files with

python create_report_dirs.py
coverage html

The coverage report is placed at be-helpers/reports/coverage/html/index.html

Credits

Based on the PyPa sample project.

be-helpers's People

Contributors

brainelectronics avatar highonvoltage avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.