# -*- coding: utf-8 -*-
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
import pandas as pd
# ?????? ?????? ??? ?????????
from sqlalchemy import create_engine
# ?????? ??????????? ? ???? ?????? ??? Postresql
#db_config = {'user': 'my_user',
# 'pwd': 'my_user_password',
# 'host': 'localhost',
# 'port': 5432,
# 'db': 'games'}
#engine = create_engine('postgresql://{}:{}@{}:{}/{}'.format(db_config['user'],
# db_config['pwd'],
# db_config['host'],
# db_config['port'],
# db_config['db']))
# ?????? ??????????? ? ???? ?????? ??? Sqlite
engine = create_engine('sqlite:////db/games.db', echo = False)
# ???????? ????? ??????
query = '''
SELECT * FROM data_raw
'''
games_raw = pd.io.sql.read_sql(query, con = engine)
#
games_grouped
games_raw['year_of_release'] =
.agg({'name': 'nunique'})
.rename(columns
columns =
.reset_index()
)
games_grouped
for column in columns: games_raw[column] =
games_raw['total'] = games_raw[['na_players',
'eu_players',
'jp_players',
'other_players']].sum(axis = 1).round(2)
#
# ????????? ???????
games_grouped['label'] = games_grouped.apply(lambda x: '{} ???'.format( x['games_launched']), axis = 1)
# ?????????
games_raw = games_raw[['name', 'platform', 'genre', 'total']].sort_values(by = 'total', ascending = False).head(10) # ???????? ???
data = [go.
y
'<b>????</b>', '<b>??????? ?? ???? ????????</b>'],
'fill_color': 'lightgrey',
'align': 'center'},
cells =
text = games_grouped['label'],
textposition = 'auto',
name = 'games_launched')]
# ?????? ??????
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets,compress=False)
app.layout = html.Div(children=[
# ????????? ????????? ????? HTML
html.H1(children =
dcc.Graph(
figure = {'data': data,
'layout': go.
yaxis = {'title': '?????????? ????'})
},
id =
),
])
# ????????? ?????? ????????
if __name__ == '__main__':
app.run_server(host='0.0.0.0', port=3000)