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

Redis Counting #2

Open
vulcan25 opened this issue Jan 8, 2020 · 0 comments
Open

Redis Counting #2

vulcan25 opened this issue Jan 8, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@vulcan25
Copy link
Owner

vulcan25 commented Jan 8, 2020

Here's a cool feature at commit: 95e5a23

REDIS COUNTS YEAAA.

Since we're already using redis in the project, it's pretty trival to add counts, using Redis' HINCRBY.

Basically we create a redis hash, which at the moment is obj_cnt:default with a field for each item.

So you can curl a few images as usual, then hit the following endpoint to get a list of overall counts, for images submitted through the system:

curl http://localhost:5001/counts
{"handbag":"4","person":"16","sports ball":"4"}

This may be useful if you're submitting a whole load of images, and what to keep track of what was found in those images.

Notice in that commit I've also grabbed the threshold from the env var COUNT_THRESHOLD

This lets you set it in the docker-compose.yml file. Something like:

services:
  processor:
    environment:
      - COUNT_THRESHOLD=0.40

Now only results above that threshold will be counted. If it's not set there it defaults to 0.


If you want, you can also check this out from inside the redis container:

docker exec -it image_processor_redis_1 redis-cli 

Then use the HGETALL command to see the counts for everything in the specified field:

127.0.0.1:6379> keys *
1) "obj_cnt:default"
127.0.0.1:6379> HGETALL obj_cnt:default
1) "sports ball"
2) "1"
3) "handbag"
4) "1"
5) "person"
6) "4"

Run the curl command again to import, then reissue the command and they should increment.


TODOs for this

  • dynamically specify a counter_id. I envision this working so if the upload request hits example.com/some_portal, the counter_id will be set as some_portal. From the frontend, this would let you submit different image 'batches' to different endpoints and get back the relevant counts, theoretically by hitting example.com/counts/some_portal. Probably this needs to be implemented carefully so it can't be doss'ed by people submitting really long keys (some validation required on the counter_id string).

  • Maybe tie this into a frontend template.

@vulcan25 vulcan25 added the enhancement New feature or request label Jan 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant