datagen package#

Submodules#

datagen.assembly module#

class datagen.assembly.UnitAssemblyTime(dct)#

Bases: object

Represents the assembly time necessary for making a unit of a specific product

classmethod get_unit_assembly_time(min, step, max)#

builds a unit assembly time based on the parameters provided in BOM :param min: :param step: :param max: :return:

datagen.bomcache module#

class datagen.bomcache.BomCache#

Bases: object

Class representing a cache holding the current BOM, to be used from other modules

classmethod add_bom(bom)#
bom = None#
classmethod get_bom()#

datagen.boms_processing module#

This class deals with the configuration file used to generate the BOMs in the system.

Basically it deserializes the datagen.json file and make all the params available for the data generator

@author adrian

class datagen.boms_processing.Bom(name: str, max_depth: int, max_children: int, randomize_children: bool, seed: int, machines_number: int, max_alternatives_machines_number: int, randomize_alternative_machines: bool, output_file: str, start_date: str, delivery_date: str, max_quantity: int, allow_identical_machines, percent_of_identical_machines: float, maintenance_duration: datagen.maintenance.MaintenanceDuration, maintenance_probability: float, unit_assembly_time: datagen.assembly.UnitAssemblyTime, setup_time: datagen.setup.SetupTime)#

Bases: object

Models the parameters needed for a single BOM. NOTE: In this version is important to keep the order of the parameters defined in datagen.json with the

list of parameters in the Bom constructor

class datagen.boms_processing.BomDecoder(*, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None)#

Bases: json.decoder.JSONDecoder

classmethod build() list[datagen.boms_processing.Bom]#
classmethod decode(todecode) list#

Return the Python representation of s (a str instance containing a JSON document).

static handle_error(key) Exception#
class datagen.boms_processing.Boms(*args, **kwargs)#

Bases: object

Singleton that holds all the BOMs defined in our data generator

classmethod add_bom(bom: datagen.boms_processing.Bom) None#
boms = []#
classmethod get_all()#
classmethod get_bom(name: str) datagen.boms_processing.Bom#
instance = None#
classmethod remove_bom(bom: datagen.boms_processing.Bom) None#
class datagen.boms_processing.MachinesSetup(time_units='seconds')#

Bases: object

Represents the general parameters for the machines used to process a specific product

datagen.generate_dataset module#

datagen.generate_dataset.generate_boms()#
datagen.generate_dataset.generate_dataset_config()#

datagen.generate_examples module#

datagen.generate_examples.main()#

datagen.gentree module#

datagen.gentree.create_children(node: anytree.node.node.Node, num_children: int, depth: int, products: list, seed: int, bom: datagen.boms_processing.Bom, random_children: bool = False) None#

This function will create a generic tree using recursion. The process looks to work slow for large depths, should be replaced with a faster alternative, for for now is usable

Parameters
  • node – the node to which the children are created and attached

  • num_children – the number of children to be created for the specified node

  • depth – the depth of the tree (the number of levels below the specified node)

  • seed – the seed used to initialize the random generator.

  • random_children – in the case one need to create a random number of children for the specified node. The number of children will vary between 1 and num_children

Returns

datagen.gentree.edgeattrfunc(node: anytree.node.node.Node, child: anytree.node.node.Node)#
datagen.gentree.edgetypefunc(node: anytree.node.node.Node, child: anytree.node.node.Node)#
datagen.gentree.export_dot(node, file_path) None#

Exports a node in .dot format to be :param node: :param file_path: :return:

datagen.gentree.export_tree(n: anytree.node.node.Node, file_path: str, onscreen: bool = True) None#

Exports a node in JSON format :param n: the node to be exported :param file_path: the path of the exported json file :param onscreen: if the exported json will be displayed on stdout too :return: None

datagen.gentree.import_tree(file_path: str) anytree.node.node.Node#

Deserialize a tree from its associated JSON file :param file_path: the path to the file containing the onject serialization :return: the Python tree object

datagen.gentree.nodenamefunc(node: anytree.node.node.Node)#
datagen.gentree.render_tree(node: anytree.node.node.Node) None#
datagen.gentree.walk(node, callback) None#

Walks through the tree and apply a callback function :param node: the root (or upper) node in the tree from where the walking process begins :param callback: the function called for every walked node :return:

datagen.importer module#

class datagen.importer.SMachine(id, name, execution_time, setup_time)#

Bases: object

class datagen.importer.SProduct(productid, code, pname, machines=None)#

Bases: object

class datagen.importer.SProductDecoder(*, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None)#

Bases: json.decoder.JSONDecoder

decode()#

Return the Python representation of s (a str instance containing a JSON document).

datagen.main module#

This is the entry point of data generator

datagen.main.main()#
datagen.main.print_name(node) None#

callback function used to traverse the tree and perform a n action :param node: the root (or upper) tree node :return:

datagen.main_all module#

This is the entry point of data generator

datagen.main_all.bom_process(bom)#
datagen.main_all.print_name(node) None#

