Skip to main content

Real-time application in order to dominate Humans.

Project description

Domination

Real-time application made to monitor and dominate Humans.

From the rating of every human (from 1 to 100) sent to the kafka topic dominate, we detect, in real time, which type they are:

  • Sha if its rating is a multiple of 3
  • Dow if its rating is a multiple of 5
  • ShaDow if its rating is a multiple of 3 and 5
  • Incompatible if none of the above.

Using a new kafka topic shadow, we make the result available to a clickhouse table named shadow.

System Design

+----------------+               +-------------+            +------------------+
|  domination    |               |  dominate   |            | domination       |
+----------------+               +-------------+            +------------------+
| python         | +-----------> |             | +--------> | python           |
| Faust producer |               | Kafka topic |            | Faust agent      |
| HumanRatings   |               |             |            | HumanCategorized |
+----------------+               +-------------+            +------------------+
                                                                      +
                                                                      |
      +---------------------------------------------------------------+
      |
      v
+----------------+           +-------------------+           +-------------------+
|  shadow        |           | shadow_stream     |           |  shadow_consumer  |
+----------------+           +-------------------+           +-------------------+
|                | +------>  | clickhouse table  | +------>  | clickhouse table  |
|  Kafka topic   |           | encapsulate topic |           | materialized view |
|                |           |                   |           |                   |
+----------------+           +-------------------+           +-------------------+
                                                                      +
                                                                      |
      +---------------------------------------------------------------+
      |
      v
+-------------------+
|  shadow           |
+-------------------+
| clickhouse table  |
| store rows        |
|                   |
+-------------------+

Structure of Kafka messages:

  • topic dominate: {"rating": <integer>, "unique_id": "<string>"}

  • topic shadow: {"type": <integer>, "unique_id": "<string>", "emit_timestamp": <datetime>}

Requirements

  • Python >= 3.6
  • docker-compose

Usage

pip install domination

# Start domination
docker-compose up -d
domination worker -l info

# Stop domination
Ctrl + C
docker-compose down

# In case of Kafka broker errors occur:
docker-compose rm && docker-compose up -d  # recreate containers

You can also run The Algorithm as a standalone. It will print the type of every human rated from 1 to 1337.

python the_algorithm.py 

Development

# Install
virtualenv -p python3.8 venv
source venv/bin/activate
pip install -r requirements.txt
make install

# Build
make test # coverage tests
make linter # runs pylint
make build

Create clickhouse tables

Open CLI of the clickhouse client

docker exec -it clickhouse bin/bash -c "clickhouse-client --multiline"

Create shadow_stream, shadow and shadow_consumer tales

CREATE TABLE IF NOT EXISTS shadow_stream
(
    `type` String,
    `unique_id` String,
    `emit_timestamp` DateTime
) ENGINE = Kafka()
  SETTINGS
    kafka_broker_list = 'kafka:29092',
    kafka_topic_list = 'shadow',
    kafka_group_name = 'shadow-group',
    kafka_format = 'JSONEachRow',
    kafka_skip_broken_messages = 1;


CREATE TABLE shadow as shadow_stream
ENGINE = MergeTree()
PARTITION BY toYYYYMM(emit_timestamp)
ORDER BY type;


CREATE MATERIALIZED VIEW shadow_consumer 
TO shadow
AS SELECT * FROM shadow;


SELECT COUNT(*) AS COUNT, type FROM shadow
 GROUP BY type ORDER BY (COUNT) DESC LIMIT 10;

References

TODO

  • deploy package to pypi using github actions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

domination-1.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

domination-1.1-py3.8.egg (7.9 kB view details)

Uploaded Source

File details

Details for the file domination-1.1.tar.gz.

File metadata

  • Download URL: domination-1.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.1

File hashes

Hashes for domination-1.1.tar.gz
Algorithm Hash digest
SHA256 c644de337bc357c12ccf75df327f8608bf83da69a302162f1eb9cff5de8b083c
MD5 fc5ef6b57a0deded93c79256ef8c548a
BLAKE2b-256 b5ef243f215df8e78087e32081acdc317902fe61c00933fe3201fcf5e3a0591e

See more details on using hashes here.

File details

Details for the file domination-1.1-py3.8.egg.

File metadata

  • Download URL: domination-1.1-py3.8.egg
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.1

File hashes

Hashes for domination-1.1-py3.8.egg
Algorithm Hash digest
SHA256 5523782a4e2830e70d94d26f006a86258cb6006d01dfea5460bf3a7f525f3de6
MD5 58a55687f234a328dc1bfbfa76f7a61c
BLAKE2b-256 bd9af3a374b001c6caa2765ad6c2614ac0be043731e1c7e3e80f212a9c5351aa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page