How to use keyNames method in fMBT

Best Python code snippet using fMBT_python

paper_ploter.py

Source:paper_ploter.py Github

copy

Full Screen

1# Jing-Kai Lou (kaeaura@gamil.com)2import os3import sys4sys.path.append('analyzer')5import matplotlib.pylab as plt6from db import LiteDB7def load_data(path, file_dict):8 all_dbs = os.listdir(path)9 assert(set(all_filenames.values()).issubset(set(all_dbs)))10 db = LiteDB()11 all_keynames = {}12 read_keynames = set()13 for read_tracename, read_filename in all_filenames.iteritems():14 db.load(os.path.join(path, read_filename))15 read_keyname = set(db.keys()).difference(read_keynames).pop()16 all_keynames.__setitem__(read_tracename, read_keyname)17 read_keynames.add(read_keyname)18 return(db, all_keynames)19def plot_frac(db, keynames, save_path):20 inFrac_name = 'inFrac_dict'21 outFrac_name = 'outFrac_dict'22 plt.clf()23 plt.figure(figsize = (8, 5))24 x_upperbound = .225 plt.subplot(2, 2, 1)26 plt.plot(map(lambda x: x / 1000.0, db[keynames['mog']][inFrac_name].keys()), db[keynames['mog']][inFrac_name].values(), 'b-', lw = 5, label = 'fairyland')27 plt.plot(map(lambda x: x / 1000.0, db[keynames['mblg']][inFrac_name].keys()), db[keynames['mblg']][inFrac_name].values(), 'r:', lw = 5, label = 'twitter')28 plt.plot(map(lambda x: x / 1000.0, db[keynames['im']][inFrac_name].keys()), db[keynames['im']][inFrac_name].values(), 'k--', lw = 5, label = 'yahoo')29 plt.xlim(xmax = x_upperbound)30 plt.ylabel('wcc fraction (id)')31 plt.title('interaction')32 plt.grid(True)33 plt.legend(('fairyland', 'twitter', 'yahoo'), loc = 'best', prop = {'size':10})34 plt.subplot(2, 2, 2)35 plt.plot(map(lambda x: x / 1000.0, db[keynames['mogF']][inFrac_name].keys()), db[keynames['mogF']][inFrac_name].values(), 'b-', lw = 5, label = 'fairyland')36 plt.plot(map(lambda x: x / 1000.0, db[keynames['mblgF']][inFrac_name].keys()), db[keynames['mblgF']][inFrac_name].values(), 'r:', lw = 5, label = 'twitter')37 plt.plot(map(lambda x: x / 1000.0, db[keynames['imF']][inFrac_name].keys()), db[keynames['imF']][inFrac_name].values(), 'k--', lw = 5, label = 'yahoo')38 plt.xlim(xmax = x_upperbound)39 plt.title('ally')40 plt.grid(True)41 #plt.legend(('fairyland', 'twitter', 'yahoo'), loc = 'best')42 plt.subplot(2, 2, 3)43 plt.plot(map(lambda x: x / 1000.0, db[keynames['mog']][outFrac_name].keys()), db[keynames['mog']][outFrac_name].values(), 'b-', lw = 5, label = 'fairyland')44 plt.plot(map(lambda x: x / 1000.0, db[keynames['mblg']][outFrac_name].keys()), db[keynames['mblg']][outFrac_name].values(), 'r:', lw = 5, label = 'twitter')45 plt.plot(map(lambda x: x / 1000.0, db[keynames['im']][outFrac_name].keys()), db[keynames['im']][outFrac_name].values(), 'k--', lw = 5, label = 'yahoo')46 plt.xlim(xmax = x_upperbound)47 plt.xlabel('removed fraction by od (%)')48 plt.ylabel('wc fraction (od)')49 plt.grid(True)50 plt.subplot(2, 2, 4)51 plt.plot(map(lambda x: x / 1000.0, db[keynames['mogF']][outFrac_name].keys()), db[keynames['mogF']][outFrac_name].values(), 'b-', lw = 5, label = 'fairyland')52 plt.plot(map(lambda x: x / 1000.0, db[keynames['mblgF']][outFrac_name].keys()), db[keynames['mblgF']][outFrac_name].values(), 'r:', lw = 5, label = 'twitter')53 plt.plot(map(lambda x: x / 1000.0, db[keynames['imF']][outFrac_name].keys()), db[keynames['imF']][outFrac_name].values(), 'k--', lw = 5, label = 'yahoo')54 plt.xlim(xmax = x_upperbound)55 plt.xlabel('removed fraction (%)')56 plt.grid(True)57 plt.savefig(os.path.join(save_dir, save_path))58def plot_degreeRate(db, keynames, save_path):59 degRate_x_name = 'degRateDistr_x'60 degRate_y_name = 'degRateDistr_y'61 plt.clf()62 plt.figure(figsize = (8, 5))63 plt.subplot(1, 2, 1)64 plt.plot(db[keynames['mog']][degRate_x_name], db[keynames['mog']][degRate_y_name], 'b-', lw=5, label = 'fairyland')65 plt.plot(db[keynames['mblg']][degRate_x_name], db[keynames['mblg']][degRate_y_name], 'r:', lw=5, label = 'twitter')66 plt.plot(db[keynames['im']][degRate_x_name], db[keynames['im']][degRate_y_name], 'k--', lw=5, label = 'yahoo')67 plt.xscale('log')68 plt.grid(True)69 plt.title('interaction')70 plt.legend(('fairyland', 'twitter', 'yahoo'), loc = 4, prop = {'size': 10})71 plt.xlabel('In-degree to Out-degree Ratio')72 plt.ylabel('CDF')73 plt.subplot(1, 2, 2)74 plt.plot(db[keynames['mogF']][degRate_x_name], db[keynames['mogF']][degRate_y_name], 'b-', lw=5, label = 'fairyland')75 plt.plot(db[keynames['mblgF']][degRate_x_name], db[keynames['mblgF']][degRate_y_name], 'r:', lw=5, label = 'twitter')76 #plt.plot(db[keynames['imF']][degRate_x_name], db[keynames['imF']][degRate_y_name], 'k--', lw=5, label = 'yahoo')77 plt.xscale('log')78 plt.grid(True)79 plt.title('ally')80 plt.xlabel('In-degree to Out-degree Ratio')81 plt.ylabel('CDF')82 plt.savefig(os.path.join(save_dir, save_path))83def plot_degreeOverlap(db, keynames, save_path, attr_name = 'degOverlapRatio'):84 plt.clf()85 plt.figure(figsize = (8, 5))86 x = sorted(db[keynames['mog']][attr_name].keys())87 y = [db[keynames['mog']][attr_name][xx] for xx in x]88 plt.plot(x, y, 'b-', lw = 5, label = 'fairyland interaction')89 x = sorted(db[keynames['mblg']][attr_name].keys())90 y = [db[keynames['mblg']][attr_name][xx] for xx in x]91 plt.plot(x, y, 'r:', lw = 5, label = 'twitter interaction')92 x = sorted(db[keynames['im']][attr_name].keys())93 y = [db[keynames['im']][attr_name][xx] for xx in x]94 plt.plot(x, y, 'k--', lw = 5, label = 'yahoo interaction')95 x = sorted(db[keynames['mogF']][attr_name].keys())96 y = [db[keynames['mogF']][attr_name][xx] for xx in x]97 plt.plot(x, y, 'b.', label = 'fairyland ally')98 x = sorted(db[keynames['mblgF']][attr_name].keys())99 y = [db[keynames['mblgF']][attr_name][xx] for xx in x]100 plt.plot(x, y, 'k*', label = 'twitter ally')101 plt.grid(True)102 plt.title('Overlap')103 plt.xlabel('Fraction of Users ordered by degree (%)')104 plt.ylabel('Overlap (%)')105 plt.legend(('fairyland interaction', 'twitter interaction', 'yahoo interaction', 'fairyland ally', 'twitter ally'), loc = 'best')106 plt.savefig(os.path.join(save_dir, save_path))107def plot_degreeDistr(db, keynames, save_path):108 indeg_x_name = 'inDegDistr_x'109 indeg_y_name = 'inDegDistr_y'110 outdeg_x_name = 'outDegDistr_x'111 outdeg_y_name = 'outDegDistr_y'112 deg_x_name = 'degDistr_x'113 deg_y_name = 'degDistr_y'114 x_upperbound = 10 ** 5115 y_lowerbound = 10 ** -6116 plt.clf()117 plt.figure(figsize = (8, 5))118 plt.subplot(2, 3, 1)119 plt.loglog(db[keynames['mog']][indeg_x_name], db[keynames['mog']][indeg_y_name], 'b-', linewidth=5, label='id')120 plt.loglog(db[keynames['mog']][outdeg_x_name], db[keynames['mog']][outdeg_y_name], 'r--', linewidth=5, label='od')121 #plt.loglog(db[keynames['mogF']][indeg_x_name], db[keynames['mogF']][indeg_y_name], 'r--', linewidth=5, label='ally')122 plt.ylabel('interaction CCDF')123 plt.grid(True)124 plt.xlim(xmax = x_upperbound)125 plt.ylim(ymin = y_lowerbound)126 plt.title('Fairyland Online')127 plt.legend(('id', 'od'), loc = 3, prop = {'size': 7})128 plt.subplot(2, 3, 2)129 plt.loglog(db[keynames['mblg']][indeg_x_name], db[keynames['mblg']][indeg_y_name], 'b-', linewidth=5, label='id')130 plt.loglog(db[keynames['mblg']][outdeg_x_name], db[keynames['mblg']][outdeg_y_name], 'r--', linewidth=5, label='od')131 #plt.loglog(db[keynames['mblgF']][indeg_x_name], db[keynames['mblgF']][indeg_y_name], 'r--', linewidth=5, label='ally')132 plt.grid(True)133 plt.xlim(xmax = x_upperbound)134 plt.ylim(ymin = y_lowerbound)135 plt.title('Twitter')136 plt.subplot(2, 3, 3)137 plt.loglog(db[keynames['im']][indeg_x_name], db[keynames['im']][indeg_y_name], 'b-', linewidth=5, label='id')138 plt.loglog(db[keynames['im']][outdeg_x_name], db[keynames['im']][outdeg_y_name], 'r--', linewidth=5, label='od')139 #plt.loglog(db[keynames['imF']][indeg_x_name], db[keynames['imF']][indeg_y_name], 'r--', linewidth=5, label='ally')140 plt.xlabel('k')141 plt.grid(True)142 plt.xlim(xmax = x_upperbound)143 plt.ylim(ymin = y_lowerbound)144 plt.title('Yahoo! Messenger')145 plt.subplot(2, 3, 4)146 plt.loglog(db[keynames['mogF']][indeg_x_name], db[keynames['mogF']][indeg_y_name], 'b-', linewidth=5, label='id')147 plt.loglog(db[keynames['mogF']][outdeg_x_name], db[keynames['mogF']][outdeg_y_name], 'r--', linewidth=5, label='od')148 #plt.loglog(db[keynames['mogF']][outdeg_x_name], db[keynames['mogF']][outdeg_y_name], 'r--', linewidth=5, label='ally')149 plt.xlabel('k')150 plt.ylabel('ally CCDF')151 plt.grid(True)152 plt.xlim(xmax = x_upperbound)153 plt.ylim(ymin = y_lowerbound)154 plt.subplot(2, 3, 5)155 plt.loglog(db[keynames['mblgF']][indeg_x_name], db[keynames['mblgF']][indeg_y_name], 'b-', linewidth=5, label='id')156 plt.loglog(db[keynames['mblgF']][outdeg_x_name], db[keynames['mblgF']][outdeg_y_name], 'r--', linewidth=5, label='od')157 #plt.loglog(db[keynames['mblgF']][outdeg_x_name], db[keynames['mblgF']][outdeg_y_name], 'r--', linewidth=5, label='ally')158 plt.xlabel('k')159 plt.grid(True)160 plt.xlim(xmax = x_upperbound)161 plt.ylim(ymin = y_lowerbound)162 plt.subplot(2, 3, 6)163 plt.loglog(db[keynames['imF']][deg_x_name], db[keynames['imF']][deg_y_name], 'k-', linewidth=5, label='d')164 #plt.loglog(db[keynames['imF']][indeg_x_name], db[keynames['imF']][indeg_y_name], 'b-', linewidth=5, label='id')165 #plt.loglog(db[keynames['imF']][outdeg_x_name], db[keynames['imF']][outdeg_y_name], 'r--', linewidth=5, label='od')166 #plt.loglog(db[keynames['imF']][outdeg_x_name], db[keynames['imF']][outdeg_y_name], 'r--', linewidth=5, label='ally')167 plt.xlabel('k')168 plt.grid(True)169 plt.xlim(xmax = x_upperbound)170 plt.ylim(ymin = y_lowerbound)171 plt.legend(('d'), loc = 'best', prop = {'size':7})172 plt.savefig(os.path.join(save_dir, save_path))173def plot_reusage(db, keynames, save_path, attr_name = [ 'linkWeightDistr_x', 'linkWeightDistr_y' ]):174 plt.clf()175 plt.figure(figsize = (8, 5))176 plt.loglog(db[keynames['mog']][attr_name[0]], db[keynames['mog']][attr_name[1]], 'b-', lw = 5, label = 'fariyland')177 plt.loglog(db[keynames['mblg']][attr_name[0]], db[keynames['mblg']][attr_name[1]], 'r:', lw = 5, label = 'twitter')178 plt.loglog(db[keynames['im']][attr_name[0]], db[keynames['im']][attr_name[1]], 'k--', lw = 5, label = 'yahoo')179 plt.xlabel('Usage (days)')180 plt.ylabel('CCDF')181 plt.title('Usage of Links')182 plt.grid(True)183 plt.legend(('fairyland', 'twitter', 'yahoo'), loc = 'best')184 plt.savefig(os.path.join(save_dir, save_path))185# knn via degree bin ####186def plot_KnnDistr(db, keynames, save_path):187 knnMean_x_name = 'knnDistr_avg_x'188 knnMean_y_name = 'knnDistr_avg_y'189 knnMedian_x_name = 'knnDistr_median_x'190 knnMedian_y_name = 'knnDistr_median_y'191 inKnnMean_x_name = 'inKnnDistr_avg_x'192 inKnnMean_y_name = 'inKnnDistr_avg_y'193 inKnnMedian_x_name = 'inKnnDistr_median_x'194 inKnnMedian_y_name = 'inKnnDistr_median_y'195 outKnnMean_x_name = 'outKnnDistr_avg_x'196 outKnnMean_y_name = 'outKnnDistr_avg_y'197 outKnnMedian_x_name = 'outKnnDistr_median_x'198 outKnnMedian_y_name = 'outKnnDistr_median_y'199 x_upperbound = 10 ** 5200 x_lowerbound = 10 ** 0201 y_upperbound = 10 ** 4202 y_lowerbound = 10 ** -1203 plt.clf()204 plt.figure(figsize = (8, 8))205 plt.subplot(2, 2, 1)206 plt.loglog(db[keynames['mog']][inKnnMean_x_name], db[keynames['mog']][inKnnMean_y_name], 'b.', mec='b', ms=5, label='fairyland')207 plt.loglog(db[keynames['mblg']][inKnnMean_x_name], db[keynames['mblg']][inKnnMean_y_name], 'r+', mec='r', mfc='None', ms=5, label='twitter')208 plt.loglog(db[keynames['im']][inKnnMean_x_name], db[keynames['im']][inKnnMean_y_name], 'k>', mec='k', mfc='None', ms=5, label='yahoo')209 plt.xlim((x_lowerbound, x_upperbound))210 plt.ylim((y_lowerbound, y_upperbound))211 plt.title('interaction')212 plt.ylabel('$<k_{nn}>^{in}$')213 plt.grid(True)214 plt.legend(('fairyland', 'twitter', 'yahoo'), loc = 'best', prop = {'size': 10})215 plt.subplot(2, 2, 2)216 plt.loglog(db[keynames['mogF']][inKnnMean_x_name], db[keynames['mogF']][inKnnMean_y_name], 'b.', mec='b', ms=5, label='fairyland')217 plt.loglog(db[keynames['mblgF']][inKnnMean_x_name], db[keynames['mblgF']][inKnnMean_y_name], 'r+', mec='r', mfc='None', ms=5, label='twitter')218 plt.loglog(db[keynames['imF']][knnMean_x_name], db[keynames['imF']][knnMean_y_name], 'k>', mec='k', mfc='None', ms=5, label='yahoo')219 plt.xlim((x_lowerbound, x_upperbound))220 plt.ylim((y_lowerbound, y_upperbound))221 plt.title('ally')222 plt.grid(True)223 plt.subplot(2, 2, 3)224 plt.loglog(db[keynames['mog']][outKnnMean_x_name], db[keynames['mog']][outKnnMean_y_name], 'b.', mec='b', ms=5, label='fairyland')225 plt.loglog(db[keynames['mblg']][outKnnMean_x_name], db[keynames['mblg']][outKnnMean_y_name], 'r+', mec='r', mfc='None', ms=5, label='twitter')226 plt.loglog(db[keynames['im']][outKnnMean_x_name], db[keynames['im']][outKnnMean_y_name], 'k>', mec='k', mfc='None', ms=5, label='yahoo')227 plt.xlim((x_lowerbound, x_upperbound))228 plt.ylim((y_lowerbound, y_upperbound))229 plt.title('interaction')230 plt.xlabel('$k$')231 plt.ylabel('$<k_{nn}>^{out}$')232 plt.grid(True)233 plt.subplot(2, 2, 4)234 plt.loglog(db[keynames['mogF']][outKnnMean_x_name], db[keynames['mogF']][outKnnMean_y_name], 'b.', mec='b', ms=5, label='fairyland')235 #plt.loglog(db[keynames['mogF']][outKnnMedian_x_name], db[keynames['mogF']][outKnnMedian_y_name], 'g--', label='fairyland-median')236 plt.loglog(db[keynames['mblgF']][outKnnMean_x_name], db[keynames['mblgF']][outKnnMean_y_name], 'r+', mec='r', mfc='None', ms=5, label='twitter')237 #plt.loglog(db[keynames['mblgF']][outKnnMedian_x_name], db[keynames['mblgF']][outKnnMedian_y_name], 'y--', label='twitter-median')238 plt.loglog(db[keynames['imF']][knnMean_x_name], db[keynames['imF']][knnMean_y_name], 'k>', mec='k', mfc='None', ms=5, label='yahoo')239 #plt.loglog(db[keynames['imF']][knnMedian_x_name], db[keynames['imF']][knnMedian_y_name], 'c--', ms=5, label='yahoo')240 plt.xlim((x_lowerbound, x_upperbound))241 plt.ylim((y_lowerbound, y_upperbound))242 plt.title('ally')243 plt.xlabel('$k$')244 plt.grid(True)245 plt.savefig(os.path.join(save_dir, save_path))246# clustering ####247def plot_clustDistr(db, keynames, save_path):248 cluMean_x_name = 'ccDistr_avg_x'249 cluMean_y_name = 'ccDistr_avg_y'250 cluMedian_x_name = 'ccDistr_median_x'251 cluMedian_y_name = 'ccDistr_median_y'252 x_upperbound = 10 ** 4253 y_upperbound = .4254 y_lowerbound = 10 ** -5255 plt.clf()256 plt.figure(figsize = (8, 5))257 plt.subplot(1, 2, 1)258 plt.loglog(db[keynames['mog']][cluMean_x_name], db[keynames['mog']][cluMean_y_name], 'b.', mec='b', ms=5, label='fairyland')259 plt.loglog(db[keynames['mblg']][cluMean_x_name], db[keynames['mblg']][cluMean_y_name], 'r+', mec='r', mfc='None', ms=5, label='twitter')260 plt.loglog(db[keynames['im']][cluMean_x_name], db[keynames['im']][cluMean_y_name], 'k>', mec='k', mfc='None', ms=5, label='yahoo')261 plt.title('interaction')262 plt.xlabel('$k$')263 plt.ylabel('cc')264 plt.grid(True)265 plt.legend(('fairyland', 'twitter', 'yahoo'), loc = 'best', prop = {'size': 10})266 plt.xlim(xmax = x_upperbound)267 plt.ylim(ymax = y_upperbound, ymin = y_lowerbound)268 plt.subplot(1, 2, 2)269 plt.loglog(db[keynames['mogF']][cluMean_x_name], db[keynames['mogF']][cluMean_y_name], 'b.', mec='b', ms=5, label='fairyland')270 plt.loglog(db[keynames['mblgF']][cluMean_x_name], db[keynames['mblgF']][cluMean_y_name], 'r+', mec='r', mfc='None', ms=5, label='twitter')271 plt.loglog(db[keynames['imF']][cluMean_x_name], db[keynames['imF']][cluMean_y_name], 'k>', mec='k', mfc='None', ms=5, label='yahoo')272 plt.title('ally')273 plt.xlabel('$k$')274 plt.grid(True)275 plt.xlim(xmax = x_upperbound)276 plt.ylim(ymax = y_upperbound, ymin = y_lowerbound)277 plt.savefig(os.path.join(save_dir, save_path))278def plot_dist(db, keynames, save_path):279 """plot the sample path distance (in number of hops)"""280 diam_name = 'diameter'281 dist_name = 'hop_counts'282 plt.clf()283 plt.figure(figsize = (8, 5))284 plt.subplot(1, 2, 1)285 x = db[keynames['mog']][dist_name].keys()286 y = db[keynames['mog']][dist_name].values()287 ySum = float(sum(y))288 y = map(lambda z: z / ySum, y)289 plt.plot(x, y, 'b-', lw = 3, label = 'fairyland')290 x = db[keynames['mblg']][dist_name].keys()291 y = db[keynames['mblg']][dist_name].values()292 ySum = float(sum(y))293 y = map(lambda z: z / ySum, y)294 plt.plot(x, y, 'r:', lw = 3, label = 'twitter')295 x = db[keynames['im']][dist_name].keys()296 y = db[keynames['im']][dist_name].values()297 ySum = float(sum(y))298 y = map(lambda z: z / ySum, y)299 plt.plot(x, y, 'k--', lw = 3, label = 'yahoo')300 plt.title('interaction')301 plt.grid(True)302 plt.xlabel('hop number')303 plt.ylabel('probability')304 plt.legend(('fairyland', 'twitter', 'yahoo'), loc = 'best')305 plt.xlim((0, 15))306 plt.ylim((0, .7))307 plt.subplot(1, 2, 2)308 x = db[keynames['mogF']][dist_name].keys()309 y = db[keynames['mogF']][dist_name].values()310 ySum = float(sum(y))311 y = map(lambda z: z / ySum, y)312 plt.plot(x, y, 'b-', lw = 3, label = 'fairyland')313 plt.title('ally')314 plt.grid(True)315 plt.xlabel('hop number')316 plt.legend(('fairyland', 'twitter', 'yahoo'), loc = 'best')317 plt.xlim((0, 15))318 plt.ylim((0, .7))319 plt.savefig(os.path.join(save_dir, save_path))320def plot_prefAttach(db, keynames, save_path):321 """docstring for plot_pref"""322 pa_name = 'pref_attach'323 import numpy as np324 from scipy.optimize import leastsq325 degree = 2326 observation_length = 200327 fit_length = 200328 plt.clf()329 plt.figure(figsize = (9, 7))330 y_upperbound = 4 * 10 ** 6331 y_lowerbound = 0332 x_upperbound = observation_length333 mSize = 5334 335 x = sorted(db[keynames['mog']][pa_name].keys())336 y = []337 for k in x:338 y.append(db[keynames['mog']][pa_name][k])339 if len(x) >= observation_length:340 x = x[:observation_length]341 y = y[:observation_length]342 A = np.vander(x[:fit_length], degree + 1)343 coef, residual, rank, sing_vals = np.linalg.lstsq(A, y[:fit_length])344 f = np.poly1d(coef)345 y_est = f(x)346 plt.plot(x, y, 'b.', label = 'fairyland', ms = mSize)347 plt.plot(x, y_est, 'b-', lw = 2, label = 'fairyland-fitness')348 x = sorted(db[keynames['mblg']][pa_name].keys())349 y = []350 for k in x:351 y.append(db[keynames['mblg']][pa_name][k])352 if len(x) >= observation_length:353 x = x[:observation_length]354 y = y[:observation_length]355 A = np.vander(x[:fit_length], degree + 1)356 coef, residual, rank, sing_vals = np.linalg.lstsq(A, y[:fit_length])357 f = np.poly1d(coef)358 y_est = f(x)359 plt.plot(x, y, 'r+', label = 'twitter', ms = mSize)360 plt.plot(x, y_est, 'r-', lw = 2, label = 'twitter-fitness')361 x = sorted(db[keynames['im']][pa_name].keys())362 y = []363 for k in x:364 y.append(db[keynames['im']][pa_name][k])365 if len(x) >= observation_length:366 x = x[:observation_length]367 y = y[:observation_length]368 A = np.vander(x[:fit_length], degree + 1)369 coef, residual, rank, sing_vals = np.linalg.lstsq(A, y[:fit_length])370 f = np.poly1d(coef)371 y_est = f(x)372 plt.plot(x, y, 'k>', mfc='None', mec='k', label = 'yahoo', ms = mSize)373 plt.plot(x, y_est, 'k--', lw = 2, label = 'yahoo-fitness')374 plt.xlim(xmax = x_upperbound)375 plt.ylim(ymax = y_upperbound, ymin = y_lowerbound)376 #plt.grid(True)377 plt.xlabel('k')378 plt.ylabel('$R_k$')379 plt.legend(('fairyland', 'fairyland-fitness', 'twitter', 'twitter-fitness', 'yahoo', 'yahoo-fitness'), loc = 2, ncol = 2, prop = {'size': 12})380 plt.savefig(os.path.join(save_dir, save_path))381def plot_clustProb(db, keynames, save_path, attr_name = 'cluster_prob'):382 """docstring for plot_pref"""383 import numpy as np384 degree = 2385 observation_length = 200386 fit_length = 200387 plt.clf()388 plt.figure(figsize = (9, 7))389 y_upperbound = 4 * 10 ** 8390 y_lowerbound = 0391 x_upperbound = observation_length392 mSize = 5393 394 x = sorted(db[keynames['mog']][attr_name].keys())395 y = []396 for k in x:397 y.append(db[keynames['mog']][attr_name][k])398 if len(x) >= observation_length:399 x = x[:observation_length]400 y = y[:observation_length]401 A = np.vander(x[:fit_length], degree + 1)402 coef, residual, rank, sing_vals = np.linalg.lstsq(A, y[:fit_length])403 f = np.poly1d(coef)404 y_est = f(x)405 plt.plot(x, y, 'b.', label = 'fairyland', ms = mSize)406 plt.plot(x, y_est, 'b-', lw = 2, label = 'fairyland-fitness')407 x = sorted(db[keynames['mblg']][attr_name].keys())408 y = []409 for k in x:410 y.append(db[keynames['mblg']][attr_name][k])411 if len(x) >= observation_length:412 x = x[:observation_length]413 y = y[:observation_length]414 A = np.vander(x[:fit_length], degree + 1)415 coef, residual, rank, sing_vals = np.linalg.lstsq(A, y[:fit_length])416 f = np.poly1d(coef)417 y_est = f(x)418 plt.plot(x, y, 'r+', label = 'twitter', ms = mSize)419 plt.plot(x, y_est, 'r-', lw = 2, label = 'twitter-fitness')420 x = sorted(db[keynames['im']][attr_name].keys())421 y = []422 for k in x:423 y.append(db[keynames['im']][attr_name][k])424 if len(x) >= observation_length:425 x = x[:observation_length]426 y = y[:observation_length]427 A = np.vander(x[:fit_length], degree + 1)428 coef, residual, rank, sing_vals = np.linalg.lstsq(A, y[:fit_length])429 f = np.poly1d(coef)430 y_est = f(x)431 plt.plot(x, y, 'k>', mfc='None', mec='k', label = 'yahoo', ms = mSize)432 plt.plot(x, y_est, 'k--', lw = 2, label = 'yahoo-fitness')433 plt.xlim(xmax = x_upperbound)434 plt.ylim(ymax = y_upperbound, ymin = y_lowerbound)435 #plt.grid(True)436 plt.xlabel('k')437 plt.ylabel('$R_k$')438 plt.legend(('fairyland', 'fairyland-fitness', 'twitter', 'twitter-fitness', 'yahoo', 'yahoo-fitness'), loc = 1, ncol = 2, prop = {'size': 12})439 plt.savefig(os.path.join(save_dir, save_path))440def plot_Knn(db, keynames, save_path, attr_names = ('knn', 'weighted_knn')):441 plt.clf()442 plt.figure(figsize = (8, 5))443 mSize = 7444 x_upperbound = 10 ** 4445 y_upperbound = 10 ** 4446 y_lowerbound = 10 ** 0447 plt.subplot(1, 2, 1)448 x = sorted(db[keynames['mog']][attr_names[0]].keys())449 y = [db[keynames['mog']][attr_names[0]][k] for k in x]450 plt.loglog(x, y, 'b.', mec = 'b', label = 'fairyland', ms = mSize)451 x = sorted(db[keynames['mblg']][attr_names[0]].keys())452 y = [db[keynames['mblg']][attr_names[0]][k] for k in x]453 plt.loglog(x, y, 'r+', label = 'twitter', ms = mSize)454 x = sorted(db[keynames['im']][attr_names[0]].keys())455 y = [db[keynames['im']][attr_names[0]][k] for k in x]456 plt.loglog(x, y, 'k>', mfc='None', label = 'yahoo', ms = mSize)457 #plt.yscale('log')458 plt.legend(('fairyland', 'twitter', 'yahoo'), loc = 'best')459 plt.title('interaction')460 plt.xlabel('$k$')461 plt.ylabel('$K_{nn}$')462 plt.xlim(xmax = x_upperbound)463 plt.ylim(ymax = y_upperbound, ymin = y_lowerbound)464 plt.grid(True)465 plt.subplot(1, 2, 2)466 x = sorted(db[keynames['mogF']][attr_names[0]].keys())467 y = [db[keynames['mogF']][attr_names[0]][k] for k in x]468 plt.loglog(x, y, 'b.', mec = 'b', label = 'fairyland', ms = mSize)469 x = sorted(db[keynames['mblgF']][attr_names[0]].keys())470 y = [db[keynames['mblgF']][attr_names[0]][k] for k in x]471 plt.loglog(x, y, 'r+', label = 'twitter', ms = mSize)472 x = sorted(db[keynames['imF']][attr_names[0]].keys())473 y = [db[keynames['imF']][attr_names[0]][k] for k in x]474 plt.loglog(x, y, 'k>', mfc='None', label = 'yahoo', ms = mSize)475 plt.title('ally')476 #plt.yscale('log')477 plt.xlabel('$k$')478 plt.xlim(xmax = x_upperbound)479 plt.ylim(ymax = y_upperbound, ymin = y_lowerbound)480 plt.grid(True)481 plt.savefig(os.path.join(save_dir, save_path))482def plot_closureProb(db, keynames, save_path, attr_name):483 plt.clf()484 plt.figure(figsize = (9, 7))485 mSize = 7486 487 x = sorted(db[keynames['mog']][attr_name].keys())488 y = []489 for k in x:490 y.append(db[keynames['mog']][attr_name][k])491 ySum = float(sum(y))492 y = map(lambda z: z / ySum, y)493 plt.plot(x, y, 'bo-', label = 'fairyland', ms = mSize)494 x = sorted(db[keynames['mblg']][attr_name].keys())495 y = []496 for k in x:497 y.append(db[keynames['mblg']][attr_name][k])498 ySum = float(sum(y))499 y = map(lambda z: z / ySum, y)500 plt.plot(x, y, 'r+:', label = 'twitter', ms = mSize)501 x = sorted(db[keynames['im']][attr_name].keys())502 y = []503 for k in x:504 y.append(db[keynames['im']][attr_name][k])505 ySum = float(sum(y))506 y = map(lambda z: z / ySum, y)507 plt.plot(x, y, 'k>--', mfc='None', mec='k', label = 'yahoo', ms = mSize)508 plt.grid(True)509 plt.xlim(xmax = 15)510 plt.xlabel('hop count $d$')511 plt.ylabel('$P(d)$')512 plt.legend(('fairyland', 'twitter', 'yahoo'), loc = 1)513 plt.savefig(os.path.join(save_dir, save_path))514# loading and plot ##########515flag = [1]516save_dir = 'doc/interactions_over_platforms/figures'517print (flag)518if 1 in flag:519 db_path = '../exp/db/degree'520 all_filenames = {'mog':'anderson_chat_degree.db', 'mogF': 'anderson_friend_degree.db', 'mblg':'twitter_cut_degree.db', 'mblgF':'twitter_follower_degree.db', 'im': 'yahoo_chat_degree.db', 'imF':'yahoo_friend_degree.db'}521 db, all_keynames = load_data(db_path, all_filenames)522 plot_degreeRate(db, all_keynames, 'degree_rate_distribution.pdf')523 plot_degreeOverlap(db, all_keynames, 'degree_overlap.pdf')524 plot_reusage(db, all_keynames, save_path = 'link_reusage.pdf')525 plot_degreeDistr(db, all_keynames, 'degree_distribution.pdf')526if 2 in flag:527 db_path = '../exp/db/focus'528 all_filenames = {'mog':'anderson_chat.db', 'mogF': 'anderson_friend.db', 'mblg':'twitter_cut.db', 'mblgF':'twitter_follower.db', 'im': 'yahoo_chat.db', 'imF':'yahoo_friend.db'}529 db, all_keynames = load_data(db_path, all_filenames)530 #plot_degreeDistr(db, all_keynames, 'degree_distribution.pdf')531 #plot_KnnDistr(db, all_keynames, 'knn_distribution.pdf')532 plot_clustDistr(db, all_keynames, 'clust_distribution.pdf')533if 3 in flag:534 db_path = '../exp/db/knn'535 all_filenames = {'mog':'anderson_chat_knn.db', 'mogF': 'anderson_friend_knn.db', 'mblg':'twitter_cut_knn.db', 'mblgF':'twitter_follower_knn.db', 'im': 'yahoo_chat_knn.db', 'imF':'yahoo_friend_knn.db'}536 db, all_keynames = load_data(db_path, all_filenames)537 plot_Knn(db, all_keynames, save_path = 'knn_distribution.pdf')538if 4 in flag:539 db_path = '../exp/db/frac'540 all_filenames = {'mog':'anderson_chat_frac.db', 'mogF': 'anderson_friend_frac.db', 'mblg':'twitter_cut_frac.db', 'mblgF':'twitter_follower_frac.db', 'im': 'yahoo_chat_frac.db', 'imF': 'yahoo_friend_frac.db'}541 db, all_keynames = load_data(db_path, all_filenames)542 plot_frac(db, all_keynames, 'frac.pdf')543if 5 in flag:544 db_path = '../exp/db/dist'545 all_filenames = {'mog':'anderson_chat_dist.db', 'mogF': 'anderson_friend_dist.db', 'mblg':'twitter_cut_dist.db', 'im': 'yahoo_chat_dist.db'}546 db, all_keynames = load_data(db_path, all_filenames)547 plot_dist(db, all_keynames, 'dist.pdf')548if 6 in flag:549 db_path = '../exp/db/pa'550 all_filenames = {'mog': 'anderson_chat_pa.db', 'mblg':'twitter_chat_pa.db', 'im': 'yahoo_chat_pa.db'}551 db, all_keynames = load_data(db_path, all_filenames)552 plot_prefAttach(db, all_keynames, 'pref_attachment_rp.pdf')553 db_path = '../exp/db/cr'554 all_filenames = {'mog': 'anderson_chat_cr.db', 'mblg':'twitter_chat_cr.db', 'im': 'yahoo_chat_cr.db'}555 db, all_keynames = load_data(db_path, all_filenames)556 plot_clustProb(db, all_keynames, 'clust_rp.pdf') 557 db_path = '../exp/db/cd'558 all_filenames = {'mog': 'anderson_chat_cd.db', 'mblg':'twitter_chat_cd.db', 'im': 'yahoo_chat_cd.db'}559 db, all_keynames = load_data(db_path, all_filenames)...

