ensembl-hive-python3  2.3
PartMultiply.py
Go to the documentation of this file.
1 
2 import eHive
3 
4 import time
5 
7  """Runnable to multiply a number by a digit"""
8 
9  def param_defaults(self):
10  return {
11  'take_time' : 0
12  }
13 
14 
15  def run(self):
16  a_multiplier = self.param_required('a_multiplier')
17  digit = int(self.param_required('digit'))
18  self.param('partial_product', rec_multiply(str(a_multiplier), digit, 0))
19  time.sleep( self.param('take_time') )
20 
21 
22  def write_output(self):
23  self.dataflow( { 'partial_product' : self.param('partial_product') }, 1)
24 
25 
26 def rec_multiply(a_multiplier, digit, carry):
27  """Function to multiply a number by a digit"""
28 
29  if a_multiplier == '':
30  return str(carry) if carry else ''
31 
32  prefix = a_multiplier[:-1]
33  last_digit = int(a_multiplier[-1])
34 
35  this_product = last_digit * digit + carry
36  this_result = this_product % 10
37  this_carry = this_product // 10
38 
39  return rec_multiply(prefix, digit, this_carry) + str(this_result)
40 
41 
def param_required(self, param_name)
Returns the value of the parameter "param_name" or raises an exception if anything wrong happens...
Definition: Process.py:242
def rec_multiply(a_multiplier, digit, carry)
Function to multiply a number by a digit.
Definition: PartMultiply.py:29
Runnable to multiply a number by a digit.
Definition: PartMultiply.py:8
This is the counterpart of GuestProcess.
Definition: Process.py:50
def param(self, param_name, args)
When called as a setter: sets the value of the parameter "param_name".
Definition: Process.py:254
def dataflow(self, output_ids, branch_name_or_code=1)
Dataflows the output_id(s) on a given branch (default 1).
Definition: Process.py:213