{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from pymongo import MongoClient\n", "import pandas as pd\n", "import json\n", "from bson.json_util import dumps\n", "from pandas.io.json import json_normalize" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "ip = '127.0.0.1'\n", "port = 27017\n", "client = MongoClient(ip, port)\n", "db = client['Vulnerabilities']\n", "vulnerabilities = db['Vulnerabilities']" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def getLayerAndSubsystem():\n", " return vulnerabilities.aggregate([\n", "\n", " { \"$match\" : {\"high-level\":{\"$ne\":\"Unclear\"} }},\n", " { \"$group\": {\n", " \"_id\": {\n", " \"layer\": \"$high-level\",\n", " \"subsystem\": \"$subsystem\"\n", " },\n", " \"value\": { \"$sum\": 1 }\n", " }},\n", " {\"$sort\":{\"_id.layer\":1}}\n", " ])" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": true }, "outputs": [], "source": [ "MongoResponse = getLayerAndSubsystem()\n", "dataFromMongoResponse = json.loads(dumps(MongoResponse))" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": true }, "outputs": [], "source": [ "myList = []\n", "for element in dataFromMongoResponse:\n", " myList.append([\"Android Subsystems.\"+element[\"_id\"][\"layer\"].encode(\"utf-8\")+\".\"+element[\"_id\"][\"subsystem\"].replace(\",\", \" \").replace(\".\", \" \").encode(\"utf-8\"),element[\"value\"]])" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": true }, "outputs": [], "source": [ "df = pd.DataFrame(myList, columns=['id','value'])" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": true }, "outputs": [], "source": [ "df = df[~df['id'].str.contains(\",\")]" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Dataframe created and appended due visualizations reasons\n", "dataTemp = {'id': ['Android Subsystems', 'Android Subsystems.HAL', 'Android Subsystems.Native Libraries', 'Android Subsystems.Android Framework', 'Android Subsystems.Kernel', 'Android Subsystems.Application', 'Android Subsystems.Android Runtime'], 'value': ['','','','','','','']}\n", "dfTemp = pd.DataFrame(data=dataTemp)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": true }, "outputs": [], "source": [ "df = df.append(dfTemp, ignore_index=True)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": true }, "outputs": [], "source": [ "df.to_csv(path_or_buf=\"sabsvEMSE.csv\", index=False)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.3" } }, "nbformat": 4, "nbformat_minor": 2 }