{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import os\n", "import numpy\n", "\n", "from iplotter import C3Plotter" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "result = {}\n", "methods = []\n", "directory = \"testfiles\"\n", "videofile = \"1_still.mov\"" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def kpis(path):\n", " with open(path) as f:\n", " lines = f.readlines()\n", " \n", " # collect all values (skipping first and last line)\n", " vals = [float(line.split(\",\")[1]) for line in lines[1:-1]] \n", " \n", " return {\"max\": max(vals), \"min\": min(vals), \"avg\": numpy.average(vals)}" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [ "for _, _, files in os.walk(directory):\n", " for file in files:\n", " if file.endswith(\".csv\") and file.startswith(videofile):\n", " method_res = kpis(os.path.join(directory, file))\n", " \n", " method = file.split(\".\")[-2].split(\"_\")[1]\n", " if method not in methods:\n", " methods.append(method)\n", " \n", " bitrate = int(file.split(\".\")[-3][:-1])\n", "\n", " if bitrate not in result:\n", " result[bitrate] = {}\n", " \n", " result[bitrate][method] = method_res" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false, "scrolled": false }, "outputs": [], "source": [ "bitrates = sorted(list(result.keys()))\n", "results_by_method = {}\n", "for method in methods:\n", " results_by_method[method] = [result[bitrate][method] for bitrate in bitrates]" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plotter = C3Plotter()\n", "charts = {}\n", "\n", "for method, results in results_by_method.items():\n", " mins = [x[\"min\"] for x in results]\n", " maxs = [x[\"max\"] for x in results]\n", " avgs = [x[\"avg\"] for x in results]\n", " charts[method] = {\n", " \"data\": {\n", " \"x\": \"bitrate\",\n", " \"columns\": [\n", " [\"bitrate\", *bitrates],\n", " [method + \" min\", *mins],\n", " [method + \" max\", *maxs],\n", " [method + \" avg\", *avgs]\n", " ]\n", " },\n", " \"padding\": {\n", " \"right\": 15\n", " }\n", " }" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plotter.plot(charts[\"psnr\"])" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plotter.plot(charts[\"msssim\"])" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plotter.plot(charts[\"vifp\"])" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plotter.plot(charts[\"psnrhvsm\"])" ] } ], "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.5.1" } }, "nbformat": 4, "nbformat_minor": 1 }