def get_lethality_from_df(input):
    """get lethality for each group in given dataframe
    Args:
        input: 

    Return: 
    """
    df_preprocessor = DataframePreprocessor.init_from_file(input)
    df = df_preprocessor.get_dataframe().fillna(0)
    ans = np.zeros(n_group)
    for _, row in df.iterrows():
        name, nkill, nwound = row[COL_gname], row[COL_nkill], row[COL_nwound]
        index = group_lookup.get(name, None)
        if index is None: continue
        lethality = nkill * kill_wound_ratio + nwound
        ans[index] += lethality
    return ans
import sys
sys.path.append("../lib")
sys.path.append("..")
from dataframe_preprocessor import DataframePreprocessor
from util import plotter
import pandas as pd 
import matplotlib.pyplot as plt
import seaborn as sns
from GTD_Config import *

# CONSTANTS
gtd_csv = "../../data/GTD/globalterrorismdb_0617dist.csv"

# Construct dataframe preprocessor 
preprocessor = DataframePreprocessor.init_from_file(gtd_csv)
column_map = get_column_map()


#########  Select by Group #################
# COL_gname = "gname"
# selected_group = GROUP_ISIL 
# # selected_group = GROUP_Taliban
# output = "../../data/GTD/generated/GTD_sub_{}.csv".format(selected_group)

# # select data by selected_group
# preprocessor.filter_rows_by_condition(COL_gname, lambda x: x == selected_group)

# preprocessor.filter_rows_by_condition(COL_gname, lambda x: x == selected_group)

Ejemplo n.º 3
0
from util.plotter import *
from GTD_Config import *
from collections import defaultdict
from itertools import combinations
import pandas as pd
from plotly.graph_objs import *
import plotly.plotly as py
import numpy as np
import pickle
from dataframe_preprocessor import DataframePreprocessor

# Param
data = "../../data/GTD/generated/GTD_sub_related.csv"

# Read data
dataframe_preprocessor = DataframePreprocessor.init_from_file(
    data, index_col=COL_eventid)
dataframe_preprocessor.filter_rows_by_condition(COL_country,
                                                lambda x: x == 217)

df = dataframe_preprocessor.get_dataframe()

############### Plot ########################

title = "Related Network Analysis"

# plot layout
layout = {}
layout['legend'] = dict(x=-.1, y=1.2)
layout['title'] = title
# figure['layout']['autoscale'] = 0
layout['geo'] = dict(
Ejemplo n.º 4
0
from plotly.graph_objs import *
from dataframe_preprocessor import DataframePreprocessor

# Param
group = GROUP_Taliban
# group = GROUP_ISIL
data = "../../data/GTD/generated/GTD_sub_{}.csv".format(group)
selected_cols = [
    COL_year, 'imonth', 'iday', 'country_txt', 'region_txt', 'provstate',
    'city', 'latitude', 'longitude', 'attacktype1_txt', 'targtype1_txt',
    'gname', 'weaptype1_txt', 'nkill', 'nwound'
]
title = "Temporal Distribution of Terrorist Event by {}".format(group)

# Read data
dataframe_preprocessor = DataframePreprocessor.init_from_file(data)
df = dataframe_preprocessor.get_dataframe()

# Using only important columns
df = df[selected_cols]

# data range
geo_margin = 5
lat_range = dataframe_preprocessor.num_feature_range(COL_lat)
print("Latitude: {}".format(lat_range))
lat_range = (lat_range[0] - geo_margin, lat_range[1] + geo_margin)

# longitude
log_range = dataframe_preprocessor.num_feature_range(COL_log)
print("Longitude: {}".format(log_range))
log_range = (log_range[0] - geo_margin, log_range[1] + geo_margin)
Ejemplo n.º 5
0
def get_gtd_relation():
    """return dataframe preprocessor for GTD Relation subcsv  
    Return: 
    """
    return DataframePreprocessor.init_from_file(relation_csv_path,
                                                index_col=COL_eventid)
Ejemplo n.º 6
0
def get_full_gtd():
    """return dataframe preprocessor for full GTD Dataset 
    Return: 
    """
    return DataframePreprocessor.init_from_file(gtd_path,
                                                index_col=COL_eventid)