Open kevinmachstudio opened 1 year ago
Hi @kevinmachstudio. I've thought about this for a while and find it important as well. I don't want to remake it in js because then I would be abandoning current python users or would have to maintain both versions. However, I'm planning on converting the project to rust or go and compiling to webassembly so that it can be used from npm and pip with https://wasmer.io/. I'm going to begin working on it immediately and expect a working version in the next week or so.
Also, cool project! This is exactly the type of project that mathgenerator was created for, and I'd love for you to use this project and provide feedback. Thanks!
Sounds good i'm looking forward to it! Thanks and happy holidays!
hey @lukew3! Any chance you made progress on converting the project to rust / go and compiling it to webassembly?
Hey @kevinmachstudio, sorry for the wait. I was doing a lot of research into webassembly, and I don't think that it's suitable for this project at this point. I'm rewriting this package in javascript on the js2 branch. Probably going to be equivalent versions in both languages from now on. All functions from the basic_math subject are available now and I'm working on the other subjects now. It is available now as mathgenerator on npm. Basically npm install mathgenerator
and you can do something like:
import * as mathgenerator from 'mathgenerator';
console.log(mathgenerator.addition());
or
import { addition } from 'mathgenerator';
console.log(addition());
hey @lukew3 , I appreciate you rewriting it in JS, a few comments here for you to consider
convert the JS to TypeScript (although there is a temporary workaround for TypeScript projects importing this JS package https://medium.com/@steveruiz/using-a-javascript-library-without-type-declarations-in-a-typescript-project-3643490015f3)
looks like the function output contains latex, is there a way we can output non-latex for each function, perhaps pass in a boolean to return non-latex?
current output (e.g. factorial function)
[
"$8!=$",
"$40320$"
]
desired alternate output, first item is the problem without the equal sign and second item is the solution
[
"8!",
"40320"
]
or
{
"problem":"8!",
"solution": "40320"
}
convert the JS to TypeScript
In the plans. I just wanted to get this down in the easiest way possible at first. Might even try converting to AssemblyScript later, which is just Typescript but with webassembly compatible types and compilation.
looks like the function output contains latex, is there a way we can output non-latex for each function, perhaps pass in a boolean to return non-latex?
My first thought is to say you should just use <problem_string>.replace('$', '')
to remove $
from each problem/solution string. Previous versions had non-latex output only, and then tried to have both as well as just returning all variables. I thought that having both was redundant and impractical for all generators, so phased it out. From your use case, where you want to provide simply a problem and solution without included context, it seems like it might be worthwhile to maybe add a minimal non-latex output kwarg/default parameter to each generator.
just a heads up the README for the npm package is python related information
Got it. Still a WIP.
FYI, this seems like it's going to take a long time to complete this conversion. If you have any generators in particular you want completed let me know or feel free to try to write them yourself.
thanks @lukew3, I added a PR for enhancing one of the functions I'm interested in using, would love to get your thoughts https://github.com/lukew3/mathgenerator/pull/416
I have been working on a PHP/JS project lately to create math practicing tool. It was relatively strait forward to spin it up into a small web API using Render.
from flask import Flask, jsonify
import mathgenerator
import random
app = Flask(__name__)
@app.route('/')
def index():
return "Math problem generator API is online!"
@app.route('/generate/<string:gen_type>')
def generate_math_problems(gen_type):
problem_func = getattr(mathgenerator, gen_type.lower(), None)
if problem_func:
problem, solution = problem_func()
return jsonify({"problems": problem, "solutions": solution})
else:
return jsonify({"error": "Invalid generator type"}), 400
@app.route('/generate')
def generate_random_math_problems():
generators = mathgenerator.getGenList()
random_gen_type = random.choice(generators)[3]
problem_func = getattr(mathgenerator, random_gen_type.lower(), None)
if problem_func:
problem, solution = problem_func()
return jsonify({"problems": problem, "solutions": solution})
else:
return jsonify({"error": "Failed to generate random math problem"}), 500
@app.route('/availableGenerators')
def get_aviliable_generators():
generators = mathgenerator.getGenList()
generator_list = [[gen[1], gen[3], gen[4], gen[5]] for gen in generators]
return jsonify(generator_list)
if __name__ == '__main__':
app.run(debug=True)
hey @lukew3, awesome project! I discovered it through Hacker News the other day. Do you have any plans to make this project into a npm package as well? I've been building a free math user interface (https://robomath.tech) for self study students / teaching orgs and was hoping to import your math generator as a npm package to generate more variety of math worksheets. The alternative would be to use this python package inside a lambda function and call it but that would be much less ideal.
Thanks for the consideration and looking forward to hearing back.