# vaknl-user

Defines the vaknl `User` dataclass. A user (here identified by a `dmp_user_id`) is an object 
that is defined by website clickstream data as a basis. The User class contains functions 
that can transform raw Firestore website clickstream data to well defined `Event` 
dataclasses and update the statistics of the `User` accordingly. These Event dataclasses are 
read and translated into user information. The `User` dataclass also includes methods to 
read from and write to Firestore.

### Authors 
| Date   | Name   |
| ------ | ------ |
| 2020-07-17 | Merijn van Es | 


## Prerequisites

Firestore read and write permissions within the Google Cloud Platform (GCP), if one wants to 
make use of the Firestore functionality.


## `User` dataclass

Can be found under `vaknl_user.user.user.User` and has the following useful methods:

### `import_statistics(self, client: utils.firestore.client)`
Imports all statistics of the `User` from Firestore.

### `export_statistics(self, client: utils.firestore.client)`
Exports all statistics of the `User` to Firestore.

### `create_user_from_clickstream(self, client: firestore.client)`
Imports all raw clickstream event data from Firestore and updates the `User` accordingly. 
Overwrites all existing statistics.

### `update_user_from_clickstream(self, client: firestore.client)`
Imports all raw clickstream event data from Firestore with a `timestamp` greater than 
`statistics.general.activity_last_timestamp`and updates the `User` accordingly. Adds 
statistics to existing.


## `Event` dataclass

This dataclass has many children (can be found in the same package directory under 
`filer.py`, `other.py`, `pageview.py` or `reservation.py`, which represent the individual 
clickstream events of interest. The `Event` dataclass can be found under 
`vaknl_user.event.event.Event` and should, in practice, only be called through the methods 
of the `User` dataclass.


## `Events` dataclass

This dataclass contains a list of `Event` instances, but has some useful methods that make 
it more desirable than a plain list. The `Events` dataclass can be found under 
`vaknl_user.event.event.Events` and should, in practice, only be called through the methods 
of the `User` dataclass.


## `create_event(data: dict)`

The `create_event()` function is used to transform single raw clickstream event 
dictionaries to a instance of `Event` (and one of it child dataclasses). The 
`create_event()` function can be found under `vaknl_user.event.event.Event` and should, in 
practice, only be called through the methods of the `User` dataclass.
