Skip to content

Commit f530c2d

Browse files
committed
update imports for python3 support
1 parent 52c570f commit f530c2d

File tree

2 files changed

+110
-110
lines changed

2 files changed

+110
-110
lines changed

gre2gmat/conversions.py

Lines changed: 106 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,107 @@
1+
from __future__ import absolute_import
12
import warnings
2-
from data_table import score_table
3-
from constants import MAX_GRE, MIN_GRE, BAD_INPUT_RETURN, MIN_GMAT, MAX_GMAT
4-
5-
6-
def _validate_score_input(v,q):
7-
try:
8-
verbal = int(v)
9-
except:
10-
warnings.warn("Was not able to parse verbal score: {}\nReturning {}".format(v,BAD_INPUT_RETURN))
11-
return BAD_INPUT_RETURN,BAD_INPUT_RETURN
12-
try:
13-
quant = int(q)
14-
except:
15-
warnings.warn("Was not able to parse quant score: {}\nReturning {}".format(q,BAD_INPUT_RETURN))
16-
return BAD_INPUT_RETURN, BAD_INPUT_RETURN
17-
18-
if verbal > MAX_GRE or verbal < MIN_GRE:
19-
warnings.warn("Verbal score of {} is not between {} and {}\nReturning {}".format(verbal,MIN_GRE,MAX_GRE,BAD_INPUT_RETURN))
20-
return BAD_INPUT_RETURN, BAD_INPUT_RETURN
21-
22-
if quant > MAX_GRE or quant < MIN_GRE:
23-
warnings.warn("Quant score of {} is not between {} and {}\nReturning {}".format(quant,MIN_GRE,MAX_GRE,BAD_INPUT_RETURN))
24-
return BAD_INPUT_RETURN, BAD_INPUT_RETURN
25-
26-
return verbal, quant
27-
28-
def gre2gmat(gre_verbal,gre_quant):
29-
"""
30-
:param gre_verbal: Numeric representation of verbal GRE score
31-
:type verbal: int
32-
33-
:param gre_quant: Numeric representation of quantitative GRE score
34-
:type quant: int
35-
36-
:return: Predicted GMAT score
37-
:rtype: int
38-
"""
39-
v,q = _validate_score_input(gre_verbal,gre_quant)
40-
if v == BAD_INPUT_RETURN or q == BAD_INPUT_RETURN:
41-
gmat = BAD_INPUT_RETURN
42-
else:
43-
try:
44-
gmat = score_table.loc[q,v]
45-
except KeyError:
46-
gmat = rough_gre2gmat(gre_verbal=v,gre_quant=q)
47-
48-
return gmat
49-
50-
51-
def rough_gre2gmat(gre_verbal,gre_quant):
52-
"""
53-
An equation for computing GMAT equivalent taken from:
54-
https://www.mbacrystalball.com/blog/2014/01/23/gre-to-gmat-score-conversion/
55-
56-
:param gre_verbal: Numeric representation of verbal GRE score
57-
:type verbal: int
58-
59-
:param gre_quant: Numeric representation of quantitative GRE score
60-
:type quant: int
61-
62-
:return: Predicted GMAT score
63-
:rtype: int
64-
"""
65-
66-
v,q = _validate_score_input(gre_verbal,gre_quant)
67-
if v == BAD_INPUT_RETURN or q == BAD_INPUT_RETURN:
68-
gmat = BAD_INPUT_RETURN
69-
else:
70-
gmat = -2080.75 + (6.38 * v) + (10.62 * q)
71-
if gmat >= MAX_GMAT:
72-
gmat = MAX_GMAT
73-
elif gmat <= MIN_GMAT:
74-
gmat = MIN_GMAT
75-
76-
return int(round(gmat,-1))
77-
def rougher_gre2gmat(gre_verbal,gre_quant):
78-
"""
79-
A terrible approximation for gmat score. Derived with love by yours truly
80-
:param gre_verbal: Numeric representation of verbal GRE score
81-
:type verbal: int
82-
83-
:param gre_quant: Numeric representation of quantitative GRE score
84-
:type quant: int
85-
86-
:return: Predicted GMAT score
87-
:rtype: int
88-
"""
89-
warnings.warn("\nThis function is inappropriately inaccurate.")
90-
v,q = _validate_score_input(gre_verbal,gre_quant)
91-
if v == BAD_INPUT_RETURN or q == BAD_INPUT_RETURN:
92-
gmat = BAD_INPUT_RETURN
93-
else:
94-
gmat = (v+q)*2.019
95-
96-
if gmat >= MAX_GMAT:
97-
gmat = MAX_GMAT
98-
elif gmat <= MIN_GMAT:
99-
gmat = MIN_GMAT
100-
101-
return int(round(gmat,-1))
102-
103-
104-
105-
106-
3+
from .data_table import score_table
4+
from .constants import MAX_GRE, MIN_GRE, BAD_INPUT_RETURN, MIN_GMAT, MAX_GMAT
5+
6+
7+
def _validate_score_input(v, q):
8+
try:
9+
verbal = int(v)
10+
except:
11+
warnings.warn("Was not able to parse verbal score: {}\nReturning {}".format(v, BAD_INPUT_RETURN))
12+
return BAD_INPUT_RETURN, BAD_INPUT_RETURN
13+
try:
14+
quant = int(q)
15+
except:
16+
warnings.warn("Was not able to parse quant score: {}\nReturning {}".format(q, BAD_INPUT_RETURN))
17+
return BAD_INPUT_RETURN, BAD_INPUT_RETURN
18+
19+
if verbal > MAX_GRE or verbal < MIN_GRE:
20+
warnings.warn("Verbal score of {} is not between {} and {}\nReturning {}".format(
21+
verbal, MIN_GRE, MAX_GRE, BAD_INPUT_RETURN))
22+
return BAD_INPUT_RETURN, BAD_INPUT_RETURN
23+
24+
if quant > MAX_GRE or quant < MIN_GRE:
25+
warnings.warn("Quant score of {} is not between {} and {}\nReturning {}".format(
26+
quant, MIN_GRE, MAX_GRE, BAD_INPUT_RETURN))
27+
return BAD_INPUT_RETURN, BAD_INPUT_RETURN
28+
29+
return verbal, quant
30+
31+
32+
def gre2gmat(gre_verbal, gre_quant):
33+
"""
34+
:param gre_verbal: Numeric representation of verbal GRE score
35+
:type verbal: int
36+
37+
:param gre_quant: Numeric representation of quantitative GRE score
38+
:type quant: int
39+
40+
:return: Predicted GMAT score
41+
:rtype: int
42+
"""
43+
v, q = _validate_score_input(gre_verbal, gre_quant)
44+
if v == BAD_INPUT_RETURN or q == BAD_INPUT_RETURN:
45+
gmat = BAD_INPUT_RETURN
46+
else:
47+
try:
48+
gmat = score_table.loc[q, v]
49+
except KeyError:
50+
gmat = rough_gre2gmat(gre_verbal=v, gre_quant=q)
51+
52+
return gmat
53+
54+
55+
def rough_gre2gmat(gre_verbal, gre_quant):
56+
"""
57+
An equation for computing GMAT equivalent taken from:
58+
https://www.mbacrystalball.com/blog/2014/01/23/gre-to-gmat-score-conversion/
59+
60+
:param gre_verbal: Numeric representation of verbal GRE score
61+
:type verbal: int
62+
63+
:param gre_quant: Numeric representation of quantitative GRE score
64+
:type quant: int
65+
66+
:return: Predicted GMAT score
67+
:rtype: int
68+
"""
69+
70+
v, q = _validate_score_input(gre_verbal, gre_quant)
71+
if v == BAD_INPUT_RETURN or q == BAD_INPUT_RETURN:
72+
gmat = BAD_INPUT_RETURN
73+
else:
74+
gmat = -2080.75 + (6.38 * v) + (10.62 * q)
75+
if gmat >= MAX_GMAT:
76+
gmat = MAX_GMAT
77+
elif gmat <= MIN_GMAT:
78+
gmat = MIN_GMAT
79+
80+
return int(round(gmat, -1))
81+
82+
83+
def rougher_gre2gmat(gre_verbal, gre_quant):
84+
"""
85+
A terrible approximation for gmat score. Derived with love by yours truly
86+
:param gre_verbal: Numeric representation of verbal GRE score
87+
:type verbal: int
88+
89+
:param gre_quant: Numeric representation of quantitative GRE score
90+
:type quant: int
91+
92+
:return: Predicted GMAT score
93+
:rtype: int
94+
"""
95+
warnings.warn("\nThis function is inappropriately inaccurate.")
96+
v, q = _validate_score_input(gre_verbal, gre_quant)
97+
if v == BAD_INPUT_RETURN or q == BAD_INPUT_RETURN:
98+
gmat = BAD_INPUT_RETURN
99+
else:
100+
gmat = (v + q) * 2.019
101+
102+
if gmat >= MAX_GMAT:
103+
gmat = MAX_GMAT
104+
elif gmat <= MIN_GMAT:
105+
gmat = MIN_GMAT
106+
107+
return int(round(gmat, -1))

