Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mathgenerator as a npm package? #409

Open
kevinmachstudio opened this issue Dec 26, 2022 · 8 comments
Open

mathgenerator as a npm package? #409

kevinmachstudio opened this issue Dec 26, 2022 · 8 comments

Comments

@kevinmachstudio
Copy link

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.

@lukew3
Copy link
Owner

lukew3 commented Dec 27, 2022

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!

@kevinmachstudio
Copy link
Author

Sounds good i'm looking forward to it! Thanks and happy holidays!

@kevinmachstudio
Copy link
Author

hey @lukew3! Any chance you made progress on converting the project to rust / go and compiling it to webassembly?

@lukew3
Copy link
Owner

lukew3 commented Jan 11, 2023

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());

@kevinmachstudio
Copy link
Author

kevinmachstudio commented Jan 12, 2023

hey @lukew3 , I appreciate you rewriting it in JS, a few comments here for you to consider

  1. 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)

  2. 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"
}
  1. just a heads up the README for the npm package is python related information

@lukew3
Copy link
Owner

lukew3 commented Jan 12, 2023

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.

@kevinmachstudio
Copy link
Author

thanks @lukew3, I added a PR for enhancing one of the functions I'm interested in using, would love to get your thoughts
#416

@kayleeherrmann
Copy link

kayleeherrmann commented May 7, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants