| ")
@@ -12,13 +13,7 @@ def array2markdown_table(string):
return string
-wList = getGenList()
-lines = []
-with open('mathgenerator/mathgen.py', 'r') as f:
- lines = f.readlines()
-
-allRows = []
-for item in wList:
+def write_row(item):
myGen = item[2]
# NOTE: renamed 'sol' to 'solu' to make it look nicer
prob, solu = myGen()
@@ -35,8 +30,44 @@ for item in wList:
# NOTE: renamed 'def_name' to 'func_name' because it suits it more
func_name = item[3]
row = [myGen.id, myGen.title, prob, solu, func_name]
+ tableLine = "| " + str(row[0]) + " | " + str(row[1]) + " | " + str(
+ row[2]) + " | " + str(row[3]) + " | " + str(row[4]) + " |\n"
print('added', item[1], '-', func_name, 'to the README.md')
- allRows.append(row)
+ return tableLine
+
+def make_table_header(name):
+ lines = [
+ '## ' + name + '\n',
+ '| Id | Skill | Example problem | Example Solution | Function Name |\n',
+ '|------|-------|-----------------|------------------|---------------|\n'
+ ]
+ for line in lines:
+ write_list.append(line)
+
+def write_subject_table(subject_name, full_gen_list):
+ subject_list = []
+ # Create list of generators in given subject
+ for gen in full_gen_list:
+ if gen[4] == subject_name:
+ subject_list.append(gen)
+ subject_list.sort()
+
+ # Create table header
+ make_table_header(subject_name)
+
+ # Add each item to write_list
+ for item in subject_list:
+ write_list.append(write_row(item))
+
+
+wList = getGenList()
+lines = []
+with open('mathgenerator/mathgen.py', 'r') as f:
+ lines = f.readlines()
+
+subjects = ['algebra', 'basic_math', 'calculus', 'computer_science', 'geometry', 'misc', 'statistics']
+for subject in subjects:
+ write_subject_table(subject, wList)
with open('README.md', "r") as g:
lines = g.readlines()
@@ -44,10 +75,8 @@ with open('README.md', "r") as g:
line = lines.index('|------|-------|-----------------|------------------|---------------|\n')
lines = lines[:line + 1]
- for row in allRows:
- tableLine = "| " + str(row[0]) + " | " + str(row[1]) + " | " + str(
- row[2]) + " | " + str(row[3]) + " | " + str(row[4]) + " |\n"
- lines.append(tableLine)
+ for write_line in write_list:
+ lines.append(write_line)
with open('README.md', "w") as g:
g.writelines(lines)
diff --git a/mathgenerator/__init__.py b/mathgenerator/__init__.py
index b4bfb54..cb899b3 100644
--- a/mathgenerator/__init__.py
+++ b/mathgenerator/__init__.py
@@ -21,10 +21,10 @@ class Generator:
text) = traceback.extract_stack()[-2]
funcname = filename[filename.rfind('/'):].strip()
funcname = funcname[1:-3]
- groupname = filename[:filename.rfind('/')].strip()
- groupname = groupname[groupname.rfind('/'):].strip()
- groupname = groupname[1:]
- genList.append([id, title, self, funcname, groupname])
+ subjectname = filename[:filename.rfind('/')].strip()
+ subjectname = subjectname[subjectname.rfind('/'):].strip()
+ subjectname = subjectname[1:]
+ genList.append([id, title, self, funcname, subjectname])
def __str__(self):
return str(
diff --git a/mathgenerator/funcs/algebra/intersection_of_two_lines.py b/mathgenerator/funcs/algebra/intersection_of_two_lines.py
index c53f6be..a8e0f3c 100644
--- a/mathgenerator/funcs/algebra/intersection_of_two_lines.py
+++ b/mathgenerator/funcs/algebra/intersection_of_two_lines.py
@@ -1,5 +1,6 @@
from .__init__ import *
+import fractions
def intersectionOfTwoLinesFunc(minM=-10,
maxM=10,
diff --git a/mathgenerator/funcs/algebra/quadratic_equation.py b/mathgenerator/funcs/algebra/quadratic_equation.py
index 5961852..da2860f 100644
--- a/mathgenerator/funcs/algebra/quadratic_equation.py
+++ b/mathgenerator/funcs/algebra/quadratic_equation.py
@@ -1,5 +1,6 @@
from .__init__ import *
+import math
def quadraticEquation(maxVal=100):
a = random.randint(1, maxVal)
diff --git a/mathgenerator/funcs/computer_science/nth_fibonacci_number.py b/mathgenerator/funcs/computer_science/nth_fibonacci_number.py
index cfb7e8a..477ff46 100644
--- a/mathgenerator/funcs/computer_science/nth_fibonacci_number.py
+++ b/mathgenerator/funcs/computer_science/nth_fibonacci_number.py
@@ -1,5 +1,6 @@
from .__init__ import *
+import math
def nthFibonacciNumberFunc(maxN=100):
golden_ratio = (1 + math.sqrt(5)) / 2
diff --git a/mathgenerator/funcs/geometry/arc_length.py b/mathgenerator/funcs/geometry/arc_length.py
index d88090e..fdda5e8 100644
--- a/mathgenerator/funcs/geometry/arc_length.py
+++ b/mathgenerator/funcs/geometry/arc_length.py
@@ -1,5 +1,7 @@
from .__init__ import *
+import math
+
def arclengthFunc(maxRadius=49, maxAngle=359):
Radius = random.randint(1, maxRadius)
diff --git a/mathgenerator/funcs/geometry/basic_trigonometry.py b/mathgenerator/funcs/geometry/basic_trigonometry.py
index 2992034..b93365b 100644
--- a/mathgenerator/funcs/geometry/basic_trigonometry.py
+++ b/mathgenerator/funcs/geometry/basic_trigonometry.py
@@ -1,5 +1,7 @@
from .__init__ import *
+import math
+
# Handles degrees in quadrant one
def basicTrigonometryFunc(angles=[0, 30, 45, 60, 90],
diff --git a/mathgenerator/funcs/misc/complex_to_polar.py b/mathgenerator/funcs/misc/complex_to_polar.py
index ad4798d..f948253 100644
--- a/mathgenerator/funcs/misc/complex_to_polar.py
+++ b/mathgenerator/funcs/misc/complex_to_polar.py
@@ -1,5 +1,7 @@
from .__init__ import *
+import math
+
def complexToPolarFunc(minRealImaginaryNum=-20, maxRealImaginaryNum=20):
num = complex(random.randint(minRealImaginaryNum, maxRealImaginaryNum),
diff --git a/mathgenerator/funcs/misc/decimal_to_roman_numerals.py b/mathgenerator/funcs/misc/decimal_to_roman_numerals.py
index c2470dc..7616f2c 100644
--- a/mathgenerator/funcs/misc/decimal_to_roman_numerals.py
+++ b/mathgenerator/funcs/misc/decimal_to_roman_numerals.py
@@ -1,5 +1,7 @@
from .__init__ import *
+import math
+
def decimalToRomanNumeralsFunc(maxDecimal=4000):
x = random.randint(0, maxDecimal)
diff --git a/mathgenerator/funcs/misc/euclidian_norm.py b/mathgenerator/funcs/misc/euclidian_norm.py
index 017fa74..8cbcf58 100644
--- a/mathgenerator/funcs/misc/euclidian_norm.py
+++ b/mathgenerator/funcs/misc/euclidian_norm.py
@@ -1,5 +1,7 @@
from .__init__ import *
+import math
+
def euclidianNormFunc(maxEltAmt=20):
vec = [
diff --git a/mathgenerator/funcs/misc/surds_comparison.py b/mathgenerator/funcs/misc/surds_comparison.py
index 7c2825c..ec50c0e 100644
--- a/mathgenerator/funcs/misc/surds_comparison.py
+++ b/mathgenerator/funcs/misc/surds_comparison.py
@@ -1,5 +1,7 @@
from .__init__ import *
+import math
+
def surdsComparisonFunc(maxValue=100, maxRoot=10):
radicand1, radicand2 = tuple(random.sample(range(1, maxValue), 2))
diff --git a/mathgenerator/funcs/statistics/confidence_interval.py b/mathgenerator/funcs/statistics/confidence_interval.py
index e6cb161..96b2b90 100644
--- a/mathgenerator/funcs/statistics/confidence_interval.py
+++ b/mathgenerator/funcs/statistics/confidence_interval.py
@@ -1,5 +1,7 @@
from .__init__ import *
+import math
+
def confidenceIntervalFunc():
n = random.randint(20, 40)
diff --git a/mathgenerator/funcs/statistics/permutation.py b/mathgenerator/funcs/statistics/permutation.py
index 63d78a8..5341a88 100644
--- a/mathgenerator/funcs/statistics/permutation.py
+++ b/mathgenerator/funcs/statistics/permutation.py
@@ -1,5 +1,7 @@
from .__init__ import *
+import math
+
def permutationFunc(maxlength=20):
a = random.randint(10, maxlength)
|