ensembl-hive-python3  2.8.1
PartMultiply.py
Go to the documentation of this file.
1 
2 # See the NOTICE file distributed with this work for additional information
3 # regarding copyright ownership.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 import eHive
18 
19 import time
20 
22  """Runnable to multiply a number by a digit"""
23 
24  def param_defaults(self):
25  return {
26  'take_time' : 0
27  }
28 
29 
30  def run(self):
31  a_multiplier = self.param_required('a_multiplier')
32  digit = int(self.param_required('digit'))
33  self.param('partial_product', rec_multiply(str(a_multiplier), digit, 0))
34  time.sleep( self.param('take_time') )
35 
36 
37  def write_output(self):
38  self.dataflow( { 'partial_product' : self.param('partial_product') }, 1)
39 
40 
41 def rec_multiply(a_multiplier, digit, carry):
42  """Function to multiply a number by a digit"""
43 
44  if a_multiplier == '':
45  return str(carry) if carry else ''
46 
47  prefix = a_multiplier[:-1]
48  last_digit = int(a_multiplier[-1])
49 
50  this_product = last_digit * digit + carry
51  this_result = this_product % 10
52  this_carry = this_product // 10
53 
54  return rec_multiply(prefix, digit, this_carry) + str(this_result)
55 
56 
eHive.process.BaseRunnable
This is the counterpart of GuestProcess.
Definition: process.py:60
eHive.process.BaseRunnable.dataflow
def dataflow(self, output_ids, branch_name_or_code=1)
Dataflows the output_id(s) on a given branch (default 1).
Definition: process.py:229
eHive.examples.LongMult.PartMultiply.PartMultiply.run
def run(self)
Definition: PartMultiply.py:30
eHive.examples.LongMult.PartMultiply.PartMultiply
Runnable to multiply a number by a digit.
Definition: PartMultiply.py:22
eHive.examples.LongMult.PartMultiply.PartMultiply.param_defaults
def param_defaults(self)
Returns the defaults parameters for this runnable.
Definition: PartMultiply.py:24
eHive.process.BaseRunnable.param_required
def param_required(self, param_name)
Returns the value of the parameter "param_name" or raises an exception if anything wrong happens or t...
Definition: process.py:253
eHive.examples.LongMult.PartMultiply.rec_multiply
def rec_multiply(a_multiplier, digit, carry)
Function to multiply a number by a digit.
Definition: PartMultiply.py:42
eHive.process.BaseRunnable.param
def param(self, param_name, *args)
When called as a setter: sets the value of the parameter "param_name".
Definition: process.py:266
eHive.examples.LongMult.PartMultiply.PartMultiply.write_output
def write_output(self)
Definition: PartMultiply.py:37