callback function used to traverse the tree and perform a n action :param node: the root (or upper) tree node :return:

datagen.maintenance module#

class datagen.maintenance.Maintenance(machine)#

Bases: object

MAX_MAINTENANCE_TIME_HOURS = 72#
MAX_START_DAYS = 30#
classmethod build_maintenance_dates()#
date_format_str = '%d/%m/%Y %H:%M:%S'#
static to_hours(time_units, val) int#
to_json()#
class datagen.maintenance.MaintenanceDuration(dct)#

Bases: object

exception datagen.maintenance.NoStartTimeException#

Bases: Exception

datagen.maintenances module#

class datagen.maintenances.Maintenances#

Bases: object

Holds the Maintenance objects generated during the product creation phase

classmethod add(maintenance) None#

add a Maintenance object to the list of maintenances :param maintenance: :return:

classmethod get_maintenances() list#
maintenances_list = {}#
classmethod reset() None#

empties the list of maintenances :return: None

classmethod to_json()#
class datagen.maintenances.MaintenancesEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)#

Bases: json.encoder.JSONEncoder

classmethod encode(o)#

Return a JSON string representation of a Python data structure.

>>> from json.encoder import JSONEncoder
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'

datagen.meta module#

class datagen.meta.Meta(operations_list, machines_list, maintenances)#

Bases: object

class datagen.meta.MetaEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)#

Bases: json.encoder.JSONEncoder

default(o: Any) str#

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)

datagen.metainfo module#

class datagen.metainfo.MetaInfo(*args, **kwargs)#

Bases: object

Singleton that holds info about the products and machines involved in the BOM

add_machine(machineid)#
add_metainfo(product, opid)#
add_operation(opid)#
add_product(prodid)#
get_machines()#
get_operations()#
get_products()#
instance = None#
reset_machines()#
reset_operations()#

datagen.msequencer module#

class datagen.msequencer.MachineSequencer(*args, **kwargs)#

Bases: object

Singleton class to generate unique ids for the machines in data generator

index = 0#
reset() None#

Resets the sequencer :return:

datagen.operations module#

class datagen.operations.Operations(*args, **kwargs)#

Bases: object

instance = None#

datagen.order module#

class datagen.order.Order(id, product_id, product_name, quantity, delivery_date)#

Bases: object

export(output_file: str) None#
class datagen.order.OrderEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)#

Bases: json.encoder.JSONEncoder

encode(o: Any) str#

Return a JSON string representation of a Python data structure.

>>> from json.encoder import JSONEncoder
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'

datagen.productgenerator module#

class datagen.productgenerator.Machine(id, name)#

Bases: object

class modelling a Machine in the production system. Every machine has an id and a name

class MachineEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)#

Bases: json.encoder.JSONEncoder

encode(obj)#

Return a JSON string representation of a Python data structure.

>>> from json.encoder import JSONEncoder
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
class datagen.productgenerator.Machines(bom)#

Bases: object

class containing all the machines in our system

class MachinesEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)#

Bases: json.encoder.JSONEncoder

encode(obj) str#

Return a JSON string representation of a Python data structure.

>>> from json.encoder import JSONEncoder
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
assign_machines()#
build() [<class 'datagen.productgenerator.Machine'>]#

Builds a list of machines specific to a BOM. For example, the maximum number of alternate machines for a specific product is taken from the passed BOM

Parameters

bom

Returns

export() None#

serializes the Machine instances in a JSON file on disk :return: None

classmethod import_machines()#
class datagen.productgenerator.Product(productid, code, name, machines_list=None)#

Bases: object

class datagen.productgenerator.ProductEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)#

Bases: json.encoder.JSONEncoder

default(o)#

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
class datagen.productgenerator.ProductGenerator(bom)#

Bases: object

build()#
code(length)#
static generate_maintenance(bom) bool#

decides if the Maintenance object is generated for a machine :return:

part()#
productid()#
quantity()#
class datagen.productgenerator.Products(bom)#

Bases: object

add_setup_time() None#

this method will decorate the list of machines with a randomly chosen setup time :return:

add_time_units() None#

this method will decorate the machines list with a time specific to create a unit of product :return:

build()#
export() None#

Exports all the products in a json file for further usage :return: None

generate_products()#
to_seconds(time_units, val) int#

Transforms a certain duration in seconds, based on the units in which duration is expressed :param time_units: :param val: :return:

datagen.productgenerator.generate(bom)#

datagen.scampdate module#

class datagen.scampdate.date#

Bases: datetime.date

datagen.scampdate.datemask()#

global date format :return:

class datagen.scampdate.datetime#

Bases: datetime.datetime

date()#

Return date object with same year, month and day.

datagen.sequencer module#

class datagen.sequencer.Sequencer(*args, **kwargs)#

Bases: object

Singleton class to generate unique ids for the data generator

index = 0#
reset() None#

Resets the sequencer :return:

datagen.setup module#

class datagen.setup.SetupTime(dct)#

Bases: object

classmethod get_setup_time(min, step, max)#

Module contents#