Daniel-Chin / nozomi.la-AI

AI learns your preferences on nozomi.la
Other
1 stars 1 forks source link

added in my version progress bar and cython decode_nozomi #6

Open dEN5-tech opened 2 years ago

dEN5-tech commented 2 years ago

created new progress.js file

const { Observable } = Rx;
const { map } = Rx.operators;
const { concatMap, concat, delay, bufferCount, switchMap } = Rx.operators;

const sleep = ms => concat(Rx.Observable.empty().pipe(delay(ms)));

const ajaxAlike = call => Rx.Observable.of(call).pipe(delay(500));

const GET_REQ$ = Rx.Observable.ajax({
    url: '/load',
    method: 'GET',
    responseType: "text"
});

function percentage(partialValue, totalValue) {
    return parseInt((100 * partialValue) / totalValue)
}

const observer = new MutationObserver(() => {
    const source = Rx.Observable.interval(100);
    const subscribe = source.subscribe(val => {
        const htmlSubscription = Rx.Observable.combineLatest(GET_REQ$)
            .subscribe(([req]) => {
                var simpleResponse = JSON.parse(req.xhr.responseText)
                const loader = document.querySelector("#myBar")
                loader.setAttribute('style', ``);
                loader.setAttribute('max', `${simpleResponse.pool_max}`);
                loader.setAttribute('value', `${simpleResponse.len}`);
                loader.setAttribute('text', `${percentage(simpleResponse.len,simpleResponse.pool_max)}%`);
                if (simpleResponse.len == simpleResponse.pool_max) {
                    loader.setAttribute('style', `visibility:hidden`);
                    subscribe.unsubscribe()
                };
            })

    });
});

document.addEventListener("DOMContentLoaded", function(event) {
    observer.observe(document.querySelector("#imgdiv"), { childList: true });
});

and add text to index.html

    <script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.5.7/Rx.js"></script>
    <script src="progress.js"></script>
        ...
    <progress  id="myBar"></progress >

in file decodeNozomi.pyx

# distutils: language = c++

from libcpp.vector cimport vector

def f(bytes n):
    cdef vector[int] vect
    cdef int i, x
    for i in range(0, len(n), 4):
        vect.push_back((n[i] << 24) + (n[i+1] << 16) + (n[i+2] << 8) + n[i+3])
    return vect

for compile: create setup.py file and paste code

from setuptools import setup
from Cython.Build import cythonize

setup(
    name='decode Nozomi app',
    ext_modules=cythonize("decodeNozomi.pyx"),
    zip_safe=False,
)

start in dir command python setup.py build_ext --inplace

for use in nozo.py file

import from decodeNozomi import f as decode_nozomi and use in code

...
post_ids = decode_nozomi(r.content)
  return post_ids

paste to server.py

    ...
    elif request.target.split('?')[0] == '/load':
      lst = []
      for x in g.jobs:
        if x.imageWorker.result is not None:
          lst.append(True)
        else:
          lst.append(False)
      respond(self.socket, json.dumps({
          'len': len(g.jobs),
          'pool_max': JOB_POOL_SIZE,
          'progress': lst,
      }).encode())
      ...
Daniel-Chin commented 2 years ago

Hi! Any explanation of what you made?

dEN5-tech commented 2 years ago

Hi! Any explanation of what you made?

What I wrote speeds up the search for an idi with arraybuffer, namely in the file decodeNozomi.pyx is cython, using compile it converts to c++ code and it can be used in the project

Daniel-Chin commented 2 years ago

Hi! Any explanation of what you made?

What I wrote speeds up the search for an idi with arraybuffer, namely in the file decodeNozomi.pyx is cython, using compile it converts to c++ code and it can be used in the project

Cool! Feel free to make a pull request.

Also, what's progress.js for?

dEN5-tech commented 2 years ago

Cool! Feel free to make a pull request.

Also, what's progress.js for?

This is an indicator of loading, in brief, I send a request once a second interval is obtained the current position of loading and visually displayed in the progress bar.

And you need this to import the libraries

and add text to index.html

    <script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.5.7/Rx.js"></script>
    <script src="progress.js"></script>
      ...
  <progress  id="myBar"></progress >

This is where I get the maximum amount of jobs

paste to server.py

  ...
    elif request.target.split('?')[0] == '/load':
      lst = []
      for x in g.jobs:
        if x.imageWorker.result is not None:
          lst.append(True)
        else:
          lst.append(False)
      respond(self.socket, json.dumps({
          'len': len(g.jobs),
          'pool_max': JOB_POOL_SIZE,
          'progress': lst,
      }).encode())
      ...
Daniel-Chin commented 2 years ago

Cool! Feel free to make a pull request. Also, what's progress.js for?

This is an indicator of loading, in brief, I send a request once a second interval is obtained the current position of loading and visually displayed in the progress bar. And you need this to import the libraries

and add text to index.html

    <script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.5.7/Rx.js"></script>
    <script src="progress.js"></script>
        ...
    <progress  id="myBar"></progress >

This is where I get the maximum amount of jobs

paste to server.py

    ...
    elif request.target.split('?')[0] == '/load':
      lst = []
      for x in g.jobs:
        if x.imageWorker.result is not None:
          lst.append(True)
        else:
          lst.append(False)
      respond(self.socket, json.dumps({
          'len': len(g.jobs),
          'pool_max': JOB_POOL_SIZE,
          'progress': lst,
      }).encode())
      ...

I see! Now I understand. Feel free to make a commit.