| ")
@@ -11,14 +14,40 @@ def array2markdown_table(string):
string = string.replace("\n", "")
return string
+def write_table_of_contents():
+ lines = []
-wList = getGenList()
-lines = []
-with open('mathgenerator/mathgen.py', 'r') as f:
- lines = f.readlines()
+ tc_lines = [
+ '* [Installation](#installation)\n',
+ '* [Basic Usage](#basic-usage)\n',
+ ' * [More Complicated Usage](#more-complicated-usage)\n'
+ '* [Documentation](#documentation)\n',
+ '* [List of Generators](#list-of-generators)\n',
+ ]
+ for subject in subjects:
+ line = ' * [' + subject + '](#' + subject + ')\n'
+ tc_lines.append(line)
-allRows = []
-for item in wList:
+ with open('README.md', "r") as g:
+ lines = g.readlines()
+
+ upper_bound = lines.index('## Table of Contents\n')
+ upper_lines = lines[:upper_bound + 1]
+ lower_bound = lines.index('## Installation\n')
+ lower_lines = lines[lower_bound - 1:]
+ lines = []
+
+ for upper_line in upper_lines:
+ lines.append(upper_line)
+ for tc_line in tc_lines:
+ lines.append(tc_line)
+ for lower_line in lower_lines:
+ lines.append(lower_line)
+
+ with open('README.md', "w") as g:
+ g.writelines(lines)
+
+def gen_to_row_string(item):
myGen = item[2]
# NOTE: renamed 'sol' to 'solu' to make it look nicer
prob, solu = myGen()
@@ -35,21 +64,54 @@ 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
-with open('README.md', "r") as g:
- lines = g.readlines()
+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)
- line = lines.index('|------|-------|-----------------|------------------|---------------|\n')
- lines = lines[:line + 1]
+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()
- for row in allRows:
- tableLine = "| " + str(row[0]) + " | " + str(row[1]) + " | " + str(
- row[2]) + " | " + str(row[3]) + " | " + str(row[4]) + " |\n"
- lines.append(tableLine)
+ # Create table header
+ make_table_header(subject_name)
-with open('README.md', "w") as g:
- g.writelines(lines)
+ # Add each item to write_list
+ for item in subject_list:
+ write_list.append(gen_to_row_string(item))
-print("New README.md table generated")
+
+def main():
+ write_table_of_contents()
+ for subject in subjects:
+ write_subject_table(subject, wList)
+
+ with open('README.md', "r") as g:
+ lines = g.readlines()
+
+ line = lines.index('## List of Generators\n')
+ lines = lines[:line + 1]
+
+ for write_line in write_list:
+ lines.append(write_line)
+
+ with open('README.md', "w") as g:
+ g.writelines(lines)
+
+ print("New README.md table generated")
+
+if __name__ == "__main__":
+ main()
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..f3bb678 100644
--- a/mathgenerator/funcs/algebra/intersection_of_two_lines.py
+++ b/mathgenerator/funcs/algebra/intersection_of_two_lines.py
@@ -1,5 +1,7 @@
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..0a6581e 100644
--- a/mathgenerator/funcs/algebra/quadratic_equation.py
+++ b/mathgenerator/funcs/algebra/quadratic_equation.py
@@ -1,5 +1,7 @@
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..273f236 100644
--- a/mathgenerator/funcs/computer_science/nth_fibonacci_number.py
+++ b/mathgenerator/funcs/computer_science/nth_fibonacci_number.py
@@ -1,5 +1,7 @@
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)
|