Foresight Data Portal for Python
===================


Installation
------

`
    $ pip install --upgrade fsai_data_sdk
`

Usage
------

## Get Data
### Get data at a specific location

```python
    import fsai_data_sdk as DatasetService
    
    dataset_service = DatasetService(API_KEY, SECRET_KEY)
    datasets = dataset_service.get_data_at(lng=-122.1598309, lat=37.4358347, radius=2000, layers=["SEMANTIC_2D", "DYNAMIC_OBJECTS"])
    print(len(datasets))
    sample_dataset = datasets[0]
    print(sample_dataset)
    print(sample_dataset.layers.semantic_2d.get())
    print(sample_dataset.layers.dynamic_objects[0].get())
  
```

The **get_data_at** function returns a list of **Dataset**. Each **Dataset** object contains the data layers:
* semantic_2d: a **DataGetter** object to get the semantic 2d json data of the area.
* dynamic_objects: a list of **DataGetter** object to get the array of dynamic_object.

### DataGetter class
Because the data layers are normally large, they can't be returned directly in the getting data calls. 
The SDK wrap the data layer in the **DataGetter** class which provides a **get** function to fetch 
the data and return the actual data of the layer.

### Parsing data

```python
    import fsai_data_sdk as DatasetService
    from fsai.services.data_object.DynamicObjectData import DynamicObjectData


    dataset_service = DatasetService(API_KEY, SECRET_KEY)
    datasets = dataset_service.get_data_at(lng=-122.1598309, lat=37.4358347, radius=2000, layers=["SEMANTIC_2D", "DYNAMIC_OBJECTS"])
    print(len(datasets))
    sample_dataset = datasets[0]
    
    "Parse dynamic object json into class objects"
    sample_dynamic_object_script = sample_dataset.layers.dynamic_objects[0].get()
    dynamic_object_data = DynamicObjectData.from_json(sample_dynamic_object_script)
    for object in dynamic_object_data.collections[0].objects:
        print(object.get_moving_distance())
  
```
        
## See also
* SDK for Javascript https://github.com/ForesightAI/fsai_data_sdk_js
* Rest API: https://data.foresight.ai/docs/public/api/
