Created
November 7, 2015 17:02
-
-
Save dandye/f93f965ffd13228d6348 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"lib/p/s/t/attack_pattern.py\n", | |
"manage.py\n" | |
] | |
} | |
], | |
"source": [ | |
"def compress_name(instr):\n", | |
" a = compress_name_a(instr)\n", | |
" b = compress_name_b(instr)\n", | |
" if not a:\n", | |
" print a\n", | |
" if len(a) > len(\"+----------------------------------------------+\")-5:\n", | |
" return b\n", | |
" else:\n", | |
" return a\n", | |
" \n", | |
"def compress_filename(instr):\n", | |
" if len(instr) > len(\"observable_object_type_definition.py\")-5:\n", | |
" return instr[0:6] + \"...\" + instr[-4:]\n", | |
" else:\n", | |
" return instr\n", | |
"\n", | |
"def compress_name_b(instr):\n", | |
" if len(instr) > len(\"lib/p/c/b/_account_object.py\"):\n", | |
" return instr.split(\"/\")[0] + \"/.../\" + compress_filename(instr.split(\"/\")[-1])\n", | |
" else:\n", | |
" return instr\n", | |
" \n", | |
"def compress_name_a(instr):\n", | |
" if instr.count(\"/\") > 0:\n", | |
" outstr = []\n", | |
" parts = instr.split(\"/\")\n", | |
" if len(parts) > 2:\n", | |
" cln = [parts[0],]\n", | |
" cln.extend([apart[0] for apart in parts[1:-1]])\n", | |
" cln.extend([parts[-1],])\n", | |
" return \"/\".join(cln)\n", | |
" else:\n", | |
" return instr\n", | |
"\n", | |
"def read_coverage_report(filename):\n", | |
" lines = open(filename).readlines()\n", | |
" data = []\n", | |
" cols = lines[0].split()\n", | |
" print cols\n", | |
" for aline in lines[1:-1]:\n", | |
" if \"---\" in aline: # skip line break decorations\n", | |
" continue \n", | |
" data.append({col: val for (col,val) in zip(cols,aline.split()) })\n", | |
" return cols, data\n", | |
" \n", | |
" \n", | |
"print compress_name(\"lib/python-stix/stix/ttp/attack_pattern.py\")\n", | |
"print compress_name(\"manage.py\")\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"['Name', 'Stmts', 'Miss', 'Cover']\n", | |
"['Name', 'Stmts', 'Miss', 'Cover']\n", | |
"+--------+--------+--------+-------+-------+-------+------+--------+--------+------------------------------------------------+\n", | |
"| StmtsA | StmtsB | StmtsD | MissA | MissB | MissD | CvrA | CoverB | CoverD | Name |\n", | |
"+--------+--------+--------+-------+-------+-------+------+--------+--------+------------------------------------------------+\n", | |
"| 16 | 15 | -1 | 12 | 0 | -12 | 25% | 100% | 75 | dev/unittest_bootstrap.py |\n", | |
"| 252 | 252 | 0 | 76 | 63 | -13 | 70% | 75% | 5 | edge/campaign.py |\n", | |
"| 301 | 301 | 0 | 148 | 149 | 1 | 51% | 50% | -1 | edge/indicator.py |\n", | |
"| 70 | 70 | 0 | 39 | 27 | -12 | 44% | 61% | 17 | edge/stixbase.py |\n", | |
"| 37 | 40 | 3 | 17 | 19 | 2 | 54% | 53% | -1 | edge/test_common.py |\n", | |
"| 118 | 104 | -14 | 112 | 12 | -100 | 5% | 88% | 83 | edge/tests/test_campaigns.py |\n", | |
"| 46 | 46 | 0 | 43 | 31 | -12 | 7% | 33% | 26 | edge/tests/test_incidents.py |\n", | |
"| 94 | 94 | 0 | 59 | 62 | 3 | 37% | 34% | -3 | edge/tests/test_indicators.py |\n", | |
"| 48 | 48 | 0 | 45 | 32 | -13 | 6% | 33% | 27 | edge/tests/test_observables.py |\n", | |
"| 41 | 38 | -3 | 37 | 15 | -22 | 10% | 61% | 51 | edge/tests/test_stix_packages.py |\n", | |
"| 246 | 160 | -86 | 206 | 116 | -90 | 16% | 28% | 12 | homepage/views.py |\n", | |
"| 626 | 626 | 0 | 456 | 432 | -24 | 27% | 31% | 4 | lib/python-stix/stix/bindings/campaign.py |\n", | |
"| 3118 | 3118 | 0 | 2268 | 2260 | -8 | 27% | 28% | 1 | lib/python-stix/stix/bindings/stix_common.py |\n", | |
"| 319 | 319 | 0 | 99 | 39 | -60 | 69% | 88% | 19 | lib/python-stix/stix/campaign/__init__.py |\n", | |
"| 109 | 109 | 0 | 77 | 30 | -47 | 29% | 72% | 43 | lib/python-stix/stix/common/statement.py |\n", | |
"| 42 | 42 | 0 | 16 | 7 | -9 | 62% | 83% | 21 | lib/python-stix/stix/common/structured_text.py |\n", | |
"| 650 | 650 | 0 | 65 | 29 | -36 | 90% | 96% | 6 | lib/python-stix/stix/common/vocabs.py |\n", | |
"| 48 | 50 | 2 | 7 | 8 | 1 | 85% | 84% | -1 | reporting/models.py |\n", | |
"| 51 | 52 | 1 | 46 | 30 | -16 | 10% | 42% | 32 | taxii/tests/test_taxii_client.py |\n", | |
"| 25 | 25 | 0 | 22 | 14 | -8 | 12% | 44% | 32 | tools/test_validate_TAXII_output.py |\n", | |
"| 74 | 75 | 1 | 6 | 0 | -6 | 92% | 100% | 8 | ttp/test_ttp.py |\n", | |
"+--------+--------+--------+-------+-------+-------+------+--------+--------+------------------------------------------------+\n" | |
] | |
} | |
], | |
"source": [ | |
"from prettytable import PrettyTable\n", | |
"\n", | |
"def coverage_report(file_a, file_b):\n", | |
" \n", | |
" cols, data_a = read_coverage_report(file_a)\n", | |
" _, data_b = read_coverage_report(file_b)\n", | |
" \n", | |
" pt = PrettyTable([\n", | |
" \"StmtsA\", \"StmtsB\", \"StmtsD\", \n", | |
" \"MissA\", \"MissB\", \"MissD\", \n", | |
" \"CvrA\", \"CoverB\", \"CoverD\",\n", | |
" \"Name\", ])\n", | |
" pt.align[\"Name\"] = \"l\" # Left align city names\n", | |
" pt.padding_width = 1 # One space between column edges and contents (default)\n", | |
" for i,data_a_row in enumerate(data_a):\n", | |
" #print data_a\n", | |
" data_b_row = data_b[i]\n", | |
" try:\n", | |
" if int(data_a_row[\"Stmts\"]) == 0 and int(data_b_row[\"Stmts\"]) == 0:\n", | |
" continue\n", | |
" if int(data_b_row[\"Cover\"][:-1]) - int(data_a_row[\"Cover\"][:-1]) == 0:\n", | |
" continue\n", | |
" #assert(compress_name(data_a_row[\"Name\"]) != None)\n", | |
" except:\n", | |
" print i\n", | |
" print data_a_row\n", | |
" print data_b_row\n", | |
" pt.add_row([ \n", | |
" data_a_row[\"Stmts\"], data_b_row[\"Stmts\"], \n", | |
" int(data_b_row[\"Stmts\"]) - int(data_a_row[\"Stmts\"]),\n", | |
" data_a_row[\"Miss\"], data_b_row[\"Miss\"], \n", | |
" int(data_b_row[\"Miss\"]) - int(data_a_row[\"Miss\"]),\n", | |
" data_a_row[\"Cover\"], data_b_row[\"Cover\"], \n", | |
" int(data_b_row[\"Cover\"][:-1]) - int(data_a_row[\"Cover\"][:-1]),\n", | |
" data_a_row[\"Name\"], \n", | |
" #compress_name(data_a_row[\"Name\"]), \n", | |
" ])\n", | |
" return pt\n", | |
"\n", | |
"print coverage_report(\n", | |
"\"/home/ddye/coverage_report_B470-date-parse-error_cb7617.txt\", \n", | |
"\"/home/ddye/coverage_report_development_dc9eff1.txt\"\n", | |
")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"-rw-r--r-- 1 ddye users 45410 Nov 6 18:20 /home/ddye/coverage_report_dc9eff1afd086b94ddcffdcb2422ada3f13a5b87.txt\r\n", | |
"-rw-r--r-- 1 ddye users 45410 Nov 6 18:21 /home/ddye/coverage_report_e653e6f0bc80cacda9120c7d94f19147b89ae565.txt\r\n", | |
"-rw-r--r-- 1 ddye users 45410 Nov 6 20:10 /home/ddye/coverage_report_B470-date-parse-error_cb7617.txt\r\n", | |
"-rw-r--r-- 1 ddye users 45410 Nov 6 20:11 /home/ddye/coverage_report_development_dc9eff1.txt\r\n" | |
] | |
} | |
], | |
"source": [ | |
"!ls -ltr /home/ddye/coverage*" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.8" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment