def prepare(metric, file, output): with open(file, 'r') as f: data = json.load(f) pairs = {} _rs = [] _lm = [] _am = [] _al = [] _as = [] _ar = [] _ls = [] _ms = [] _rl = [] _rm = [] for k, v in data.iteritems(): for key, value in v.iteritems(): if key == "rs" or key == "sr": _rs.append(value) elif key == "lm" or key == "ml": _lm.append(value) elif key == "am" or key == "ma": _am.append(value) elif key == "al" or key == "la": _al.append(value) elif key == "as" or key == "sa": _as.append(value) elif key == "ar" or key == "ra": _ar.append(value) elif key == "ls" or key == "sl": _ls.append(value) elif key == "ms" or key == "sm": _ms.append(value) elif key == "rl" or key == "lr": _rl.append(value) elif key == "rm" or key == "mr": _rm.append(value) _rs_avg = calc.calcular_full(_rs) _lm_avg = calc.calcular_full(_lm) _am_avg = calc.calcular_full(_am) _al_avg = calc.calcular_full(_al) _as_avg = calc.calcular_full(_as) _ar_avg = calc.calcular_full(_ar) _ls_avg = calc.calcular_full(_ls) _ms_avg = calc.calcular_full(_ms) _rl_avg = calc.calcular_full(_rl) _rm_avg = calc.calcular_full(_rm) _aa_avg = 1.0 _ss_avg = 1.0 _rr_avg = 1.0 _ll_avg = 1.0 _mm_avg = 1.0 color_bar(_rs_avg, _lm_avg, _am_avg, _al_avg, _as_avg, _ar_avg, _ls_avg, _ms_avg, _rl_avg, _rm_avg, _aa_avg, _ss_avg, _rr_avg, _ll_avg, _mm_avg, output_dir)
def _byteify(data, ignore_dicts=False): # if this is a unicode string, return its string representation if isinstance(data, unicode): return data.encode('utf-8') # if this is a list of values, return list of byteified values if isinstance(data, list): return [_byteify(item, ignore_dicts=True) for item in data] # if this is a dictionary, return dictionary of byteified keys and values # but only if we haven't already byteified it if isinstance(data, dict) and not ignore_dicts: return { _byteify(key, ignore_dicts=True): _byteify(value, ignore_dicts=True) for key, value in data.iteritems() } # if it's anything else, return it in its original form return data
def gainPercentage(ts): ts_gain = pd.DataFrame(columns=['gain']) # Get the data starting from the 2nd element data = ts[1:] ''' The formula of the gain being the current stock price minus the previous one, devided by the latter, we'll need to keep track of the previous index at all times ''' previous_index = ts.index[0] # Iterating over the data without the first element, and compute the gain using the aforementioned formula for index_ts, row_ts in data.iteritems(): gain_value = (ts[index_ts]-ts[previous_index])/ts[previous_index] ts_gain.loc[index_ts] = gain_value previous_index = index_ts return ts_gain.gain
def prepare(metric, file, output): with open(file, 'r') as f: data = json.load(f) pairs = {} _rs = [] _lm = [] _am = [] _al = [] _as = [] _ar = [] _ls = [] _ms = [] _rl = [] _rm = [] for k, v in data.iteritems(): for key, value in v.iteritems(): if key == "rs": _rs.append(value) elif key == "lm": _lm.append(value) elif key == "am": _am.append(value) elif key == "al": _al.append(value) elif key == "as": _as.append(value) elif key == "ar": _ar.append(value) elif key == "ls": _ls.append(value) elif key == "ms": _ms.append(value) elif key == "rl": _rl.append(value) elif key == "rm": _rm.append(value) plot_hist(_rs, output, metric, "Retweets X Followee") plot_hist(_lm, output, metric, "Likes X Mentions") plot_hist(_am, output, metric, "Follow X Mentions") plot_hist(_al, output, metric, "Follow X Likes") plot_hist(_as, output, metric, "Follow X Followee") plot_hist(_ar, output, metric, "Follow X Retweets") plot_hist(_ls, output, metric, "Likes X Followee") plot_hist(_ms, output, metric, "Mentions X Followee") plot_hist(_rl, output, metric, "Retweets X Likes") plot_hist(_rm, output, metric, "Retweets X Mentions") _rs_avg = calc.calcular_full(_rs) _rs_avg = _rs_avg['media'] _lm_avg = calc.calcular_full(_lm) _lm_avg = _lm_avg['media'] _am_avg = calc.calcular_full(_am) _am_avg = _am_avg['media'] _al_avg = calc.calcular_full(_al) _al_avg = _al_avg['media'] _as_avg = calc.calcular_full(_as) _as_avg = _as_avg['media'] _ar_avg = calc.calcular_full(_ar) _ar_avg = _ar_avg['media'] _ls_avg = calc.calcular_full(_ls) _ls_avg = _ls_avg['media'] _ms_avg = calc.calcular_full(_ms) _ms_avg = _ms_avg['media'] _rl_avg = calc.calcular_full(_rl) _rl_avg = _rl_avg['media'] _rm_avg = calc.calcular_full(_rm) _rm_avg = _rm_avg['media'] _aa_avg = 1.0 _ss_avg = 1.0 _rr_avg = 1.0 _ll_avg = 1.0 _mm_avg = 1.0 color_bar(_rs_avg, _lm_avg, _am_avg, _al_avg, _as_avg, _ar_avg, _ls_avg, _ms_avg, _rl_avg, _rm_avg, _aa_avg, _ss_avg, _rr_avg, _ll_avg, _mm_avg, output_dir)
def prepare(metric,file,title): with open(file,'r') as f: data = json.load(f) _aa = [] _as = [] _ar = [] _al = [] _am = [] _sa = [] _ss = [] _sr = [] _sl = [] _sm = [] _ra = [] _rs = [] _rr = [] _rl = [] _rm = [] _la = [] _ls = [] _lr = [] _ll = [] _lm = [] _ma = [] _ms = [] _mr = [] _ml = [] _mm = [] for k,v in data.iteritems(): for key,value in v.iteritems(): if key == "aa": _aa.append(value) elif key == "as": _as.append(value) elif key == "ar": _ar.append(value) elif key == "al": _al.append(value) elif key == "am": _am.append(value) elif key == "sa": _sa.append(value) elif key == "ss": _ss.append(value) elif key == "sr": _sr.append(value) elif key == "sl": _sl.append(value) elif key == "sm": _sm.append(value) elif key == "ra": _ra.append(value) elif key == "rs": _rs.append(value) elif key == "rr": _rr.append(value) elif key == "rl": _rl.append(value) elif key == "rm": _rm.append(value) elif key == "la": _la.append(value) elif key == "ls": _ls.append(value) elif key == "lr": _lr.append(value) elif key == "ll": _ll.append(value) elif key == "lm": _lm.append(value) elif key == "ma": _ma.append(value) elif key == "ms": _ms.append(value) elif key == "mr": _mr.append(value) elif key == "ml": _ml.append(value) elif key == "mm": _mm.append(value) else: print ("Rede inválida") sys.exit() box_plot(metric,_aa,_as,_ar,_al,_am,_sa,_ss,_sr,_sl,_sm,_ra,_rs,_rr,_rl,_rm,_la,_ls,_lr,_ll,_lm,_ma,_ms,_mr,_ml,_mm,title)
def prepare(metric,file): with open(file,'r') as f: data = json.load(f) _aa = [] _as = [] _ar = [] _al = [] _am = [] _sa = [] _ss = [] _sr = [] _sl = [] _sm = [] _ra = [] _rs = [] _rr = [] _rl = [] _rm = [] _la = [] _ls = [] _lr = [] _ll = [] _lm = [] _ma = [] _ms = [] _mr = [] _ml = [] _mm = [] for k,v in data.iteritems(): for key,value in v.iteritems(): if key == "aa": _aa.append(value) elif key == "as": _as.append(value) elif key == "ar": _ar.append(value) elif key == "al": _al.append(value) elif key == "am": _am.append(value) elif key == "sa": _sa.append(value) elif key == "ss": _ss.append(value) elif key == "sr": _sr.append(value) elif key == "sl": _sl.append(value) elif key == "sm": _sm.append(value) elif key == "ra": _ra.append(value) elif key == "rs": _rs.append(value) elif key == "rr": _rr.append(value) elif key == "rl": _rl.append(value) elif key == "rm": _rm.append(value) elif key == "la": _la.append(value) elif key == "ls": _ls.append(value) elif key == "lr": _lr.append(value) elif key == "ll": _ll.append(value) elif key == "lm": _lm.append(value) elif key == "ma": _ma.append(value) elif key == "ms": _ms.append(value) elif key == "mr": _mr.append(value) elif key == "ml": _ml.append(value) elif key == "mm": _mm.append(value) else: print ("Rede inválida") sys.exit() _aa_avg = calc.calcular_full(_aa) _as_avg = calc.calcular_full(_as) _ar_avg = calc.calcular_full(_ar) _al_avg = calc.calcular_full(_al) _am_avg = calc.calcular_full(_am) _sa_avg = calc.calcular_full(_sa) _ss_avg = calc.calcular_full(_ss) _sr_avg = calc.calcular_full(_sr) _sl_avg = calc.calcular_full(_sl) _sm_avg = calc.calcular_full(_sm) _ra_avg = calc.calcular_full(_ra) _rs_avg = calc.calcular_full(_rs) _rr_avg = calc.calcular_full(_rr) _rl_avg = calc.calcular_full(_rl) _rm_avg = calc.calcular_full(_rm) _la_avg = calc.calcular_full(_la) _ls_avg = calc.calcular_full(_ls) _lr_avg = calc.calcular_full(_lr) _ll_avg = calc.calcular_full(_ll) _lm_avg = calc.calcular_full(_lm) _ma_avg = calc.calcular_full(_ma) _ms_avg = calc.calcular_full(_ms) _mr_avg = calc.calcular_full(_mr) _ml_avg = calc.calcular_full(_ml) _mm_avg = calc.calcular_full(_mm) color_bar(metric,_aa_avg,_as_avg,_ar_avg,_al_avg,_am_avg, _sa_avg,_ss_avg,_sr_avg,_sl_avg,_sm_avg, _ra_avg,_rs_avg,_rr_avg,_rl_avg,_rm_avg, _la_avg,_ls_avg,_lr_avg,_ll_avg,_lm_avg, _ma_avg,_ms_avg,_mr_avg,_ml_avg,_mm_avg)
def print_data_overlapping_vertives(metric, file, output): with open(file, 'r') as f: data = json.load(f) pairs = {} _aa = [] _as = [] _ar = [] _al = [] _am = [] _sa = [] _ss = [] _sr = [] _sl = [] _sm = [] _ra = [] _rs = [] _rr = [] _rl = [] _rm = [] _la = [] _ls = [] _lr = [] _ll = [] _lm = [] _ma = [] _ms = [] _mr = [] _ml = [] _mm = [] for k, v in data.iteritems(): for key, value in v.iteritems(): if key == "aa": _aa.append(value) elif key == "as": _as.append(value) elif key == "ar": _ar.append(value) elif key == "al": _al.append(value) elif key == "am": _am.append(value) elif key == "sa": _sa.append(value) elif key == "ss": _ss.append(value) elif key == "sr": _sr.append(value) elif key == "sl": _sl.append(value) elif key == "sm": _sm.append(value) elif key == "ra": _ra.append(value) elif key == "rs": _rs.append(value) elif key == "rr": _rr.append(value) elif key == "rl": _rl.append(value) elif key == "rm": _rm.append(value) elif key == "la": _la.append(value) elif key == "ls": _ls.append(value) elif key == "lr": _lr.append(value) elif key == "ll": _ll.append(value) elif key == "lm": _lm.append(value) elif key == "ma": _ma.append(value) elif key == "ms": _ms.append(value) elif key == "mr": _mr.append(value) elif key == "ml": _ml.append(value) elif key == "mm": _mm.append(value) plot_overlapping_vertices(_aa, output, metric, "Following and Following") plot_overlapping_vertices(_as, output, metric, "Following and Followers") plot_overlapping_vertices(_ar, output, metric, "Following and Retweets") plot_overlapping_vertices(_al, output, metric, "Following and Likes") plot_overlapping_vertices(_am, output, metric, "Following and Mentions") plot_overlapping_vertices(_sa, output, metric, "Followers and Following") plot_overlapping_vertices(_ss, output, metric, "Followers and Followers") plot_overlapping_vertices(_sr, output, metric, "Followers and Retweets") plot_overlapping_vertices(_sl, output, metric, "Followers and Likes") plot_overlapping_vertices(_sm, output, metric, "Followers and Mentions") plot_overlapping_vertices(_ra, output, metric, "Retweets and Following") plot_overlapping_vertices(_rs, output, metric, "Retweets and Followers") plot_overlapping_vertices(_rr, output, metric, "Retweets and Retweets") plot_overlapping_vertices(_rl, output, metric, "Retweets and Likes") plot_overlapping_vertices(_rm, output, metric, "Retweets and Mentions") plot_overlapping_vertices(_la, output, metric, "Likes and Following") plot_overlapping_vertices(_ls, output, metric, "Likes and Followers") plot_overlapping_vertices(_lr, output, metric, "Likes and Retweets") plot_overlapping_vertices(_ll, output, metric, "Likes and Likes") plot_overlapping_vertices(_lm, output, metric, "Likes and Mentions") plot_overlapping_vertices(_ma, output, metric, "Mentions and Following") plot_overlapping_vertices(_ms, output, metric, "Mentions and Followers") plot_overlapping_vertices(_mr, output, metric, "Mentions and Retweets") plot_overlapping_vertices(_ml, output, metric, "Mentions and Likes") plot_overlapping_vertices(_mm, output, metric, "Mentions and Mentions")