A small package for processing and analyzing data in batches.
Project description
Yet Another PRocessing and Analyzing Kit
This is a small package for simplifying batch data processing and analysis.
This project is licensed under the terms of the MIT license.
Installation
pip install yaprak
Documentation
Use Case
Yaprak can be used for running the same set of functions on a set of input files. For instance, when processing a dataset with multiple files each with time-series data, typically all the data should be preprocessed with the same set of filters before any other operation can be carried out. Similarly, the filtered data needs to be processed for a given application in a similar manner.
Use Example
To use yaprak, in addition to the input files, at least two more files are needed:
- A Python file with a class derived from Yaprak.
- A JSON file for configuring a run (file paths, methods to be called (processes), and parameters to pass to these methods (referred to as
process_specin the Python code, and any other user variables relevant to the use case)
Class inheriting Yaprak
First, define a class derived from Yaprak (myClass in the example below). 4 methods must be defined in this class:
__init__(self, config): The initialization method has one parameterconfig, which is the name of the JSON configuration file. This method should also call the initialization method for Yaprak.load(self, file): This method describes how to load one input file (file). This is specific to the use case. For instance, in the example below, there is only one integer value in each file, so theload()method implements the loading of the file and extracts the integer value from it. In another case, the input files can be.csvfiles or binary files, and the load function should implement the relevant load operation.save(self, file): Similar to load this method describes how to save the processed data to an output file, and it is specific to the application.report(self): If there is any information to be reported pertinent to the current file, thereportfunction can be used for this purpose.
Any other method that is needed to process the data, should also be described in this class (or derived from another class, here). These methods should include only one parameter other than self, which is process_spec.
For instance, the add(self, process_spec) method below adds two numbers. One is from the process_spec (which is read from the parameter list for this method from the configuration file (process_spec['a1'])), and the other one is read from the input file (self.file_input).
To use the class, only two steps are needed:
yap = myClass('myconfig.json'): Define an instance (yap) of the derived class (myClass) passing the configuration file name (myconfig.json) as the parameter.yap.run(): Run the batch, which will sequentially read each file, execute all the processes described in the configuration file on each input file, report any information regarding the currently processed file, and save the output to an output file.
from yaprak.yaprak import Yaprak
class myClass(Yaprak):
def __init__(self, config):
Yaprak.__init__(self, config)
self.total = 0
self.product = 0
self.file_input = None
def load(self, file):
with open(file, 'r') as f:
self.file_input = int(f.readline())
print(self.file_input)
def save(self, file):
with open(file, 'w') as f:
f.write("Sum is " + str(self.total) +"\n")
f.write("Product is " + str(self.product))
def report(self):
print('Finished processing')
def add(self, process_spec):
self.total = process_spec['a1'] + int(str(self.file_input))
def mul(self, process_spec):
self.product = process_spec['m1'] * self.config['m_global']
yap = myClass('myconfig.json')
yap.run()
JSON Configuration File
The configuration file below (myconfig.json) is a standard JSON file and consists of the following sections:
processes: This list has one entry for each process (i.e., method in the derived class) to be executed for all inputs. The processes in this list are executed in the given order. For each process, the key process should have the value of the name of the method (e.g. add, mul). The key apply is a Boolean and should be set to true for processes to be executed and false for processes to be skipped. Any other parameter (currently only numbers, and strings) to the method can also be passed as key-value pairs for each process. For instance, for the add process below, an integer parameter a1 is given.
This approach of configuring processes has two features, which can be achieved without any changes to the Python code:
- The order of the processes can be changed.
- The parameter values of the processes can be changed.
- The processes can be applied selectively.
In addition to the processes list, the following items must also exist in the JSON file:
- A list of
IDs, representing each file with an ID string (This could be the prefix of the file name for instance). - A list of all the input files in the list
inFileList, and - A list of all the output files in the list
outFileList.
The inFileList and outFileList may define absolute paths. Alternatively, paths for input files (inPath ) and output files (outPath) can be defined and the file names in the file lists can be relative.
Any other parameter useful to the application can be configured in this file as key-value pairs and can be accessed within the derived class from the config dictionary.
{
"processes": [
{
"process": "add",
"a1": 10,
"apply": true
},
{
"process": "mul",
"m1": 20,
"apply": true
}
],
"m_global": 100,
"inPath": "./inputs/",
"outPath": "./outputs/",
"IDs": [
"1",
"2",
"3"
],
"inFileList": [
"1.dat",
"2.dat",
"3.dat"
],
"outFileList": [
"1.txt",
"2.txt",
"3.txt"
]
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yaprak_delete-0.1.2.tar.gz.
File metadata
- Download URL: yaprak_delete-0.1.2.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee0c1cf6d36aa2502ca8fe492805583b36c9e88b3953929c698a2b0f67d4d5e2
|
|
| MD5 |
3aa56a3b85249a45a88279188fe57aad
|
|
| BLAKE2b-256 |
cc94119ce9171a037ed16c931725234a918903e758c56bc1fbddd10eb3d8b699
|
File details
Details for the file yaprak_delete-0.1.2-py3-none-any.whl.
File metadata
- Download URL: yaprak_delete-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de02e0386a5b3443e0faa40ec02da3d7761dc85f97cd6ca9eb20e7a40dfee90b
|
|
| MD5 |
f2f129786415d8d47e417168364d1e2f
|
|
| BLAKE2b-256 |
477f2fbc72c76e0d3f581c40b7af920c623251aa576b7d33ddd453885661c77c
|