Full Screen

Full Screen

keynames.py

Source:keynames.py Github

copy

Full Screen

1# Orca2#3# Copyright 2006-2008 Sun Microsystems Inc.4#5# This library is free software; you can redistribute it and/or6# modify it under the terms of the GNU Lesser General Public7# License as published by the Free Software Foundation; either8# version 2.1 of the License, or (at your option) any later version.9#10# This library is distributed in the hope that it will be useful,11# but WITHOUT ANY WARRANTY; without even the implied warranty of12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13# Lesser General Public License for more details.14#15# You should have received a copy of the GNU Lesser General Public16# License along with this library; if not, write to the17# Free Software Foundation, Inc., Franklin Street, Fifth Floor,18# Boston MA 02110-1301 USA.19"""Exposes a dictionary, keynames, that maps key events20into localized words."""21__id__ = "$Id$"22__version__ = "$Revision$"23__date__ = "$Date$"24__copyright__ = "Copyright (c) 2006-2008 Sun Microsystems Inc."25__license__ = "LGPL"26from . import chnames27from .orca_i18n import _28from .orca_i18n import C_29# __keynames is a dictionary where the keys represent a UTF-830# string for a keyboard key and the values represent the common31# phrase used to describe the key.32#33__keynames = {}34# Translators: this is how someone would speak the name of the shift key35#36__keynames["Shift"] = C_("keyboard", "Shift")37# Translators: this is how someone would speak the name of the alt key38#39__keynames["Alt"] = C_("keyboard", "Alt")40# Translators: this is how someone would speak the name of the control key41#42__keynames["Control"] = C_("keyboard", "Control")43# Translators: this is how someone would speak the name of the left shift key44#45__keynames["Shift_L"] = _("left shift")46# Translators: this is how someone would speak the name of the left alt key47#48__keynames["Alt_L"] = _("left alt")49# Translators: this is how someone would speak the name of the left ctrl key50#51__keynames["Control_L"] = _("left control")52# Translators: this is how someone would speak the name of the right shift key53#54__keynames["Shift_R"] = _("right shift")55# Translators: this is how someone would speak the name of the right alt key56#57__keynames["Alt_R"] = _("right alt")58# Translators: this is how someone would speak the name of the right ctrl key59#60__keynames["Control_R"] = _("right control")61# Translators: this is how someone would speak the name of the left meta key62#63__keynames["Meta_L"] = _("left meta")64# Translators: this is how someone would speak the name of the right meta key65#66__keynames["Meta_R"] = _("right meta")67# Translators: this is how someone would speak the name of the num lock key68#69__keynames["Num_Lock"] = _("num lock")70# Translators: this is how someone would speak the name of the caps lock key71#72__keynames["Caps_Lock"] = _("caps lock")73# Translators: this is how someone would speak the name of the scroll lock key74#75__keynames["Scroll_Lock"] = _("scroll lock")76# Translators: this is how someone would speak the name of the page up key77#78__keynames["Page_Up"] = _("page up")79# Translators: this is how someone would speak the name of the page up key80#81__keynames["KP_Page_Up"] = _("page up")82# Translators: this is how someone would speak the name of the page up key83#84__keynames["Prior"] = _("page up")85# Translators: this is how someone would speak the name of the page up key86#87__keynames["KP_Prior"] = _("page up")88# Translators: this is how someone would speak the name of the page down key89#90__keynames["Page_Down"] = _("page down")91# Translators: this is how someone would speak the name of the page down key92#93__keynames["KP_Page_Down"] = _("page down")94# Translators: this is how someone would speak the name of the page down key95#96__keynames["Next"] = _("page down")97# Translators: this is how someone would speak the name of the page down key98#99__keynames["KP_Next"] = _("page down")100# Translators: this is how someone would speak the name of the tab key101#102__keynames["Tab"] = _("tab")103# Translators: this is how someone would speak the name of the left tab key104#105__keynames["ISO_Left_Tab"] = _("left tab")106# Translators: this is how someone would speak the name of the F11 key107#108__keynames["SunF36"] = _("F 11")109# Translators: this is how someone would speak the name of the F12 key110#111__keynames["SunF37"] = _("F 12")112# Translators: this is the spoken word for the space character113#114__keynames["space"] = _("space")115# Translators: this is how someone would speak the name of the backspace key116#117__keynames["BackSpace"] = _("backspace")118# Translators: this is how someone would speak the name of the return key119#120__keynames["Return"] = _("return")121# Translators: this is how someone would speak the name of the enter key122#123__keynames["KP_Enter"] = _("enter")124# Translators: this is how someone would speak the name of the up arrow key125#126__keynames["Up"] = _("up")127# Translators: this is how someone would speak the name of the up arrow key128#129__keynames["KP_Up"] = _("up")130# Translators: this is how someone would speak the name of the down arrow key131#132__keynames["Down"] = _("down")133# Translators: this is how someone would speak the name of the down arrow key134#135__keynames["KP_Down"] = _("down")136# Translators: this is how someone would speak the name of the left arrow key137#138__keynames["Left"] = _("left")139# Translators: this is how someone would speak the name of the left arrow key140#141__keynames["KP_Left"] = _("left")142# Translators: this is how someone would speak the name of the right arrow key143#144__keynames["Right"] = _("right")145# Translators: this is how someone would speak the name of the right arrow key146#147__keynames["KP_Right"] = _("right")148# Translators: this is how someone would speak the name of the left super key149#150__keynames["Super_L"] = _("left super")151# Translators: this is how someone would speak the name of the right super key152#153__keynames["Super_R"] = _("right super")154# Translators: this is how someone would speak the name of the menu key155#156__keynames["Menu"] = _("menu")157# Translators: this is how someone would speak the name of the ISO shift key158#159__keynames["ISO_Level3_Shift"] = _("ISO level 3 shift")160# Translators: this is how someone would speak the name of the help key161#162__keynames["Help"] = _("help")163# Translators: this is how someone would speak the name of the multi key164#165__keynames["Multi_key"] = _("multi")166# Translators: this is how someone would speak the name of the mode switch key167#168__keynames["Mode_switch"] = _("mode switch")169# Translators: this is how someone would speak the name of the escape key170#171__keynames["Escape"] = _("escape")172# Translators: this is how someone would speak the name of the insert key173#174__keynames["Insert"] = _("insert")175# Translators: this is how someone would speak the name of the insert key176#177__keynames["KP_Insert"] = _("insert")178# Translators: this is how someone would speak the name of the delete key179#180__keynames["Delete"] = _("delete")181# Translators: this is how someone would speak the name of the delete key182#183__keynames["KP_Delete"] = _("delete")184# Translators: this is how someone would speak the name of the home key185#186__keynames["Home"] = _("home")187# Translators: this is how someone would speak the name of the home key188#189__keynames["KP_Home"] = _("home")190# Translators: this is how someone would speak the name of the end key191#192__keynames["End"] = _("end")193# Translators: this is how someone would speak the name of the end key194#195__keynames["KP_End"] = _("end")196# Translators: this is how someone would speak the name of the begin key197#198__keynames["KP_Begin"] = _("begin")199# Translators: this is how someone would speak the name of the200# non-spacing diacritical key for the grave glyph201#202__keynames["dead_grave"] = _("grave")203# Translators: this is how someone would speak the name of the204# non-spacing diacritical key for the acute glyph205#206__keynames["dead_acute"] = _("acute")207# Translators: this is how someone would speak the name of the208# non-spacing diacritical key for the circumflex glyph209#210__keynames["dead_circumflex"] = _("circumflex")211# Translators: this is how someone would speak the name of the212# non-spacing diacritical key for the tilde glyph213#214__keynames["dead_tilde"] = _("tilde")215# Translators: this is how someone would speak the name of the216# non-spacing diacritical key for the diaeresis glyph217#218__keynames["dead_diaeresis"] = _("diaeresis")219# Translators: this is how someone would speak the name of the220# non-spacing diacritical key for the ring glyph221#222__keynames["dead_abovering"] = _("ring")223# Translators: this is how someone would speak the name of the224# non-spacing diacritical key for the cedilla glyph225#226__keynames["dead_cedilla"] = _("cedilla")227# Translators: this is how someone would speak the name of the228# non-spacing diacritical key for the stroke glyph229#230__keynames["dead_stroke"] = _("stroke")231# Translators: this is how someone would speak the name of the minus key232#233__keynames["minus"] = _("minus")234# Translators: this is how someone would speak the name of the plus key235#236__keynames["plus"] = _("plus")237def getKeyName(key):238 """Given a keyboard key, return its name as people might refer to it239 in ordinary conversation.240 Arguments:241 - key: the key to get the name for242 Returns a string representing the name for the key243 """244 if isinstance(key, unicode):245 key = key.encode("UTF-8")246 try:247 return __keynames[key]248 except:249 return chnames.getCharacterName(key)250def localizeKeySequence(keys):251 """Given a sequence of keys, such as 'Shift Control A', localize the252 full sequence.253 Arguments:254 - keys: the key sequence to localize255 Returns a string representing the localized version to present to the256 user257 """258 keyList = keys.split()259 for key in keyList:260 keyName = getKeyName(key)261 try:262 key = key.encode("UTF-8")263 except UnicodeDecodeError:264 pass265 try:266 keyName = keyName.encode("UTF-8")267 except UnicodeDecodeError:268 pass269 try:270 keys = keys.replace(key, keyName)271 except UnicodeDecodeError:272 pass...

