Example #1
0
 def __call__(self, cls):
     model_name= os.path.basename(getmodule(cls).__file__).split('.')[0]
     kwargs = make_name.DJANGO_MODEL
     kwargs['remove_prefix'] = self.remove_prefix
     model_name = make_name(model_name, **kwargs)
     # self.db_name = re.sub(r'[.]pyc?$', '', self.db_name, flags=re.IGNORECASE)
     # self.db_name = re.sub(r'[._-]+models$', '', self.db_name, flags=re.IGNORECASE)
     # self.db_name = re.sub(r'^models[._-]+', '', self.db_name, flags=re.IGNORECASE)
     setattr(cls, '__name__', model_name + self.sep + getattr(cls, '__name__'))
     return cls
Example #2
0
 def __call__(self, cls):
     model_name = os.path.basename(getmodule(cls).__file__).split('.')[0]
     kwargs = make_name.DJANGO_MODEL
     kwargs['remove_prefix'] = self.remove_prefix
     model_name = make_name(model_name, **kwargs)
     # self.db_name = re.sub(r'[.]pyc?$', '', self.db_name, flags=re.IGNORECASE)
     # self.db_name = re.sub(r'[._-]+models$', '', self.db_name, flags=re.IGNORECASE)
     # self.db_name = re.sub(r'^models[._-]+', '', self.db_name, flags=re.IGNORECASE)
     setattr(cls, '__name__',
             model_name + self.sep + getattr(cls, '__name__'))
     return cls
Example #3
0
def d3_plot_context(context, table=((0, 0),), title='Line Chart', xlabel='Time', ylabel='Value', header=None, limit=10001):
    """

    Arguments:
      table (list of lists of values): A CSV/Excel style table with an optional header row as the first list
      title (str): String to display atop the plot
      xlabel (str): Text to display along the bottom axis
      ylabel (str): Text to display along the vertical axis
      limit (int): Maximum number of points to include in context variable `data.d3data`
    """
    if isinstance(table, pd.Series):
        table = pd.DataFrame(table, columns=header or [ylabel]).sort_index()
    if isinstance(table, pd.DataFrame):
        df = table.sort_index()
        table = list(df.to_records())
        for i, row in enumerate(table):
            d = row[0]
            first_row = []
            if isinstance(d, datetime.datetime):
                # ISO 8601 date-time format is ECMA/javascript-friendly: 
                #    YYYY-MM-DDTHH:mm:ss.sssZ  
                #    `T` and `Z` are literal characters, alternatively `Z` (means UTC) can be replaced with timezone info like +/-HH:mm
                table[i][0] = d.isoformat()
                if not first_row:
                    first_row += ['Date-Time']
            elif isinstance(d, datetime.date):
                table[i][0] = "{0:02d}-{1:02d}-{2:02d}".format(d.year, d.month, d.day)
                if not first_row:
                    first_row += ['Date']
            else:
                if not first_row:
                    first_row += ['Sample']
        first_row += list(str(c).strip() for c in df.columns)
        header = None
    else:
        first_row = list(table[0])
    N, M = len(table), max(len(row) for row in table)
    identifiers = header
    descriptions = header
    if not header and not all(isinstance(col, basestring) and col.strip() for col in first_row):
        print first_row
        if isinstance(header, bool):
            header = []
        else:
            header = [('y{0}'.format(i-1) if i else 'x') for i in range(M)]
    else:
        header = first_row
        table = table[1:]

    # header should now be a list of one list of strings or an empty list,
    # So now just need to make sure the names of the columns are valid javascript identifiers
    if header:
        identifiers = [util.make_name(h, language='javascript', space='') for h in header]
        table = [header] + table
        descriptions = [unicode(h) for h in header]
    
    # print header, identifiers
    if len(table) > limit:
        new_table = [table[0]]
        step = int(float(len(table))/limit)
        print "step = {0}".format(step)
        for i in range(1+limit, len(table), step):
            new_table += [table[i]]
        table = new_table

    context['data'] = context.get('data', {})
    context['data'].update({
        #'lags_dict': {hist_type: lags},
        'title': title,
        'header': json.dumps(identifiers),
        'descriptions': json.dumps(descriptions),
        'xlabel': xlabel,
        'ylabel': ylabel,
        'd3data': json.dumps(util.transposed_lists(table)), 
        'form': {},
    })
    # print context['data']
    return context
Example #4
0
def clean_labels(df):
    # in iPython Notebook print out df.columns to show that many of them contain dots
    # rename the columns to be attribute-name friendly
    df.columns = [label.replace('.', '_') for label in df.columns]
    df.columns = [make_name(label) for label in df.columns]
    return df
Example #5
0
File: clean.py Project: Redwa/twip
def clean_labels(df):
    # in iPython Notebook print out df.columns to show that many of them contain dots
    # rename the columns to be attribute-name friendly
    df.columns = [label.replace('.', '_') for label in df.columns]
    df.columns = [make_name(label) for label in df.columns]
    return df