forked from dongweiming/web_develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0d175d
commit d4cc8cb
Showing
9 changed files
with
91 additions
and
13 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# coding=utf-8 | ||
# From http://bit.ly/2beWXlj | ||
import xlsxwriter | ||
|
||
workbook = xlsxwriter.Workbook('chart_styles.xlsx') | ||
|
||
# Show the styles for all of these chart types. | ||
chart_types = ['column', 'area', 'line', 'pie'] | ||
|
||
for chart_type in chart_types: | ||
|
||
# Add a worksheet for each chart type. | ||
worksheet = workbook.add_worksheet(chart_type.title()) | ||
worksheet.set_zoom(30) | ||
style_number = 1 | ||
|
||
# Create 48 charts, each with a different style. | ||
for row_num in range(0, 90, 15): | ||
for col_num in range(0, 64, 8): | ||
|
||
chart = workbook.add_chart({'type': chart_type}) | ||
chart.add_series({'values': '=Data!$A$1:$A$6'}) | ||
chart.set_title({'name': 'Style %d' % style_number}) | ||
chart.set_legend({'none': True}) | ||
chart.set_style(style_number) | ||
|
||
worksheet.insert_chart(row_num, col_num, chart) | ||
style_number += 1 | ||
|
||
# Create a worksheet with data for the charts. | ||
data_worksheet = workbook.add_worksheet('Data') | ||
data = [10, 40, 50, 20, 10, 50] | ||
data_worksheet.write_column('A1', data) | ||
data_worksheet.hide() | ||
|
||
workbook.close() |
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# coding=utf-8 | ||
import logging | ||
from logging.handlers import RotatingFileHandler | ||
|
||
from flask import Flask, request, jsonify | ||
from flask_sqlalchemy import get_debug_queries | ||
|
||
from ext import db | ||
from users import User | ||
|
||
app = Flask(__name__) | ||
app.config.from_object('config') | ||
app.config['DATABASE_QUERY_TIMEOUT'] = 0.0001 | ||
app.config['SQLALCHEMY_RECORD_QUERIES'] = True | ||
db.init_app(app) | ||
|
||
formatter = logging.Formatter( | ||
"[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s") | ||
handler = RotatingFileHandler('slow_query.log', maxBytes=10000, backupCount=10) | ||
handler.setLevel(logging.WARN) | ||
handler.setFormatter(formatter) | ||
app.logger.addHandler(handler) | ||
|
||
with app.app_context(): | ||
db.drop_all() | ||
db.create_all() | ||
|
||
|
||
@app.route('/users', methods=['POST']) | ||
def users(): | ||
username = request.form.get('name') | ||
|
||
user = User(username) | ||
print 'User ID: {}'.format(user.id) | ||
db.session.add(user) | ||
db.session.commit() | ||
|
||
return jsonify({'id': user.id}) | ||
|
||
|
||
@app.after_request | ||
def after_request(response): | ||
for query in get_debug_queries(): | ||
if query.duration >= app.config['DATABASE_QUERY_TIMEOUT']: | ||
app.logger.warn( | ||
('\nContext:{}\nSLOW QUERY: {}\nParameters: {}\n' | ||
'Duration: {}\n').format(query.context, query.statement, | ||
query.parameters, query.duration)) | ||
return response | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(host='0.0.0.0', port=9000) |