Full Screen

Full Screen

gen_keys.py

Source:gen_keys.py Github

copy

Full Screen

1import sys, os2# genereate keys.h file3f = file("src/engine/keys.h", "w")4keynames = []5for i in range(0, 512):6 keynames += ["&%d"%i]7print >>f, "#ifndef ENGINE_KEYS_H"8print >>f, "#define ENGINE_KEYS_H"9print >>f, '/* AUTO GENERATED! DO NOT EDIT MANUALLY! */'10print >>f, "enum"11print >>f, "{"12highestid = 013for line in open("scripts/SDL_keysym.h"):14 l = line.strip().split("=")15 if len(l) == 2 and "SDLK_" in line:16 key = l[0].strip().replace("SDLK_", "KEY_")17 value = int(l[1].split(",")[0].strip())18 print >>f, "\t%s = %d,"%(key, value)19 20 keynames[value] = key.replace("KEY_", "").lower()21 22 if value > highestid:23 highestid =value24print >>f, "\tKEY_MOUSE_1 = %d,"%(highestid+1); keynames[highestid+1] = "mouse1"25print >>f, "\tKEY_MOUSE_2 = %d,"%(highestid+2); keynames[highestid+2] = "mouse2"26print >>f, "\tKEY_MOUSE_3 = %d,"%(highestid+3); keynames[highestid+3] = "mouse3"27print >>f, "\tKEY_MOUSE_4 = %d,"%(highestid+4); keynames[highestid+4] = "mouse4"28print >>f, "\tKEY_MOUSE_5 = %d,"%(highestid+5); keynames[highestid+5] = "mouse5"29print >>f, "\tKEY_MOUSE_6 = %d,"%(highestid+6); keynames[highestid+6] = "mouse6"30print >>f, "\tKEY_MOUSE_7 = %d,"%(highestid+7); keynames[highestid+7] = "mouse7"31print >>f, "\tKEY_MOUSE_8 = %d,"%(highestid+8); keynames[highestid+8] = "mouse8"32print >>f, "\tKEY_MOUSE_WHEEL_UP = %d,"%(highestid+9); keynames[highestid+9] = "mousewheelup"33print >>f, "\tKEY_MOUSE_WHEEL_DOWN = %d,"%(highestid+10); keynames[highestid+10] = "mousewheeldown"34print >>f, "\tKEY_LAST,"35print >>f, "};"36print >>f, ""37print >>f, "#endif"38# generate keynames.c file39f = file("src/engine/client/keynames.h", "w")40print >>f, '/* AUTO GENERATED! DO NOT EDIT MANUALLY! */'41print >>f, ''42print >>f, '#ifndef KEYS_INCLUDE'43print >>f, '#error do not include this header!'44print >>f, '#endif'45print >>f, ''46print >>f, "#include <string.h>"47print >>f, ""48print >>f, "const char g_aaKeyStrings[512][16] ="49print >>f, "{"50for n in keynames:51 print >>f, '\t"%s",'%n52print >>f, "};"53print >>f, ""...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful