Git Product home page Git Product logo

intentional-walk-server's Introduction

Intentional Walk Server

Coverage Status

API

See Wiki

Docker-based Development Setup

  1. Install Docker Desktop: https://www.docker.com/products/docker-desktop

    1. If you have Windows Home Edition, you will need to install Docker Toolbox instead. See the troubleshooting notes below.
  2. Copy example.env to .env and edit the Docker environment variables as needed.

  3. Open a command-line shell, change into your repo directory, and execute this command:

    $ docker-compose up
    

    It will take a while the first time you run this command to download and build the images to run the web application code in a Docker "container". In addition, random database data is generated during this process.

  4. Now you should be able to open the web app in your browser at: http://localhost:8000/

    1. If you had to install Docker Toolbox, then replace "localhost" with the IP address of the Docker Virtual Machine.
  5. To stop the server, press CONTROL-C in the window with the running server. If it is successful, you will see something like this:

    Killing intentional-walk-server_db_1           ... done
    Killing intentional-walk-server_server_1       ... done
    

    If it is not successful, you may see something like this:

    ERROR: Aborting.
    

    If you get an error, the server may still be running on your computer. To force it to stop, run the following command and wait for the output to report DONE:

    $ docker-compose stop
    Stopping intentional-walk-server_db_1          ... done
    Stopping intentional-walk-server_server_1      ... done
    

Server management commands

Note: see the instructions in the next quick reference section to start/log in to a running server container and perform the following actions within the container CLI.

  • To create an admin user that can log in to the web views:

    # python manage.py createsuperuser
    
  • To run the test suite:

    # pytest
    
  • To run database migrations:

    # python manage.py migrate
    
  • To collect staticfiles (required for admin interface):

    # python manage.py collectstatic
    
  • To restore a database backup:

    # bin/pg_restore_dump <name of backup.dump>
    
  • To generate a random database dump for development

    # python scripts/dummydata.py --help
    # python scripts/dummydata.py > data.dump
    

Testing

This project uses pytest for testing. Tests are located in the tests directory.

To run tests, invoke the following command in a docker terminal connected to the container:

make test

To generate a code coverage report to see which parts of the code are covered by the tests. This is done with the following command:

make coverage

This runs the tests, generates a coverage report and displays a nice HTML direcotry htmlcov. You can view this report on http://localhost:8001/. Be sure to manually refresh the page each time you run make coverage.

Heroku deployment info

  • Register a free Heroku account here: https://signup.heroku.com/

    Set up your ssh keys with your account for authentication. Then contact an existing team member for access to the Heroku deployment instance(s).

  • Add the git remote repository corresponding to the Heroku deployment environment you wish to access. For example, the staging environment:

    # git remote add staging https://git.heroku.com/iwalk-test.git
    
  • Log in with the Heroku client:

    # heroku login
    
  • Perform a manual database backup:

    # heroku pg:backups:capture
    
  • Download the latest database backup:

    # heroku pg:backups:download
    
  • Deploy to Heroku:

    # git push <remote name, i.e. staging> <branch to deploy, i.e. master>
    
  • Execute a management command in the Heroku deployment environment:

    # heroku run --remote <remote name, i.e. staging> <command to execute, i.e. python manage.py migrate>
    

Docker Command Quick Reference

  • To start all the containers:

    $ docker-compose up
    
  • To run commands within the server container, use the Docker Desktop UI to open a shell inside the running server container. Alternatively, with the containers running, open a new terminal window, change directory (cd) to the root directory of this project, and run:

    $ docker-compose exec server bash -l
    

    If you are missing modules, re-build the server (see below).

  • To stop all the containers, in case things didn't shutdown properly with CTRL-C:

    $ docker-compose stop
    
  • To run the server container without starting everything:

    $ docker-compose run --rm server bash -l
    
  • To re-build the server container (e.g., when you are missing a new modules):

    $ docker-compose build server
    

    Alternatively, you can use to Docker Desktop UI to re-build the server or db container.

Docker Troubleshooting

  • On some PC laptops, a hardware CPU feature called virtualization is disabled by default, which is required by Docker. To enable it, reboot your computer into its BIOS interface (typically by pressing a key like DELETE or F1 during the boot process), and look for an option to enable it. It may be called something like Intel Virtualization Technology, Intel VT, AMD-V, or some similar variation.

  • On Windows, Docker Desktop cannot run on Windows Home edition. Install Docker Toolbox instead:

    https://docs.docker.com/toolbox/overview/

    https://github.com/docker/toolbox/releases

    Use the Docker QuickStart shell installed with Docker Toolbox to open a command-line shell that launches Docker for you when it starts. On Windows, right-click on the shotcut and Run as Administrator. Note: this can take a long time to start, depending upon your computer, as it needs to start a virtual machine running Linux.

    The virtual machine will have its own, separate IP address on your computer. In the .env file (see step 4 in Getting Started), replace localhost with 192.168.99.100 in the BASE_HOST and BASE_URL variables. To confirm that this is the correct IP address, run this command in the command-line shell:

    $ docker-machine ip
    

Requirements

The Heroku buildpack for python requires the existence of a requirements.txt file. However, we use poetry (and its associated requirements file, pyproject.toml) to run coverage tests in TravisCI. Keeping the two package lists in sync is difficult to manage manually; instead we export a requirements.txt file from poetry with:

poetry add {NEW_PACKAGE}
poetry export -f requirements.txt --without-hashes > requirements.txt

intentional-walk-server's People

Contributors

francisli avatar lee51 avatar odo-sfct avatar kevr avatar emdat avatar dependabot[bot] avatar benperlman avatar monkeysaa avatar markcerv avatar aukeller avatar jimmihagen avatar patrickgods1 avatar seanmalbert avatar sreeja-apparaju avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar Steven Zheng avatar  avatar Dion Pham  avatar Alec Venida  avatar yads avatar Mark Khoo avatar Vivek avatar

Watchers

 avatar  avatar James Cloos avatar  avatar 24soaringSoarcererszSauronMelkorSargerasAndKai avatar  avatar Mark Buckner avatar Shereen Punnassery avatar Allen Meyer avatar  avatar  avatar Austin avatar  avatar  avatar

intentional-walk-server's Issues

Update UI table for "Users" view to include new columns

Let's put the new columns, new_signup and active_during_contest in the display table in the Users view.

Ideally I think we would want the table to allow filtering, not just sorting, by column. I'm not sure how much work this would take, but then we could filter the view to only those who were active OR only those who were new signups.

It would also be nice if we could hide the "Rec *" (intentional walk) fields by default but only show them when checking a box or clicking a button to "extend" the view/columns.

Admin should see stats properly de-duped...

In the API calls, we've got the logic to de-dupe records across multiple accounts registered to the same address.

We need to make sure that the aggregate stats do this as well, or we'll be double/triple counting steps/distance...

Should we have a background job that does this on a regular interval and stores the states back in the database, rather than doing it on request?

Docker image fails to build due to Poetry install change

 > [4/7] RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python:                                                                                                                                         
#0 0.975 Retrieving Poetry metadata                                                                                                                                                                                                                  
#0 0.975                                                                                                                                                                                                                                             
#0 0.975 This installer is deprecated, and scheduled for removal from the Poetry repository on or after January 1, 2023.                                                                                                                             
#0 0.975 See https://github.com/python-poetry/poetry/issues/6377 for details.                                                                                                                                                                        
#0 0.975 
#0 0.975 You should migrate to https://install.python-poetry.org instead, which supports all versions of Poetry, and allows for `self update` of versions 1.1.7 or newer.
#0 0.975 Instructions are available at https://python-poetry.org/docs/#installation.
#0 0.975 
#0 0.975 Without an explicit version, this installer will attempt to install the latest version of Poetry.
#0 0.975 This installer cannot install Poetry 1.2.0a1 or newer (and installs will be unable to `self update` to 1.2.0a1 or newer).
#0 0.975 
#0 0.975 To continue to use this deprecated installer, you must specify an explicit version with --version <version> or POETRY_VERSION=<version>.
#0 0.975 Alternatively, if you wish to force this deprecated installer to use the latest installable release, set GET_POETRY_IGNORE_DEPRECATION=1.
#0 0.975 
#0 0.975 Version 1.2.0 is not supported by this installer! Please specify a version prior to 1.2.0a1 to continue!

There are Accounts with IntentionalWalk records but not DailyWalk records

Unclear how this is happening- the app should be sending DailyWalk records on every launch during the contest, so if someone is opening the app to record an IntentionalWalk, then, it should have had a chance to query and send DailyWalk records.

Note that these users are not showing as members of the Contest period, because the association between Account and Contest is made when creating DailyWalk records.

Backend can save new users

These are the fields we're looking to save:

  • First Name
  • Last Name
  • Email
  • Age
  • ZIP Code

There is no password functionality at this point in time

Admin can see stats scoped by contest dates

There's a Contest model that defines the start and end dates for a competition.

When there's an active Contest (i.e. the current date is between the start/end dates of a Contest record), we should scope the stats calculated for that date range.

Crash exporting user contest data

2023-01-14T04:37:08.067047+00:00 app[web.1]: /app/.heroku/python/lib/python3.8/site-packages/django/db/models/fields/__init__.py:1358: RuntimeWarning: DateTimeField IntentionalWalk.end received a naive datetime (2022-06-01 00:00:00) while time zone support is active.
2023-01-14T04:37:08.067074+00:00 app[web.1]: warnings.warn("DateTimeField %s.%s received a naive datetime "
2023-01-14T04:37:38.014611+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/data/users_agg.csv?contest_id=63d18a8c-58cc-4f21-a720-83eacda8728b" host=iwalk-prod.herokuapp.com request_id=b12725bb-ba04-49fc-827c-9b3cddbccaff fwd="23.93.92.146" dyno=web.1 connect=0ms service=30000ms status=503 bytes=0 protocol=https

New registration flow

The app will be splitting the registration process into a number of steps. At each step, the user will enter information and press "Next", which will trigger an API call with partial registration data.

First screen

POST: Name, Email, Zip, Age

Second screen

PUT: Latino/Hispanic origin

Third screen

PUT: Race

Fourth screen

PUT: Gender identity

Fifth screen

PUT: Sexual orientation

We need to modify AppUserCreateView so that it allows a POST request with just name, email, zip, and age and returns account_id. Each subsequent PUT request will be an account update that requires account_id along with any additional fields.

Rename variable name `new_user` to `new_signup` in user_stats

In home/views/web/data.py::user_agg_csv_view we have the CSV column header properly named, new_signup, but in forming the CSV, we are calling the relevant key-value pair new_user. Although this will have no effect on the output, let's rename the key to be consistent with the header.

Export a date range of walks

As an admin,
I want to export all walk data from a given month,
So that I can see if the app is being used outside of contest periods.

121418621-fcf4c180-c91f-11eb-9590-f6e64ca360bf

CI failing CircleCI with no error in dependency installation

#!/bin/bash -eo pipefail
poetry install

Creating virtualenv intentional-walk-3aSsmiER-py3.8 in /home/circleci/.cache/pypoetry/virtualenvs
Installing dependencies from lock file

Package operations: 48 installs, 1 update, 0 removals


Exited with code exit status 1

CircleCI received exit code 1

Is Tester Flag

Is tester flag not auto populating as True for me ("Tester Emon" is the name I used)

App will send user daily_walk baseline data to server

Baseline period will be 1 month prior to contest start.
Baseline data may start getting pushed to server prior to contest start; otherwise, baseline data will be sent at contest start.
Client will receive baseline period start date from server.
For the current contest, instead of using contest start date (or promo date) as "start" filter for walk data, the app will use baseline date.

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.