# Hive AI Detection lambda

### Additional Setup

Copy `.env.shadow` to `.env` and add a value for `hive_credentials=`

### Invoking Function

* The function can take input from an MSK->Lambda connector, see [kafka_event()](./tests/unit/test_app.py) for an example.

* It can also consume from an SQS event source mapping (used for bulk/historical scans). Each message body is a single asset object, e.g. `{"ASSET_FINAL_ID": 20920529, "DURATION_MS": 183000}` — see [sqs_event()](./tests/unit/test_app.py).

* For a more human experience, asset final data can be passed like this instead...

```bash
curl --request POST \
  --url http://localhost:9000/2015-03-31/functions/function/invocations \
  --header 'Content-Type: application/json' \
  --data '{
  "eventSource": "custom",
  "assets": [
    {
      "ASSET_FINAL_ID": 20920529,
      "DURATION_MS": 183000
    },
    {
      "ASSET_FINAL_ID": 77630036,
      "DURATION_MS": 10593131
    }
  ]
}'
```

* Use products with assets in QA as defined [here](https://www.notion.so/Encoding-Workers-4614a8e498034b4984eba275c3709c21?source=copy_link#4a9f2a8ff4d04661a8dd5f37fdc67229) to test with.

```sql
SELECT
    au.upc,
    au.track_unique_id,
    CONCAT(
        JSON_OBJECT(
            'ASSET_FINAL_ID', af.id,
            'DURATION_MS', af.duration
        ),
        ','
    ) AS input_data
FROM ows_assets.asset_upload au
JOIN ows_assets.asset_final af
    ON af.asset_upload_id = au.id
    AND af.asset_type = 'FLAC'
WHERE
    au.upc in (
        '5054526973572',
        '197189428050'
    )
ORDER BY
    au.upc,
    au.track_unique_id
;
```
