<commit_before>"""
This module is responsible for handling configuration and files related to it,
including calibration parameters.
"""

import configparser
import os


"""
Default options
"""
#TODO: more default options...
_CONFIG_DEFAULTS = {
      "paths": {
        # default database path is ../db/test.db relative to this file
        "db_path": os.path.join(
          os.path.dirname(os.path.dirname(__file__)),
          "db/test.db"),
      },

    }

"""
Initialize a configparser dictionary with given or default filename and
return it
"""
def get_config_dict(filename = None):

  if filename is None:
    cfg_path = os.path.dirname(__file__)
    filename = os.path.join(cfg_path, "config.ini")

  cp = configparser.ConfigParser() #_CONFIG_DEFAULTS)

  # read default values from dict
  cp.read_dict(_CONFIG_DEFAULTS)

  #TODO: use logging instead of print...
  print("Using configuration file " + filename)
  cp.read(filename)

  return cp

  #def __getitem__(self, i): self.configparser.<commit_msg>Add some calibration default values.<commit_after>"""
This module is responsible for handling configuration and files related to it,
including calibration parameters.
"""

import configparser
import os


"""
Default options
"""
#TODO: more default options...
_CONFIG_DEFAULTS = {
      "paths": {
        # default database path is ../db/test.db relative to this file
        "db_path": os.path.join(
          os.path.dirname(os.path.dirname(__file__)),
          "db/test.db"),
      },

      "calibration" : {
        "sensor_min_value" : 0,
        "sensor_max_value" : 1024,
      },

    }

"""
Initialize a configparser dictionary with given or default filename and
return it
"""
def get_config_dict(filename = None):

  if filename is None:
    cfg_path = os.path.dirname(__file__)
    filename = os.path.join(cfg_path, "config.ini")

  cp = configparser.ConfigParser() #_CONFIG_DEFAULTS)

  # read default values from dict
  cp.read_dict(_CONFIG_DEFAULTS)

  #TODO: use logging instead of print...
  print("Using configuration file " + filename)
  cp.read(filename)

  return cp

  #def __getitem__(self, i): self.configparser.
{'fraction_non_alphanumeric': 0.11209302325581395, 'fraction_numerical': 0.002325581395348837, 'mean_word_length': 3.31062124248497, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '66262', 'n_tokens_mistral': 652, 'n_tokens_neox': 632, 'n_words': 190}