# ows-playlist

A microservice to provide insights into playlists available in different streaming services to any interested parties (department, organization, or other services) within the organization.

This service accesses the data from the tables in snowflake(aggregated and granular) to provide a real-time view into the playlisting data.

The tables are constructed using the dbt-analytics pipeline.

This service powers the Playlisting in Insights and is expected to be as performant as possible with given datastore.

## Endpoints

| Endpoint                                                         | Description                                                 
| ---------------------------------------------------------------- | ----------------------------------------------------------- 
| `/placements`                                                    | Placements, filtered by isrc or global_participant_id       
| `/placements/label/recent`                                       | Placements - sorted by last_added_on_date DESC filtered by label_id, subaccount_id or label_participant_id which are taken from the permissions of the profile making the request 
| `/placements/breakdown`                                          |                                                             
| `/playlist/<global_playlist_id>/placement/<isrc>/positions`      | Placement position time series                              
| `/playlist/<global_playlist_id>/placement/<isrc>/streams`        | Placement stream time series                                


## Getting Started

### Installation

1. Ensure python3.9 is installed with pyenv.
- the specific current version used by the project is set in `.python-version`

```
$ brew update
$ brew install pyenv
$ pyenv install 3.9.7 
```

If you use Windows, just ask for a remote VM that has it installed for you.

2. You'll next want to install the python packages used by the project:

```bash
$ cd ows-playlist
$ make pip_dev
$ pre-commit install
```

### Permissions

In PROD and QA environments, to accept and authorize incoming and outgoing
requests, make sure you have the right DynamoDB permissions, as highlighted
in the corresponding [tech design](https://docs.google.com/document/d/1eHoI_BddTFMi15yCaHS6KvhSSoTrMEd3WwJINIpgNpM/edit).

### Running

When all dependencies have been installed, you can run the flask application
on your local instance by running:

```bash
(env) $ python dev.py
```

or

```bash
make dev
```

All make commands will automatically install all dependencies in an virtual environment folder called env.
You can activate a virtual environment by running `. env/bin/activate` or `source env/bin/activate`.

By using the development server, you will have access to specific features that
are not necessarily available in production, such as the exception tracer.

### Testing

To run the tests, all you have to do is to run:

```bash
(env) $ py.test tests/unit/
(env) $ py.test tests/integration/
(env) $ flake8 playlist/ tests/
```

or

To run unit tests: `make test`

To run unit tests with coverage reporting: `make test_unit`

To run integration tests: `make test_integration`

To lint: `make lint`

### Updating

To install new dependencies.

```bash
(env) $ pip install -r requirements.txt
(env) $ pip install -r requirements-dev.txt
```

or

```bash
make pip_dev
```

### Notes

Windows users will not be able to use the `make` commands as Make is a Unix util.
Windows users can attempt to install [GNUWin](http://gnuwin32.sourceforge.net/packages/make.htm) to get this functionality.

## Usage

The api endpoints accessible from this service is available at -

https://swagger.theorchard.io/ows-playlist

## Docs

- [Whimsical](https://whimsical.com/playlisting-LuKXZZAA73p59ozaBDaQ4v)
- [Google Drive](https://drive.google.com/drive/folders/17HN5D7sBgD6RUr_OBnL84vq_K0IP8UlO?usp=sharing)

## Support

Data squad
Insights/Playlisting2.0 team

Any questions related to this repository or PRs can be directed **#insights-initiatives** slack channel
