Exemple #1
0
    def setUp(self):
        '''Produces short test datasets that can be used to unit test functions affecting dataframes'''
        df1 = pd.DataFrame(np.random.randn(10, 5),
                           columns=['a', 'b', 'c', 'd', 'e'])
        df2 = pd.DataFrame([
            'High', 'Medium', 'Low', 'High', 'High', 'Low', 'Low', 'Medium',
            'Low', 'Low'
        ],
                           columns=['Height'])
        df3 = pd.DataFrame([
            'Heavy', 'Light', 'Very Heavy', 'Very Heavy', 'Light',
            'Very Light', 'Very Light', 'Light', 'Light', 'Heavy'
        ],
                           columns=['Weight'])
        df4 = pd.DataFrame([
            'Box', 'Bag', 'Bag', 'Box', 'Box', 'Box', 'Bag', 'Bag', 'Box',
            'Box'
        ],
                           columns=['Container'])
        self.test_data = pd.concat([df1, df2, df3, df4], axis=1)

        self.data_creation = ht.GTA()
        self.test_bc_data = self.data_creation.gt_df[0:10][[
            'country', 'region', 'attacktype', 'casualties'
        ]]
        self.test_bubble_chart = Bubble_Chart_Data(self.test_bc_data,
                                                   'country', 'region',
                                                   'attacktype', 'casualties')

        self.test_dot_plot_data = self.data_creation.gt_df[0:50000]
        self.test_dot_plot = Dot_Plot_Data(self.test_dot_plot_data, 'country',
                                           'casualties', 'year', 'attacktype',
                                           'casualties')
Exemple #2
0
    def test_GTA(self):
        '''
        test the GTA class with its attributes and methods in the heatmap module
        '''
        gta = ht.GTA()
        # test the attibute
        self.assertIn('South Asia', gta.region_names)
        self.assertEqual(12, len(gta.region_names))

        # test the methods
        ctr_dict = gta.countries_by_region()
        self.assertEqual(dict, type(ctr_dict))
        self.assertIn('Australasia & Oceania', ctr_dict.keys())
        self.assertTrue(np.ndarray, type(ctr_dict['East Asia']))
        self.assertIn('Vatican City', ctr_dict['Western Europe'])
Exemple #3
0
Project co-author: Viola Ciao (xc965)
'''

from __future__ import print_function
from ipywidgets import interact, interactive, fixed
import ipywidgets as widgets

import pandas as pd
import seaborn as sns
import math

from util import *
from Geo2D import year_interval_slider
import heatmap as ht

global_terrorism = ht.GTA()
global_terrorism.gt_df.head()

dot_plot_features = ['country', 'year', 'attacktype', 'casualties']
gtd_dot = global_terrorism.gt_df[dot_plot_features]


class Dot_Plot_Data():
    def __init__(self, data, yaxis_vals, xaxis_vals, user_filter1,
                 user_filter2, metric):
        '''Defines attributes of the dot plot'''
        self.data = data[[yaxis_vals, xaxis_vals, user_filter1, user_filter2]]
        self.yaxis_vals = yaxis_vals
        self.xaxis_vals = xaxis_vals
        self.user_filter1 = user_filter1
        self.user_filter2 = user_filter2
module author: Caroline Roper
project co-author: Viola Ciao
'''

from ipywidgets import *
import pandas as pd
import numpy as np
import heatmap as ht
import matplotlib.pyplot as plt
import math
import matplotlib.patches as mpatches
import util
from matplotlib import cm

Global_terrorism_analysis = ht.GTA()
bubble_chart_features = ['year', 'country', 'region', 'casualties']
gtd_bubble = Global_terrorism_analysis.gt_df[bubble_chart_features]
gtd_bubble = util.replace_series_with_range(gtd_bubble, gtd_bubble['year'], 5)


def construct_interval(year):
    '''Constructs an interval given a year'''
    return '(' + str(year - 5) + ', ' + str(year) + ']'


def draw_legend(colors_legend):
    '''Draws a legend according to a dictionary'''
    recs = []
    for key in list(colors_legend.keys()):
        recs.append(