Skip to content
Snippets Groups Projects
Commit 102cf9a8 authored by Alex Wiens's avatar Alex Wiens
Browse files

Prule: add quantity function for rules

parent 5a1ef9c9
No related branches found
No related tags found
No related merge requests found
...@@ -164,6 +164,26 @@ Parameters: ...@@ -164,6 +164,26 @@ Parameters:
Computes linear regression over samples in time and returns the slope. Computes linear regression over samples in time and returns the slope.
### Other functions
#### `quantity`
Creates Pint Quantity values.
Parameters:
* value (str or other)
* unit (str, optional)
Example:
```
> quantity('1 GB/s')
<class 'pint.Quantity'>
1.0 gigabyte / second
> quantity(5, 'GB/s')
<class 'pint.Quantity'>
5 gigabyte / second
```
## Rule format ## Rule format
......
...@@ -344,6 +344,21 @@ def rule_prepare_input(parameters, rules, clusters, job_meta, job_data): ...@@ -344,6 +344,21 @@ def rule_prepare_input(parameters, rules, clusters, job_meta, job_data):
#for jn in job_names: #for jn in job_names:
# globals[jn] = True # globals[jn] = True
def quantity_create(value, unit=None):
if unit == None:
if type(value) == str:
return unit_registry.parse_expression(value)
else:
raise Exception("Unit creation: expected string, got {}".format(value))
else:
if type(value) == str and type(unit) == str:
return unit_registry.parse_expression(value+" "+unit)
elif type(unit) == str:
return unit_registry.Quantity(value, unit_registry.parse_units(unit))
else:
raise Exception("Unit creation: expected string for unit, got {}".format(unit))
globals["quantity"] = quantity_create
# prepare job metadata # prepare job metadata
job = JobMetadata() job = JobMetadata()
# copy all attributes from json to job object # copy all attributes from json to job object
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment