Exemple #1
0
def regress_js(filehash):
    file_handler = CSVFileHandler(settings.STORAGE_DIR)
    try:
        stats_data = file_handler.load_file(filehash)
    except:
        flask.abort(404)

    regression_params = RegressionParams.build_from_flask_args(request.args)
    sr = get_stats_runner(stats_data, regression_params)
    sr.run()
    result = sr.to_dict()

    # Trim a couple things from the result -- won't need 'em
    del result['all_point_data']
    del result['all_point_cols']
    http_result = flask.jsonify(result)
    http_result.headers['Cache-Control'] = 'max-age=300000000,public'
    http_result.headers['Expires'] = '31 December 2037 23:59:59 GMT'
    return http_result
Exemple #2
0
def regress_csv(filehash):
    import StringIO
    file_handler = CSVFileHandler(settings.STORAGE_DIR)
    try:
        stats_data = file_handler.load_file(filehash)
    except:
        flask.abort(404)

    regression_params = RegressionParams.build_from_flask_args(request.args)
    sr = get_stats_runner(stats_data, regression_params)
    sr.run()
    result = sr.to_dict()

    # Build us a string in memory
    out_buf = StringIO.StringIO()
    writer = csv.writer(out_buf, dialect='excel')
    writer.writerow(result['all_point_cols'])
    writer.writerows(result['all_point_data'])

    response = flask.make_response(out_buf.getvalue())
    response.headers["Content-Disposition"] = "attachment;filename=data.csv"
    response.headers["Content-Type"] = "text/csv"
    return response