Code Monkey home page Code Monkey logo

platyrhynchos's People

Contributors

dependabot[bot] avatar jqdq avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

platyrhynchos's Issues

`Total of weights must be greater than zero` in Pyodide

Describe the bug
While generating crosswords in Pyodide, an exception rises sometimes:

Uncaught (in promise) PythonError: Traceback (most recent call last):
  File "/lib/python311.zip/_pyodide/_base.py", line 540, in eval_code_async
    await CodeRunner(
  File "/lib/python311.zip/_pyodide/_base.py", line 365, in run_async
    await coroutine
  File "<exec>", line 8, in <module>
  File "/lib/python3.11/site-packages/platyrhynchos/director/direct_search.py", line 16, in generate_crossword
    word, colrow = await cruciverbalist.choose_and_fill(crossword)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.11/site-packages/platyrhynchos/cruciverbalist/base.py", line 62, in choose_and_fill
    return await self.find_word(colrows)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.11/site-packages/platyrhynchos/cruciverbalist/base.py", line 54, in find_word
    choice = random.choices(words, weights=list(range(len(words))), k=1)[0]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python311.zip/random.py", line 509, in choices
    raise ValueError('Total of weights must be greater than zero')
ValueError: Total of weights must be greater than zero
    PythonError https://cdn.jsdelivr.net/pyodide/v0.23.1/full/pyodide.asm.js:9
    new_error https://cdn.jsdelivr.net/pyodide/v0.23.1/full/pyodide.asm.js:9
    _PyCFunctionWithKeywords_TrampolineCall https://cdn.jsdelivr.net/pyodide/v0.23.1/full/pyodide.asm.js:9
pyodide.asm.js:9:105278
    a http://localhost:8080/main.js:971
    <anonymous> webpack-internal:///./src/index.js:27
    AsyncFunctionThrow self-hosted:760
    (Async: setTimeout handler)
    hiwire_call_bound https://cdn.jsdelivr.net/pyodide/v0.23.1/full/pyodide.asm.js:9

Additional context
It might be due to lack of words

Improved database query speed

Is your feature request related to a problem? Please describe.
DB query speed on Pyodide is deficient - every query takes around ~1.5 seconds to be sent to a server, executed and returned.

Describe the solution you'd like
I have some ideas:

  • Database caching:
    • Sample the database and ask the cache first, sending a request to DB if it doesn't find anything satisfactory
    • add a db cache based on alphabit record
    • add indexing by alphabit
    • cache database by category
  • Splitting the requests into pages
  • Render the database cache and store it on S3

Describe alternatives you've considered

  • We can ignore the issue for now
  • Connecting to DB via a web socket
  • Queue-based DB - would require a significant rewrite
  • Remove some awaits from DB
  • Switch to redis (once again, a significant rewrite)

Add more testing of `crossword/improvable.py`

Is your feature request related to a problem? Please describe.
Low test coverage

Describe the solution you'd like
Testing of add, addLetter and rotate functions.

Describe alternatives you've considered

  • Improved testing of crossword/base.py- not used currently
  • Fix crossword/addable.py testing - not used currently
  • Remove crossword/addable.py, and related functions from the main branch.

The last one will probably be done while at it.

Graph-based crossword representation

Is your feature request related to a problem? Please describe.

  • As the optimization algorithm I would like to know what words conflict with each other.
  • As the optimization algorithm I would like to know what words work well together.
  • As the optimization algorithm I would like to know the history of specific words
    This would allow us to use SAT solvers (or other knapsack-like solvers) when generating the crossword.

Describe the solution you'd like
Representing a single word as an object with a list of all other words that interact with it (maybe via a field class?). Depending on the type of interaction, these might be considered a good thing or a bad thing.
This would require rewriting the crossword libs.

Describe alternatives you've considered
Random choice, wrappers, simple backtracking with copying, adding a child class.

Additional context
I thought about it when thinking about action representation. It's somewhat similar to how Larch backtracking worked.

Word scanning at the end

Sometimes the crossword contains words unbeknownst to the generator. Let's scan for them using full-text search (?).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.