Skip to content

Instantly share code, notes, and snippets.

@ymirpl
Created June 2, 2013 15:43
Show Gist options
  • Save ymirpl/5693889 to your computer and use it in GitHub Desktop.
Save ymirpl/5693889 to your computer and use it in GitHub Desktop.
# coding: utf8
import re
from collections import defaultdict
NO_MPLS_NO_GAL = "/Volumes/Data/ymir/Dropbox/mgr/dla_ens/res/pre_results/no_mpls_no_gal/General-0.sca"
GAL_NO_MPLS = "/Volumes/Data/ymir/Dropbox/mgr/dla_ens/res/pre_results/gal_no_mpls/General-0.sca"
GAL_MPLS = "/Volumes/Data/ymir/Dropbox/mgr/dla_ens/res/pre_results/gal_mpls/General-0.sca"
def make_latex_table(title_row=['a', 'b'], cols=2, data=[], caption="opis", id="tab"):
# flatten data
if type(data) in (dict, defaultdict):
data = [list(i) for i in data.items()]
cc = "|".join(["c" for i in xrange(cols)])
cc += "|"
preamble = "% \n \\begin{table}[!htb] \n \small \n \centering \n \\begin{tabular}{|" + cc + "} \hline \n"
header_row = "%s \\\\ \hline \n" % (" & ".join(title_row))
postamble = "\end{tabular} \n \caption{" + caption + "} \n \label{tab:" + id + "} \n \end{table} \n %"
print preamble, header_row
for l in data:
print "%s \\\\ \hline \n" % (" & ".join([str(el) for el in l]))
print postamble
def file_one(filename=NO_MPLS_NO_GAL):
""" Compute how many packets send """
send_p = defaultdict(int)
with open(filename, 'r') as f:
for l in f.readlines():
m = re.match(r'scalar BIG.(host[\d]+).udpApp\[[\d+]+\]\s+sentPk:count\s+(\d+)', l)
# print m
if m:
send_p[m.group(1)] += int(m.group(2))
if filename == NO_MPLS_NO_GAL:
make_latex_table(title_row=['Host', u'Liczba pakietów wysłanych'], data=send_p, caption="Liczba pakietów wysłanych (bez MPLS, bez GAL)")
if filename == GAL_NO_MPLS:
make_latex_table(title_row=['Host', u'Liczba pakietów wysłanych'], data=send_p, caption="Liczba pakietów wysłanych (bez MPLS, GAL)")
if filename == GAL_MPLS:
make_latex_table(title_row=['Host', u'Liczba pakietów wysłanych'], data=send_p, caption="Liczba pakietów wysłanych (MPLS, GAL)")
if __name__ == '__main__':
file_one(NO_MPLS_NO_GAL)
file_one(GAL_NO_MPLS)
file_one(GAL_MPLS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment