def test_function_selector_could_not_match(): # should return False obj = go.layout.Annotation(x=1, y=2, text="pat metheny") def _sel(d): return d["x"] == 1 and d["y"] == 3 and d["text"] == "pat metheny" assert BaseFigure._selector_matches(obj, _sel) == False
def test_baseplotlytypes_cannot_match_subset(): # should return False because "undefined" keys in sel return None, and are # compared (because "key in sel" returned True, it's value was None) obj = go.layout.Annotation(x=1, y=2, text="pat metheny") sel = go.layout.Annotation( x=1, y=2, ) assert BaseFigure._selector_matches(obj, sel) == False
def test_selector_has_nonmatching_value(): # should return False assert ( BaseFigure._selector_matches( dict(hello="everybody", today="cloudy", myiq=55), dict(myiq=55, today="sunny"), ) == False )
def test_selector_has_nonmatching_key(): # should return False assert ( BaseFigure._selector_matches( dict(hello="everybody", today="cloudy", myiq=55), dict(myiq=55, cronenberg="scanners"), ) == False )
def test_selector_matches_subset_of_obj(): # should return True assert ( BaseFigure._selector_matches( dict(hello="everybody", today="cloudy", myiq=55), dict(myiq=55, today="cloudy"), ) == True )
def test_string_selector_matches_type_key(): assert BaseFigure._selector_matches(dict(type="bar"), "bar") assert BaseFigure._selector_matches(dict(type="scatter"), "bar") == False
def test_selector_none(): # should return True assert BaseFigure._selector_matches({}, None) == True # arbitrary,
def test_baseplotlytypes_could_not_match(): # should return False obj = go.layout.Annotation(x=1, y=3, text="pat metheny") sel = go.layout.Annotation(x=1, y=2, text="pat metheny") assert BaseFigure._selector_matches(obj, sel) == False
def test_selector_empty_dict(): # should return True assert ( BaseFigure._selector_matches(dict(hello="everybody"), {}) == True # arbitrary, )
def index(): global colors # extract data needed for visuals data = df.iloc[:, 4:] genre_counts = df.groupby('genre').count()['message'] genre_names = list(genre_counts.index) cat_count = (df.iloc[:, 4:] != 0).sum() cat_names = list(cat_count.index) graphs = [ { 'data': [ bar( x=genre_names, y=genre_counts, color=genre_counts ) ], 'layout': { 'title': 'Distribution of Message Genres', 'yaxis': { 'title': "Count" }, 'xaxis': { 'title': "Genre" } } }, #top 5 most popular categories { 'data': [ bar( x=cat_names, y=cat_count, color=cat_count, color_continuous_scale=px.colors.diverging.Tealrose, color_continuous_midpoint=2 ) ], 'layout': { 'title': 'Counts of All Message Categories', 'yaxis': { 'title': "Count" }, 'xaxis': { 'title': "Categories" } } } ] #corr_list = [] #for row in data.corr().values: # corr_list.append(list(row)) # create visuals #strength #Default graph: genre distribution graph ''' graphs = [ { 'data': [ Bar( x=genre_names, y=genre_counts, marker = dict(color=color) ) ], 'layout': { 'title': 'Distribution of Message Genres', 'yaxis': { 'title': "Count" }, 'xaxis': { 'title': "Genre" } } }, #top 5 most popular categories { 'data': [ Bar( x=cat_names, y=cat_count, marker = dict(color=color) ) ], 'layout': { 'title': 'Counts of All Message Categories', 'yaxis': { 'title': "Count" }, 'xaxis': { 'title': "Categories" } } } ] ''' #assign unique id to each graph ids = ["graph-{}".format(i) for i, _ in enumerate(graphs)] graphJSON = BaseFigure.write_json('graph-1') # encode plotly graphs in JSON #graphJSON = json.dumps(graphs, cls=plotly.utils.PlotlyJSONEncoder) # render web page with plotly graphs return render_template('master.html', ids=ids, graphJSON=graphJSON)