1# CHARTEPSSG
  2
  3*Please note this document is intended for developers at the subcontractor's premises. See the CHART-EPSSG Confluence page https://confluence.eumetsat.int/display/SAE/CHART+EPS-SG for additional information*
  4
  5## Debug container usage
  6The debug container will wait for a debugger to attach on port `5678` before continuing the execution.
  7
  8In order to expose this port to localhost run the container like this:
  9```bash
 10$ docker run -p 5678:5678 --rm registry.solenix.ch/ds-esoc/slxde-dptms/chart/eps-sg/chartepssg/debug:fix-unittest
 11```
 12Afterwards you can attach using a debugger (e.g. VSCode).
 13
 14## Example of serving CHART with the docker container
 15```bash
 16$ docker run --rm -p 10000:10000 registry.solenix.ch/ds-esoc/slxde-dptms/chart/eps-sg/chartepssg/app:fix-unittest serve
 17```
 18
 19## Example of ingesting CCSDS packets using the docker container
 20You have to mount the data you want to process as a volume in the docker container. 
 21Example usage:
 22```bash
 23$ docker run --rm -v$(realpath .)/TestData:/TestData registry.solenix.ch/ds-esoc/slxde-dptms/chart/eps-sg/chartepssg/app:fix-unittest ccsds /TestData/10313.id\ -\ Archived\ HK\ TM/EXP_PARC_SGB1_PARC_TM_2020-10-02T12_00_00.008592__2020-10-02T14_59_59.995026
 24```
 25Note: the local folder `./TestData/` will be mounted in the conatainer under the root: `/TestData`. Then we can provide the in-container path to the CCSDS file to the `ccsds` command.
 26
 27There are two ways to invoke chartepssg application:
 28
 29## Usage of virtual environment
 30Note: the instructions below assume that you are in the root of the Chart-EPSSG project.
 31
 321. Set up the virtual environment
 33```bash
 34$ python3 -m venv venv
 35```
 362. Activate the virtual enviorment
 37```bash
 38$ source venv/bin/activate
 39```
 403. Install Chart-CORE
 41```bash
 42$ pip install -e  ../chart  # Note: this is the local path to your chart core version
 43```
 444. Install Chart-EPSSG
 45```bash
 46$ pip install -e .
 47```
 485. Install basemap
 49```bash
 50$ pip install --only-binary ":all:" https://github.com/matplotlib/basemap/archive/v1.2.2rel.tar.gz
 51```
 52If we use this approach, then we need to activate enviorment using $ source venv/bin/activate  command.
 53It is also important to know that to order to execute any command in this approach, it needs to be preceeded as follows :
 54python bin/chartepssg <command>
 55
 56## Set up of environment variables like other missions
 57This case we can execute commands simliar to other missions.
 58
 59## (Re-)Create DB, layout and import data
 60On my setup i have to activate the `venv` prior to the steps below:
 61```bash
 62$ source venv/bin/activate
 63```
 64
 651. If you already have the CHARTEPSSG DB, drop the database in PGADMIN (or by other means) and create a new one
 662. Recreate the CSVs out ouf the dats
 67    execute the following commands from the root of the project chartepssg.
 68    ```bash
 69    $ rm -rf SRDB/
 70    $ python utils/extract_csvs_from_dat.py ../TestData/SRDB/ESG14012/ SRDB/current
 71    ```
 723. Run the srdb tool to create the XMLs (or use `srdb.sh`)
 73    ## Using srdb.sh
 74    if we use srdb.sh, execute following command
 75    ```bash
 76    $ chmod 777 utils/srdb.sh
 77    ```
 78    ```bash
 79    $ utils/srdb.sh
 80    ```
 81    ## Using CommandLine
 82     ```bash
 83    mkdir -p chartepssg/db/ts
 84    python bin/chartepssg srdb --gen-param1-param2-xml
 85    python bin/chartepssg srdb --gen-table-xml chartepssg/db/ts/TM.xml --storage-table TM_STORE
 86    python bin/chartepssg srdb --gen-table-xml chartepssg/db/ts/TC.xml --tc --storage-table TC_STORE
 87    python bin/chartepssg srdb --gen-packets-xml -s epssga
 88    python bin/chartepssg srdb --gen-packets-xml -s epssga --tc
 89    python bin/chartepssg srdb --gen-cal-xml -s epssga
 90    python bin/chartepssg srdb --gen-cal-xml -s epssga --tc
 91    ```
 92
 934. Create the tables in the DB (or use `ddl.sh`)
 94    ## Using ddl.sh
 95    if we use ddl.sh, execute following command
 96    ```bash
 97    $ chmod 777 utils/ddl.sh
 98    ```
 99    ```bash
100    $ utils/ddl.sh
101    ```
102    ## Using CommandLine
103    ```bash
104    python bin/chartepssg ddl --all-ts --execute
105    python bin/chartepssg ddl --all-sys --execute
106    python bin/chartepssg ddl --all-cal --execute
107    python bin/chartepssg ddl --all-functions --execute
108    ```
109
1105. Import data to the DB
111    ```bash
112    $ python bin/chartepssg ccsds -s EPSSGA --rapid ../TestData/10313.id\ -\ Archived\ HK\ TM/EXP_PARC_SGB1__PARC_TM_2020-10-01T13_09_59.016405 --ingest
113    ```
114    
1156. To generate report using test_report.xml present in config->report folder
116    ```bash
117    $python bin/chartepssg report --template chartepssg/config/reports/test_report.xml -o ./output --sid EPSSGA --sensing-start 20201002000000 --sensing-stop 20201004000000
118    ```