gre2gmat/data_table.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
"""
99
TABLE_FILE_NAME = 'data_table.csv'
1010

11-
print os.path.dirname(__file__)
12-
fullpath = os.path.join(os.path.dirname(__file__),TABLE_FILE_NAME)
13-
score_table = pd.read_csv(fullpath,index_col=0)
11+
fullpath = os.path.join(os.path.dirname(__file__), TABLE_FILE_NAME)
12+
score_table = pd.read_csv(fullpath, index_col=0)
1413
score_table.columns = [int(c) for c in score_table.columns]
1514

1615
"""
@@ -24,8 +23,8 @@
2423
# one40 = [200,220,240,260,280,300,320,340,360,390,410,430,450,470,490,510,530,560,580,600,620]
2524
# one42 = [210,230,250,270,290,310,330,360,380,400,420,440,460,480,500,530,550,570,590,610,630]
2625
# one44 = [220,240,260,280,300,330,350,370,390,410,430,450,470,500,520,540,560,580,600,620,640]
27-
# one46 = [230,250,270,300,320,340,360,380,400,420,440,470,490,510,530,550,570,590,610,640,660]
28-
# one48 = [250,270,290,310,330,350,370,390,420,440,460,480,500,520,540,560,580,610,630,650,670]
26+
# one46 = [230,250,270,300,320,340,360,380,400,420,440,470,490,510,530,550,570,590,610,640,660]
27+
# one48 = [250,270,290,310,330,350,370,390,420,440,460,480,500,520,540,560,580,610,630,650,670]
2928
# one50 = [260,280,300,320,340,360,390,410,430,450,470,490,510,530,560,580,600,620,640,660,680]
3029
# one52 = [270,290,310,330,360,380,400,420,440,460,480,500,530,550,570,590,610,630,650,670,700]
3130
# one54 = [280,300,330,350,370,390,410,430,450,470,500,520,540,560,580,600,620,640,670,690,710]

0 commit comments

Comments
 (0)