Figure 5c Code Stats
Compute and parse metrics¶
In [1]:
Copied!
!pip install radon
!pip install radon
Collecting radon Downloading https://files.pythonhosted.org/packages/b3/30/53685bac034654656a096a87a52f5e77667b2bb8ab02bcc9ab3a844af802/radon-4.5.0-py2.py3-none-any.whl (51kB) |████████████████████████████████| 61kB 3.2MB/s Collecting mando<0.7,>=0.6 Downloading https://files.pythonhosted.org/packages/e6/cc/f6e25247c1493a654785e68cd975e479c311e99dafedd49ed17f8d300e0c/mando-0.6.4-py2.py3-none-any.whl Requirement already satisfied: future in /usr/local/lib/python3.7/dist-packages (from radon) (0.16.0) Collecting colorama>=0.4.1; python_version > "3.4" Downloading https://files.pythonhosted.org/packages/44/98/5b86278fbbf250d239ae0ecb724f8572af1c91f4a11edf4d36a206189440/colorama-0.4.4-py2.py3-none-any.whl Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from mando<0.7,>=0.6->radon) (1.15.0) Installing collected packages: mando, colorama, radon Successfully installed colorama-0.4.4 mando-0.6.4 radon-4.5.0
In [2]:
Copied!
!git clone https://github.com/almaan/stereoscope.git
!git clone https://github.com/YosefLab/scvi-tools.git
!git clone https://github.com/almaan/stereoscope.git
!git clone https://github.com/YosefLab/scvi-tools.git
Cloning into 'stereoscope'... remote: Enumerating objects: 288, done. remote: Counting objects: 100% (288/288), done. remote: Compressing objects: 100% (211/211), done. remote: Total 596 (delta 156), reused 194 (delta 74), pack-reused 308 Receiving objects: 100% (596/596), 57.61 MiB | 33.73 MiB/s, done. Resolving deltas: 100% (309/309), done. Cloning into 'scvi-tools'... remote: Enumerating objects: 370, done. remote: Counting objects: 100% (370/370), done. remote: Compressing objects: 100% (259/259), done. remote: Total 24193 (delta 219), reused 220 (delta 104), pack-reused 23823 Receiving objects: 100% (24193/24193), 148.33 MiB | 29.92 MiB/s, done. Resolving deltas: 100% (17597/17597), done.
In [3]:
Copied!
!rm stereoscope/stsc/look.py
!rm stereoscope/stsc/look.py
In [4]:
Copied!
import radon
import json
import re
import radon
import json
import re
In [5]:
Copied!
!radon cc stereoscope/stsc/ -s -a > orig_cc.txt
!radon hal stereoscope/stsc/ > orig_hal.txt
!radon raw stereoscope/stsc/ > orig_raw.txt
!radon cc stereoscope/stsc/ -s -a > orig_cc.txt
!radon hal stereoscope/stsc/ > orig_hal.txt
!radon raw stereoscope/stsc/ > orig_raw.txt
In [6]:
Copied!
!radon cc scvi-tools/scvi/external/stereoscope/ -s -a > scvi_cc.txt
!radon hal scvi-tools/scvi/external/stereoscope/ > scvi_hal.txt
!radon raw scvi-tools/scvi/external/stereoscope/ > scvi_raw.txt
!radon cc scvi-tools/scvi/external/stereoscope/ -s -a > scvi_cc.txt
!radon hal scvi-tools/scvi/external/stereoscope/ > scvi_hal.txt
!radon raw scvi-tools/scvi/external/stereoscope/ > scvi_raw.txt
In [7]:
Copied!
with open("orig_raw.txt") as f:
orig_total_sloc = 0
for line in f:
if ':' in line:
key, value = line.split(':')
value = ' '.join(value.split())
if key == " SLOC":
orig_total_sloc += int(value)
with open("scvi_raw.txt") as f:
scvi_total_sloc = 0
for line in f:
if ':' in line:
key, value = line.split(':')
value = ' '.join(value.split())
if key == " SLOC":
scvi_total_sloc += int(value)
with open("orig_raw.txt") as f:
orig_total_sloc = 0
for line in f:
if ':' in line:
key, value = line.split(':')
value = ' '.join(value.split())
if key == " SLOC":
orig_total_sloc += int(value)
with open("scvi_raw.txt") as f:
scvi_total_sloc = 0
for line in f:
if ':' in line:
key, value = line.split(':')
value = ' '.join(value.split())
if key == " SLOC":
scvi_total_sloc += int(value)
In [8]:
Copied!
with open("orig_hal.txt") as f:
orig_time = 0
orig_bugs = 0
for line in f:
key, value = line.split(':')
value = ' '.join(value.split())
if key == " time":
orig_time += float(value)
if key == " bugs":
orig_bugs += float(value)
with open("scvi_hal.txt") as f:
scvi_time = 0
scvi_bugs = 0
for line in f:
key, value = line.split(':')
value = ' '.join(value.split())
if key == " time":
scvi_time += float(value)
if key == " bugs":
scvi_bugs += float(value)
with open("orig_hal.txt") as f:
orig_time = 0
orig_bugs = 0
for line in f:
key, value = line.split(':')
value = ' '.join(value.split())
if key == " time":
orig_time += float(value)
if key == " bugs":
orig_bugs += float(value)
with open("scvi_hal.txt") as f:
scvi_time = 0
scvi_bugs = 0
for line in f:
key, value = line.split(':')
value = ' '.join(value.split())
if key == " time":
scvi_time += float(value)
if key == " bugs":
scvi_bugs += float(value)
In [9]:
Copied!
with open('orig_cc.txt') as f:
for line in f:
pass
orig_avg_complexity = line
with open('scvi_cc.txt') as f:
for line in f:
pass
scvi_avg_complexity = line
with open('orig_cc.txt') as f:
for line in f:
pass
orig_avg_complexity = line
with open('scvi_cc.txt') as f:
for line in f:
pass
scvi_avg_complexity = line
Average complexity¶
In [10]:
Copied!
print ("Original Stereoscope Implementation", orig_avg_complexity)
print ("Scvi-tools Implementation", scvi_avg_complexity)
print ("Original Stereoscope Implementation", orig_avg_complexity)
print ("Scvi-tools Implementation", scvi_avg_complexity)
Original Stereoscope Implementation Average complexity: A (2.875) Scvi-tools Implementation Average complexity: A (1.4230769230769231)
Sum of time¶
In [11]:
Copied!
print("Sum of time in original stereoscope implementation:",orig_time)
print("Sum of time in scvi-tools implementation:",scvi_time)
print("Sum of time in original stereoscope implementation:",orig_time)
print("Sum of time in scvi-tools implementation:",scvi_time)
Sum of time in original stereoscope implementation: 800.0500377165816 Sum of time in scvi-tools implementation: 54.3024615601502
Sum of bugs¶
In [12]:
Copied!
print("Sum of bugs in original stereoscope implementation:",orig_bugs)
print("Sum of bugs in scvi-tools implementation:",scvi_bugs)
print("Sum of bugs in original stereoscope implementation:",orig_bugs)
print("Sum of bugs in scvi-tools implementation:",scvi_bugs)
Sum of bugs in original stereoscope implementation: 0.7669894669699762 Sum of bugs in scvi-tools implementation: 0.08709522640708889
Source lines of code¶
In [13]:
Copied!
print ("Sum of SLOC in original stereoscope implementation:", orig_total_sloc)
print ("Sum of SLOC in scvi-tools implementation:", scvi_total_sloc)
print ("Sum of SLOC in original stereoscope implementation:", orig_total_sloc)
print ("Sum of SLOC in scvi-tools implementation:", scvi_total_sloc)
Sum of SLOC in original stereoscope implementation: 1400 Sum of SLOC in scvi-tools implementation: 291
Plot¶
In [63]:
Copied!
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams["svg.fonttype"] = "none"
plt.rcParams["pdf.fonttype"] = 42
plt.rcParams["savefig.transparent"] = True
sns.set_theme(style="whitegrid")
df = pd.DataFrame(index=["scvi-tools", "original"], columns=["Complexity", "Halstead Time", "Halstead Bugs", "Source Lines"])
df.loc["scvi-tools", "Complexity"] = float(scvi_avg_complexity.split("(")[1].split(")")[0])
df.loc["original", "Complexity"] = float(orig_avg_complexity.split("(")[1].split(")")[0])
df.loc["scvi-tools", "Halstead Time"] = scvi_time
df.loc["original", "Halstead Time"] = orig_time
df.loc["scvi-tools", "Halstead Bugs"] = scvi_bugs
df.loc["original", "Halstead Bugs"] = orig_bugs
df.loc["scvi-tools", "Source Lines"] = scvi_total_sloc
df.loc["original", "Source Lines"] = orig_total_sloc
df["Implementation"] = df.index.to_list()
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams["svg.fonttype"] = "none"
plt.rcParams["pdf.fonttype"] = 42
plt.rcParams["savefig.transparent"] = True
sns.set_theme(style="whitegrid")
df = pd.DataFrame(index=["scvi-tools", "original"], columns=["Complexity", "Halstead Time", "Halstead Bugs", "Source Lines"])
df.loc["scvi-tools", "Complexity"] = float(scvi_avg_complexity.split("(")[1].split(")")[0])
df.loc["original", "Complexity"] = float(orig_avg_complexity.split("(")[1].split(")")[0])
df.loc["scvi-tools", "Halstead Time"] = scvi_time
df.loc["original", "Halstead Time"] = orig_time
df.loc["scvi-tools", "Halstead Bugs"] = scvi_bugs
df.loc["original", "Halstead Bugs"] = orig_bugs
df.loc["scvi-tools", "Source Lines"] = scvi_total_sloc
df.loc["original", "Source Lines"] = orig_total_sloc
df["Implementation"] = df.index.to_list()
In [64]:
Copied!
df
df
Out[64]:
Complexity | Halstead Time | Halstead Bugs | Source Lines | Implementation | |
---|---|---|---|---|---|
scvi-tools | 1.42308 | 54.3025 | 0.0870952 | 291 | scvi-tools |
original | 2.875 | 800.05 | 0.766989 | 1400 | original |
In [65]:
Copied!
# Make the PairGrid
g = sns.PairGrid(df,
x_vars=["Complexity", "Halstead Time", "Halstead Bugs", "Source Lines"],
y_vars=["Implementation"],
height=2, aspect=1.5)
# Draw a dot plot using the stripplot function
g.map(sns.stripplot, size=10, orient="h", jitter=False,
palette="flare_r", linewidth=1, edgecolor="w")
# Use the same x axis limits on all columns and add better labels
# g.set(xlim=(0, 25), xlabel="Crashes", ylabel="")
# # Use semantically meaningful titles for the columns
titles = df.columns
xlims = [(1, 3), (30, 900), (0, 1), (0, 1500)]
for ax, title, xlim in zip(g.axes.flat, titles, xlims):
# Set a different title for each axes
ax.set(title=title)
ax.set_xlim(xlim)
# Make the grid horizontal instead of vertical
ax.xaxis.grid(False)
ax.yaxis.grid(True)
sns.despine(left=True, bottom=True)
plt.savefig("code_stats.pdf", bbox_inches="tight")
# Make the PairGrid
g = sns.PairGrid(df,
x_vars=["Complexity", "Halstead Time", "Halstead Bugs", "Source Lines"],
y_vars=["Implementation"],
height=2, aspect=1.5)
# Draw a dot plot using the stripplot function
g.map(sns.stripplot, size=10, orient="h", jitter=False,
palette="flare_r", linewidth=1, edgecolor="w")
# Use the same x axis limits on all columns and add better labels
# g.set(xlim=(0, 25), xlabel="Crashes", ylabel="")
# # Use semantically meaningful titles for the columns
titles = df.columns
xlims = [(1, 3), (30, 900), (0, 1), (0, 1500)]
for ax, title, xlim in zip(g.axes.flat, titles, xlims):
# Set a different title for each axes
ax.set(title=title)
ax.set_xlim(xlim)
# Make the grid horizontal instead of vertical
ax.xaxis.grid(False)
ax.yaxis.grid(True)
sns.despine(left=True, bottom=True)
plt.savefig("code_stats.pdf", bbox_inches="tight")
In [53]:
Copied!