-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
87 lines (69 loc) · 2.63 KB
/
plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
import click
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from sqlalchemy import func
from db import database
from db.pin import Pin
VALID_PLOTS = {
'PINS_VS_PROCESS',
'PINS_VS_YEAR',
'VCC_VS_GND_DIST',
'VCC_VS_GND',
}
VALID_PLOTS_STR = ', '.join(VALID_PLOTS)
@click.command()
@click.option(
'-n',
'--name',
type=str,
help='Which plot to show, case insensitive. '
f'Valid options are:\n{VALID_PLOTS_STR}')
def plot(name: str):
name = name.upper()
if name.upper() not in VALID_PLOTS:
raise KeyError(
f"Invalid plot name '{name}'. Try one of: {VALID_PLOTS_STR}")
manager = database.DbManager()
session = manager.open_session()
if name == 'PINS_VS_PROCESS':
query = session.query(Pin.family, Pin.part, func.count(Pin.pin_id),
Pin.process).group_by(Pin.part)
df = pd.read_sql_query(query.statement, session.bind)
ax = sns.swarmplot(x="process", y="count_1", data=df)
ax.set_xlabel('Process Node [nm]')
ax.set_ylabel('Pin Count [#]')
if name == 'PINS_VS_YEAR':
query = session.query(Pin.family, Pin.part, func.count(Pin.pin_id),
Pin.year).group_by(Pin.part)
df = pd.read_sql_query(query.statement, session.bind)
ax = sns.swarmplot(x="year", y="count_1", data=df)
ax.set_xlabel('Year')
ax.set_ylabel('Pin Count [#]')
if name == 'VCC_VS_GND_DIST':
query = session.query(Pin.family, Pin.part, Pin.pin_type, func.count(
Pin.pin_id)) \
.filter(Pin.pin_type.in_(['VCC', 'GND'])) \
.group_by(Pin.part, Pin.pin_type)
df = pd.read_sql_query(query.statement, session.bind)
# You can probably do this in SQL but I wasn't sure how to do that
df['ratio'] = df.count_1 / df.count_1.shift(1)
ax = sns.distplot(df[df['pin_type'] == 'VCC']['ratio'])
ax.set_xlabel('(# of VCC Pins) / (# of GND Pins)')
ax.set_yticks([])
if name == 'VCC_VS_GND':
query = session.query(Pin.family, Pin.part, Pin.pin_type, func.count(
Pin.pin_id)) \
.filter(Pin.pin_type.in_(['VCC', 'GND'])) \
.group_by(Pin.part, Pin.pin_type)
df = pd.read_sql_query(query.statement, session.bind)
ax = sns.scatterplot(
x=df[df['pin_type'] == 'VCC']['count_1'].values,
y=df[df['pin_type'] == 'GND']['count_1'].values)
ax.set_xlabel('# of VCC Pins')
ax.set_ylabel('# of GND Pins')
session.close()
plt.show()
if __name__ == '__main__':
plot()