def description(self): if self.repr('at') == get_choice(self.AT_CHOICES, self.STOP) or ( self.repr('at') == get_choice(self.AT_CHOICES, self.LIMIT)): price = ' = todays {}'.format(self.repr('pr')) else: price = '' return 'Enter tomorrow at {}{}.'.format(self.repr('at'), price)
def description(self): if self.repr('at') == get_choice(self.AT_CHOICES, self.OPEN): when = 'on the first trading day' elif self.repr('at') == get_choice(self.AT_CHOICES, self.CLOSE): when = 'on the last trading day' else: when = 'at the end' return 'Exit {} of the month at {}.'.format(when, self.repr('at'))
def description(self): if self.repr('xc') in ( get_choice(_Equity.EXCEED_CHOICES, _Equity.NOT), get_choice(_Equity.EXCEED_CHOICES, _Equity.ALL)): exceed = '{}'.format(self.repr('xc')) else: exceed = '{} if at least {} of the required cash is available'.\ format(self.repr('xc'), self.repr('pce')) return 'If there is not enough cash available for the next trade, ' \ '{}.'.format(exceed)
def description(self): if self.repr('sw') == get_choice(self.SWITCH_CHOICES, self.ON): if self.repr('mt') == get_choice(_Market.MKT_CHOICES, _Market.ANY): return 'Exit at {} if the market type is not this method\'s.'.\ format(self.repr('at')) else: return 'Exit at {} if the market type is {}.'.format( self.repr('at'), self.repr('mt')) else: return 'This exit is inactive'
def description(self): if self.repr('nd') == '1': when = 'tomorrow' else: when = 'after {} days on the market'.format(self.repr('nd')) if self.repr('at') == get_choice(self.AT_CHOICES, self.STOP) or ( self.repr('at') == get_choice(self.AT_CHOICES, self.LIMIT)): price = ' = todays {}'.format(self.repr('pr')) else: price = '' return 'Exit {} at {}{}.'.format(when, self.repr('at'), price)
def description(self): if self.repr('mo') == get_choice(self.MODE_CHOICES, self.ONE): mode = 'angle of channel {} is'.format(self.repr('lb')) flat = '.' else: mode = 'angles of all channels {} {} are'.format(self.repr('mo'), self.repr('lb')) flat = ', Flat otherwise.' return 'Market type is Up if the {} positive, Down if negative{}'.\ format(mode, flat)
def repr(self, parameter, negative=False): ''' Returns a formatted string that represents the value of this parameter, even if it is a range or a list of choices. If <negative> is True, -<value> will be returned in the string. ''' #TODO: AA: consider using mode as in ModeWidget choices = self.parameters[parameter].get('choices', None) fmt = self.parameters[parameter]['format'] sign = -1 if negative else 1 value = self._get_value(parameter) if isinstance(value, str) or isinstance(value, unicode): if not choices: raise ValueError('No choices found for {}'.format(parameter)) return get_choice(choices, value) elif isinstance(value, tuple): # assign a random value if choices: values = [get_choice(choices, v) for v in value] return '({})'.format(', '.join(values)) else: lo = fmt.format(sign * value[0]) hi = fmt.format(sign * value[1]) return '[{} to {}]'.format(lo, hi) elif isinstance(value, list): if len(value) == 1: # variable if choices: return get_choice(choices, value[0]) else: return fmt.format(sign * value[0]) else: # traverse a list if choices: values = [get_choice(choices, v) for v in value] return '[{}]'.format(', '.join(values)) else: values = [fmt.format(v) for v in value] return '[{}]'.format(', '.join(values)) elif not isinstance(value, int) and not isinstance(value, float): raise TypeError('Invalid type for {}.'.format(parameter)) return fmt.format(sign * value)
def render(self, name, value, attrs=None): ''' Show a fake dropdown with the value. ''' print name, self.model, self.choices_dict if self.model: val = self.model.objects.get(id=value).name elif self.choices_dict: val = get_choice(self.choices_dict, value) else: val = value txt = '<select disabled"/>' txt += '<option selected="selected">{}</option>'.format(val) txt += '</select><input type="hidden" name="{}" value="{}" id="id_{}">'\ .format(name, value, name) return mark_safe(txt)
def get_direction(self): ''' Return the trade diretion in human readable format ''' return get_choice(self.DIR_CHOICES, self.direction)
def markettype_str(self): ''' Return markettype as text ''' return get_choice(_Market.MKT_CHOICES, self.markettype)
def render(self, name, value, attrs=None): ''' Return an html string for this widget. <name> is the string containing the name of the field and <value> is a variable that contains the value of this parameter, the type of this value determines what the mode is. ''' size = 40 error = False readonly = attrs.get('readonly') == 'readonly' #determine mode mode = self.CHOICES if 'choices' in self.parameters else self.INTFLT if isinstance(value, int) or isinstance(value, float) or \ isinstance(value, str) or isinstance(value, unicode): mode += self.FIXED elif not len(value): raise ValueError('iterable parameter must not be empty') else: if isinstance(value, tuple): mode += self.RANDOM elif isinstance(value, list): mode += self.VARIABLE if len(value) == 1 else self.LIST else: raise TypeError('invalid value type: {}'.format(type(value))) if isinstance(value[0], int) or isinstance(value[0], float): # mode should be self.INTFLT pass elif isinstance(value[0], str) or isinstance(value[0], unicode): # mode should be self.CHOICES if mode & self.INTFLT: error = True else: raise TypeError('invalid type in iterable: {}'.format(type( value[0]))) print 'MODE = ', mode, name, value if mode & self.INTFLT: if mode & self.FIXED: val = '={}'.format(value) elif mode & self.RANDOM: val = '{} {}'.format(value[0], value[1]) elif mode & self.LIST: fmt = self.parameters['format'].partition('}')[0].partition('{') fmt = '{' + fmt[2] + '}' # remove everything outside {} if error: val = value else: val = ', '.join(fmt.format(v) for v in value) elif mode & self.VARIABLE: val = value[0] d = '' if readonly and ((mode & self.FIXED) or (mode & self.RANDOM)): d = ' readonly' html = '<input type="text" size="{0}" name="{1}" value="{2}" '\ 'id="id_{1}"{3}/>'.format(size, name, val, d) elif mode & self.CHOICES: if readonly and ((mode & self.FIXED) or (mode & self.RANDOM)): # show a fake dropdown if mode & self.RANDOM: val = '- random -' value = '-RND-' else: val = '=' + get_choice(self.parameters['choices'], value) value = '={}'.format(value) html = '<select disabled"/><option selected="selected">' html += '{}</option></select>'.format(val) # The actual value of this parameter is specified here: print '**', name, val, value html += '<input type="hidden" name="{}" value="{}" id="id_{}">'\ .format(name, value, name) else: html = '<select name="{0}" id="id_{0}"/>'.format(name) s = ' selected="selected"' if (mode & self.LIST) else '' html += '<option value="-ALL-"{}>- all -</option>'.format(s) if not readonly or (mode == self.RANDOM): s = ' selected="selected"' if (mode & self.RANDOM) else '' html += '<option value="-RND-"{}>- random -</option>'.\ format(s) html += '<optgroup label="Variable:">' for c1, c2 in self.parameters['choices']: s = '' if (mode & self.VARIABLE) and (str(c1) == str(value[0])): s = ' selected="selected"' html += '<option value="{}"{}>{}</option>'.format(c1, s, c2) html += '</optgroup>' if not readonly or (mode == self.FIXED) or (mode == self.RANDOM): html += '<optgroup label="Fixed:">' for c1, c2 in self.parameters['choices']: s = '' if (mode & self.FIXED) and (str(c1) == str(value)): s = ' selected="selected"' html += '<option value="={}"{}>={}</option>'.format( c1, s, c2) html += '</optgroup>' html += '</select>' html += '<input type="hidden" name="{}_MODE" value="{}">'.\ format(name, mode) return mark_safe(html)
def description(self): if self.repr('sw') == get_choice(self.SWITCH_CHOICES, self.ON): return 'Exit at {} if the market type has changed.'.format( self.repr('at')) else: return 'This exit is inactive'
def description(self): ra = '' if self.repr('ra') == get_choice(self.SWITCH_CHOICES, self.ON): ra = ' Adjust the bottom line in the direction of the trade.' return 'Exit tomorrow at market if the price goes below the bottom '\ 'line of the rank channel.{}'.format(ra)
def description(self): ra = '' if self.repr('ra') == get_choice(self.SWITCH_CHOICES, self.ON): ra = ' Adjust the top line in the direction of the trade.' return 'Exit tomorrow at market if the price goes above the top '\ 'line of the {} channel.{}'.format(self.repr('lb'), ra)
def render_method(self, record): return '{}'.format(get_choice(record.method.DIR_CHOICES, record.method.direction))