Example #1
0
def data_to_table(axes, data):
    if axes is None or 'x' not in axes or 'y' not in axes:
        return None

    groupped_data = group_by_x(axes['x']['key'], data)

    rows = []
    x_axis_format = axes['x'].get('format', {})
    for x_value, data in groupped_data.iteritems():
        row = [{
            'formatted': format(x_value, x_axis_format),
            'raw': json.dumps(x_value),
        }]
        for axis in axes['y']:
            formatting = axis.get('format', {})

            if 'groupKey' in axis and 'groupValue' in axis:
                datum = find_by_grouping(axis, data)
            else:
                datum = data[0]

            if datum is not None:
                value = datum[axis['key']]
                row.append({
                    'formatted': format(value, formatting),
                    'raw': json.dumps(value),
                })
            else:
                row.append({
                    'formatted': None,
                    'raw': None,
                })
        rows.append(row)

    try:
        fields = [{
            'label': axes['x']['label'],
            'format': json.dumps(axes['x'].get('format', {}),)
        }] + [{
            'label': axis['label'],
            'format': json.dumps(axis.get('format', {})),
        } for axis in axes['y']]
    except KeyError:
        fields = [{
            'label': '',
            'format': '{}',
        }] * len(rows[0])
        print self.data_source.url()
        print self._json['module-type']

    return {
        'fields': fields,
        'rows': rows,
    }
 def __str__(self):
     """
     Calling str(datum) should check first for a formatted
     version of value, then fall back to the default value
     if there's no set formatting.
     """
     if self.column_name in list(self.table.formatting.keys()):
         func = self.table.formatting[self.column_name].get("method", None)
         args = self.table.formatting[self.column_name].get("arguments", [])
         kwargs = self.table.formatting[self.column_name].get("options", {})
         if func:
             row = self.table[self.row_num]
             args = [row[arg].value for arg in args]
             return format(self.value, func, *args, **kwargs)
     return self.value.encode("utf-8")
 def __str__(self):
     """
     Calling str(datum) should check first for a formatted
     version of value, then fall back to the default value
     if there's no set formatting.
     """
     if self.column_name in list(self.table.formatting.keys()):
         func = self.table.formatting[self.column_name].get('method', None)
         args = self.table.formatting[self.column_name].get('arguments', [])
         kwargs = self.table.formatting[self.column_name].get('options', {})
         if func:
             row = self.table[self.row_num]
             args = [row[arg].value for arg in args]
             return format(self.value, func, *args, **kwargs)
     return self.value.encode('utf-8')
 def __unicode__(self):
     """
     Check first for a formatted version of value, then fall back to the
     default value if there's no set formatting.
     """
     # Unicode or bust
     value = self.value
     if isinstance(self.value, basestring):
         if not isinstance(self.value, unicode):
             value = unicode(self.value, 'utf-8')
     # Apply any formatting
     if self.table.formatting.has_key(self.column_name):
         func = self.table.formatting[self.column_name].get('method', None)
         args = self.table.formatting[self.column_name].get('arguments', [])
         kwargs = self.table.formatting[self.column_name].get('options', {})
         if func:
             row = self.table[self.row_num]
             args = [row[arg].value for arg in args]
             return format(value, func, *args, **kwargs)
     else:
         return value
Example #5
0
from flask import Flask, render_template, redirect, url_for, jsonify
from bs4 import BeautifulSoup
from tourney_simulator import season_simulator
from formatting import format
from chalk import chalk_simulator

app = Flask(__name__)

year = 2019
models = ["Model A", "Model B", "Model C"]
first64 = [str(x) for x in range(64)]
data = season_simulator(year)
model_A = format(data)
print("HERE")
model_B = chalk_simulator(year)

@app.route('/')
def render():
	return render_template("index.html", game = [])


@app.route('/modelA')
def modelA():
	return render_template("index.html", model="2019 Model", game = model_A)

@app.route('/modelB')
def modelB():
	return render_template("index.html", model="Chalk", game = model_B)

@app.route('/modelC')
def modelC():