volentixlabsinc / venue-server

The backend services for Venue, a community engagement platform for the Volentix community
https://venue.volentix.io
MIT License
6 stars 0 forks source link

venue-server

CircleCI code style: prettier standard-readme compliant MIT PRs Welcome Open Source Love

The backend services for Venue, a community engagement platform for the Volentix community.

With Venue, members can post campaigns and bounties for work needed -- for example, fixing bugs, creating content, or promoting Volentix -- and anyone may claim a bounty in exchange for their efforts. Venue provides real time metrics on VTX rewards earned by participants and incentivizes the adoption of VTX.

This backend is a REST API server which receives, processes, and/or serves data for the Venue frontend.

The major dependencies are:

Table of Contents

Install

Before running Venue, make sure you have the following installed on your machine.

Usage

Configuration

You must create a file named .env and place it in the root directory. There are a number of configuration values available (for details, see the code), but in order to have email confirmations sent correctly, you must set:

# Server token from [Postmark](https://postmarkapp.com/)
POSTMARK_SERVER_TOKEN=<server_token>

Other values can be found in settings.py

Running

Note that at the time of writting, the app does not have a set up for local development other than the docker compose script. Future iterations are expected to provide this capability.

To run the application:

docker-compose up

To recreate the docker containers from scratch and clean out the database:

docker-compose down
docker-compose build web
docker-compose up

Test the app:

http://localhost:8000/api/retrieve/leaderboard-data/

Login to the admin:

See the API docs and interactive explorer:

http://localhost:8000/docs/

Troubleshooting

Postgres error

If you get this error while trying to run docker on your machine:

postgres_1  | ERROR:  relation "venue_userprofile" does not exist at character 250

or

postgres_1  | ERROR:  relation "venue_forumprofile" does not exist at character 623

Try to use these commands:

docker-compose down -v
docker-compose up postgres
docker-compose up 

Docker should work well after this.

Docker-Isolation error

If you get this error (on Ubuntu):

ERROR: unable to insert jump to DOCKER-ISOLATION rule in FORWARD chain:  
(iptables failed: iptables --wait -I FORWARD -j DOCKER-ISOLATION: 
iptables v1.6.0: Couldn't load target `DOCKER-ISOLATION':
No such file or directory

You have to run these commands:

iptables -t filter -F DOCKER
iptables -t filter -X DOCKER
iptables -t filter -F DOCKER-ISOLATION
iptables -t filter -X DOCKER-ISOLATION
iptables -t nat -F DOCKER
iptables -t nat -X DOCKER-ISOLATION

Then you need to restart docker daemon:

sudo mkdir -p /etc/systemd/system/docker.service.d
sudo systemctl daemon-reload
sudo systemctl restart docker

Run docker again after restarting the daemon and the error should be fixed.

Testing

Run the tests

docker-compose up  # If the containers are not running yet
docker exec -it venue-server_web_1 pytest

Bitcointalk Signature Campaign

The first ever campaign launched in Venue is a signature campaign in Bitcointalk.org forum site. In this campaign, users who have accounts in the forum can sign up in Venue and join the campaign where it is possible to choose from a selection of signature codes. The code is a BBCode for a Volentix ad banner, which will be shown as signature in each of the user's posts and the user earns VTX tokens as a reward.

Only members of the higher Bitcointalk positions are allowed to participate in the campaign -- namely Member, Full Member, Sr. Member, Hero, and Legendary.

Forum Account Verification

When a Venue user joins the campaign, he/she will be asked for Bitcointalk user ID. The system validates this ID -- checks if it exists and if the position is high enough to be allowed to participate in the campaign. When allowed, the user is asked to choose a signature. The code for the selected signature then needs to be copied and placed in the user's Bitcointalk profile. The system then verifies the placement of the signature. The integrity of the signature placed in the profile is checked simply by checking if it contains the expected links.

Points System

The campaign has a fixed number of total VTX tokens as reward. Participants will earn their share proportional to their number of posts plus some bonus according to their forum positions. This is all tracked using a point system, which is described below.

Some settings that affect the behavior of point system are made configurable through the admin interface (/admin/constance/config/):

  1. VTX_AVAILABLE [default: 120,000] - Total VTX tokens available
  2. POST_POINTS_MULTIPLIER [default: 100] - Points for each new post
  3. MATURATION_PERIOD [default: 24] - Post maturation period in hours
  4. UPTIME_PERCENTAGE_THRESHOLD [default: 90] - Percentage of uptime required

This is how the point system works:

Every new post by a user that bears the signature is automatically credited 100 base points (defined by POST_POINTS_MULTIPLIER) plus a multiplier based on the user's forum position. This new post is monitored roughly every 5 minutes for up to 24 hours (MATURATION_PERIOD) to check for signature removal. The time elapsed when the signature is not found is recorded as invalid signature minutes (i.e. signature downtime). During this MATURATION_PERIOD hour period, the signature must be in place a minimum of UPTIME_PERCENTAGE_THRESHOLD percent, otherwise the points for the post are removed.

The default bonus points percentage are as follows (these are configurable at /admin/venue/forumuserrank/):

  1. Member - no bonus
  2. Full Member - 1%
  3. Sr. Member - 2%
  4. Hero/Legendary - 5%

Scraping and Calculations

Scraping of the users' profiles and their posts in Bitcointalk is done regularly in the background roughly every 5 minutes. Upon completion of every scraping round, the total points are calculated which is the basis for the ranking and the dynamic computation of VTX tokens earned by each user. All these cascade of background tasks are executed automatically by a periodic call to the update_data() function in venue/tasks.py.

API

The API is available from a server running locally at http://localhost:8000/docs. The documentation is also usually available in the Volentix Venue UAT environment.

One nice feature of the docs is the ability to perform API calls on that server. Copy a token (one can be retrieved using authenticate > create), then choose Authenticate > token from the bottom of the screen. Enter Token as the Scheme and paste the token in the next field. All subsequent calls will use this token to perform calls. It's a great way to practice sending and receiving data to and from the server.

Maintainers

@shawnlauzon @joemarct

Contribute

Venue is a project which was originally created by Volentix Labs, but is owned and maintained by the Volentix community. We actively support and appreciate anyone who wants to improve this or any project within the community.

See CONTRIBUTING.md

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © 2018 Volentix Labs Inc