Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 20513e9f

Přidáno uživatelem Martin Sebela před více než 3 roky(ů)

  • ID 20513e9fbd66bbf97c19c368530ecc5b3f30358d
  • Rodič 7e44e97f

Dokončení oborového projektu KIV/OPSWI

Zobrazit rozdíly:

.gitlab-ci.yml
1
stages:
2
    - build
3
    - linter
4
    - test
5
    - deploy
6
    
7
build:
8
    stage: build
9
    tags:
10
        - build
11
    script:
12
        # Test whether container can be build or not
13
        - ./scripts/build.sh
14
        - docker-compose stop crawler nginx
15
        # We could also push docker image to some registry or docker hub
16

  
17
php_linter: 
18
    stage: linter
19
    tags:
20
        - linter
21
    script:
22
        - ./scripts/composer.sh require --dev squizlabs/php_codesniffer
23
        - docker-compose exec -T php-fpm /bin/sh -c "/var/www/symfony/vendor/bin/php-cs-fixer fix /var/www/symfony/src --dry-run --config /var/www/symfony/.php_cs --stop-on-violation --using-cache=no"
24

  
25

  
26
tests:
27
    stage: test
28
    tags:
29
        - test
30
    script:
31
        - ./scripts/composer.sh require --dev symfony/phpunit-bridge
32
        - ./scripts/composer.sh require --dev symfony/browser-kit symfony/css-selector         
33
        - docker-compose exec -T php-fpm /bin/sh -c "export APP_ENV=test && cd ../symfony && php bin/phpunit"
34
        - docker stop $(docker ps -q)
35
        
36
deploy_prod:
37
    stage: deploy
38
    tags:
39
        - deploy
40
    variables:
41
        GIT_STRATEGY: none
42
    environment:
43
        name: heatmap
44
        url: https://heatmap.zcu.cz
45
    script:
46
        - ssh root@heatmap.zcu.cz "cd ~ && rm -rf aswi2020sebela && git clone https://gitlab.kiv.zcu.cz/aswi/aswi-2020/aswi2020sebela.git && cd aswi2020sebela && ./scripts/build.sh && exit"
47
    only:
48
        - master
49
    when: manual
README.md
1
# ZČU Heatmap
1
# Heatmap.ZČU
2
App was created within the school project by ZČU students. The main goal of this project is to create a simple and generic tool for vizualization of heatmap like datasets. The first implementation can be seen at https://heatmap.zcu.cz.
3
## Intro webpage
4
<img src="./doc/images/website-intro.png" style="width: 600px; height: auto;">
2 5

  
3
- [**Nginx**](https://www.nginx.com/) - Server
4
- [**Symfony**](https://symfony.com/) - PHP framework
5
- [**MongoDB**](https://www.mongodb.com/) - Database
6
## Heatmap webpage
7
<img src="./doc/images/website-heatmap.png" style="width: 600px; height: auto;">
8

  
9
## Responsive
10
<img src="./doc/images/website-responsive.png" style="width: 200px; height: auto;">
11

  
12
<br><hr><br>
13

  
14
## Technologies
15

  
16
- [**Nginx**](https://www.nginx.com/) – Webserver
17
- [**Symfony**](https://symfony.com/) – PHP framework
18
- [**MongoDB**](https://www.mongodb.com/) – Database
19

  
20
<br><hr><br>
6 21

  
7 22
## 🔩 Development env
8 23
### SW needed for development
9 24
* **[🐳 docker](https://docs.docker.com/engine/install)**
10 25
* **[🐳 docker-compose](https://docs.docker.com/compose/install/)**
11 26
* **[📝 Visual Studio Code](https://code.visualstudio.com/Download)**
27
<br><br>
28

  
12 29
### Development setup
13 30
* First you need to **build** and **run** all needed containers
14 31
  * run either of these scripts inside the **root of the project**:
......
58 75
* Set your breakpoints and hit <kbd>F5</kbd> or goto <kbd>Run >> Start debugging</kbd>
59 76
* Working in both modules
60 77
## 🚀 Production env
61
* To run production env on your local machine execute this `./scripts/build.sh`
78
* To run production env on your local machine execute this `./scripts/build.sh`
79

  
80
<br><hr><br>
81

  
82
## Add new dataset to heatmap
83

  
84
Follow these steps:
85

  
86
1. Run script `modules/crawler/prepare_new_dataset.py` in directory `modules/crawler`.
87
2. Fill items like `display-name`, `display-color`, `dataset-name`, `url`, `regex`, `update-period` within the YAML config file in directory `modules/crawler/DatasetConfigs`.
88
3. Implement own dataset crawler in directory `modules/crawler/DatasetCrawler`.
89
4. Implement own dataset processor in directory `modules/crawler/DatasetProcessing`.
90
5. Run script `modules/crawler/force_update_dataset.py` and enter name of new dataset. After that all needed data are downloaded and processed.
91
6. Fill coordinates to `devices` items in the YAML config file.
92
7. After running `force_update_datasets.py` again, data will be loaded to database.
93

  
94
<br><hr><br>
95

  
96
## Auto updating datasets –⁠ Cron script
97

  
98
File `modules/crawler/crone_update_script.py` performs update of all added datasets. Update period is defined in the YAML config file of each dataset (item `update-period`).
99

  
100
Script `modules/crawler/crone_update_script.py` is executed by systems cron (`modules/crawler/crontab`) every day.
101

  
102
<br><hr><br>
103

  
104
## Customize appearance of the heatmap
105

  
106
### SASS style file
107
CSS color settings (backgrounds, controls, ...).
108

  
109
`public/css/style.scss`
110

  
111
### Heatmap locations list
112
Locations with coordinates.
113

  
114
`public/templates/heatmap-locations.html.twig`
115

  
116
<img src="./doc/images/heatmap-locations-list.png" style="width: 250px; height: auto;">
117

  
118
### Intro heatmap webpage
119
`public/templates/index.html.twig`
120

  
121
### Heatmap webpage
122
`public/templates/heatmap.html.twig`
docker-compose-prod.yml
7 7
              ports: 
8 8
                     - "443:443"
9 9
              volumes: 
10
                     - /acme-1:/root/.acme.sh/heatmap.zcu.cz
11
                     - /acme-2:/root/.acme.sh/www.heatmap.zcu.cz
10
                     # TODO: set certificate here
11
                     # https://github.com/acmesh-official/acme.sh
12
                     #
13
                     #- /acme-1:/root/.acme.sh/heatmap.zcu.cz
14
                     #- /acme-2:/root/.acme.sh/www.heatmap.zcu.cz
15
                     #
12 16
                     - /etc/certificate:/certificate
13 17
                     - ./docker/nginx/sites:/etc/nginx/sites-available
14 18
                     - /logs/nginx:/var/log/nginx
docker-compose.yml
55 55
                       - '27017-27019:27017-27019'
56 56
               environment:
57 57
                       MONGO_INITDB_DATABASE: open-data-db
58
                       #
59
                       # TODO: set MongoDB credentials
60
                       #
58 61
                       MONGO_INITDB_ROOT_USERNAME: root
59 62
                       MONGO_INITDB_ROOT_PASSWORD: root
60 63
               volumes:
docker/nginx/nginx.conf
9 9
    worker_connections 1024;
10 10
}
11 11

  
12

  
13 12
http {
14 13
    include /etc/nginx/mime.types;
15 14
    default_type application/octet-stream;
docker/nginx/sites-dev/default.conf
2 2
    listen 80 default_server;
3 3
    listen [::]:80 default_server ipv6only=on;
4 4

  
5
    #
6
    # TODO: set website domain
7
    #
5 8
    server_name heatmap.zcu.cz www.heatmap.zcu.cz;
6 9
    root /var/www/symfony/public;
7 10
    index index.php index.html index.htm;
docker/nginx/sites/default.conf
1 1
server {
2 2
    listen 80;
3 3
    listen [::]:80;
4

  
5
    #
6
    # TODO: set website domain
7
    #
4 8
    server_name heatmap.zcu.cz www.heatmap.zcu.cz;
5 9

  
6 10
    location ~ /.well-known {
......
13 17
server {
14 18
    listen 443 ssl;
15 19
    listen [::]:443 ssl;
20

  
21
    #
22
    # TODO: set website domain
23
    #
16 24
    server_name www.heatmap.zcu.cz;
25

  
26
    #
27
    # TODO: set certificate files
28
    #
17 29
    ssl_certificate /root/.acme.sh/heatmap.zcu.cz/fullchain.cer;
18 30
    ssl_certificate_key /root/.acme.sh/heatmap.zcu.cz/heatmap.zcu.cz.key;
31

  
19 32
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
20 33
    ssl_prefer_server_ciphers on;
21 34
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
22 35

  
36
    #
37
    # TODO: set website domain
38
    #
23 39
    return 301 https://heatmap.zcu.cz$request_uri;
24 40
}
25 41
server {
26 42
    listen 443 ssl;
27 43
    listen [::]:443 ssl;
28 44

  
45
    #
46
    # TODO: set website domain
47
    #
29 48
    server_name heatmap.zcu.cz;
49

  
50
    #
51
    # TODO: set certificate files
52
    #
30 53
    ssl_certificate /root/.acme.sh/heatmap.zcu.cz/fullchain.cer;
31 54
    ssl_certificate_key /root/.acme.sh/heatmap.zcu.cz/heatmap.zcu.cz.key;
32 55

  
docker/php-fpm/dev/Dockerfile
1
#DEV ONLY DOCKERFILE
1
# DEV ONLY DOCKERFILE
2 2
FROM php:7.4-fpm-alpine
3 3
RUN apk update; \
4 4
    apk upgrade; \
modules/crawler/.devcontainer/devcontainer.json
1 1
{
2
    //TODO: dodat extensionu pro yaml soubory!!!
3 2
    "forwardPorts": [
4 3
        8000,
5 4
        443,
modules/crawler/Utilities/Database/database_loader.py
6 6
import pymongo
7 7
import re
8 8

  
9
#
10
# TODO: set MongoDB credentials
11
#
12

  
9 13
# specify mongodb connection
10 14
MONGODB_CONNECTION = "mongodb://root:root@database"
11 15
# mongodb account name
scripts/build.sh
3 3
docker-compose -f docker-compose.yml -f docker-compose-prod.yml up --build -d
4 4
docker-compose exec -T php-fpm composer install --no-interaction --working-dir=/var/www/symfony --no-dev
5 5
docker-compose exec -T php-fpm /bin/sh -c "cd /var/www/symfony && npm install && npm link webpack && npm run build"
6
#python module initiation
6

  
7
# python module initiation
7 8
docker-compose exec -T crawler /bin/sh -c "cd /src && python docker_prepare_structure.py && python force_update_datasets.py all"
scripts/pip.sh
1 1
#!/bin/bash
2
#install requirements pip.sh install -r /var/python/requirements.txt
3 2
docker-compose exec -T crawler pip $@
scripts/renew_certificate.sh
3 3
# if you want create new license run: renew_certificate new
4 4
# if you want re-create the existing license run: renew_certificate
5 5

  
6
#
7
# TODO: set website domain
8
#
6 9
if [ "$1" = "new" ]; then
7 10
    docker-compose exec nginx /bin/sh -c "
8 11
    cd /root/.acme.sh; \
scripts/restore_db.sh
1 1
#!/bin/bash
2

  
3
#
4
# TODO: set MongoDB credentials
5
#
2 6
docker-compose exec -T database mongorestore --username root --password root --authenticationDatabase admin --db open-data-db /dev-dump/data
website/.env
19 19
#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
20 20
#TRUSTED_HOSTS='^(localhost|example\.com)$'
21 21
###< symfony/framework-bundle ###
22

  
23
#
24
# TODO: set MongoDB credentials
25
#
22 26
DATABASE_CONNECTION_STRING=mongodb://root:root@database
23 27

  
24 28
###> sentry/sentry-symfony ###
website/.env.test
1 1
APP_ENV=test
2 2
APP_SECRET=ca5751564bbb9a0d75d412e020790283
3

  
4
#
5
# TODO: set MongoDB credentials
6
#
3 7
DATABASE_CONNECTION_STRING=mongodb://root:root@database
website/config/services.yaml
3 3

  
4 4
# Put parameters here that don't need to change on each machine where the app is deployed
5 5
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
6

  
7
#
8
# TODO: set MongoDB credentials
9
#
6 10
parameters:
7 11
    databaseConnectionString: 'mongodb://root:root@database'
8 12

  
website/phpunit.xml.dist
7 7
    <php>
8 8
        <env name="APP_ENV" value="test" />
9 9
        <env name="KERNEL_CLASS" value="App\Kernel" />
10
        <!--
11
            TODO: set MongoDB credentials
12
        -->
10 13
        <env name="DATABASE_CONNECTION_STRING" value="mongodb://root:root@database" />
11 14
    </php>
12 15
</phpunit>
website/public/js/index.js
249 249
    heatmapLayer = L.heatLayer(mergedPoints, { max: max, minOpacity: 0.5, radius: 35, blur: 30 }).addTo(mymap)
250 250
  }
251 251

  
252
  // timto vyresen bug #8191 - TODO: znamena to, ze muzeme smazat volani updatePopup() ve funkcich, kde se nejdriv vola drawHeatmap() a pak updatePopup()?
253 252
  updatePopup()
254 253
}
255 254

  
......
417 416
  info = []
418 417
  currentPageInPopup = 0
419 418

  
420
  // https://wiki.openstreetmap.org/wiki/Zoom_levels
421
  // Todo change to variable - it is used in heatmap init
422 419
  const stile = 40075016.686 * Math.cos(startX) / Math.pow(2, mymap.getZoom())
423 420
  const radius = 25 * stile / 256
424 421

  
website/templates/base.html.twig
4 4
    <meta charset="utf-8">
5 5
        
6 6
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7
    <meta name="description" content="Heatmapa kampusu Západočeské univerzity v Plzni">
8
    <meta name="keywords" content="heatmap, open data, otevřená data, dataset, západočeská univerzita, zču, plzeň">
9
    <meta name="author" content="Tým BHVS &ndash; Tomáš Ballák, Petr Hlaváč, Jakub Vašta, Martin Šebela">
7
    <meta name="description" content="">
8
    <meta name="keywords" content="">
10 9

  
11
    <meta property="og:url" content="https://heatmap.zcu.cz">
10
    <meta property="og:url" content="">
12 11
    <meta property="og:type" content="website">
13
    <meta property="og:title" content="Heatmapa kampusu Západočeské univerzity v Plzni">
14
    <meta property="og:description" content="Hodina po hodině, den po dni.">
15
    <meta property="og:image" content="https://heatmap.zcu.cz/img/banner.jpg">
12
    <meta property="og:title" content="">
13
    <meta property="og:description" content="">
14
    <meta property="og:image" content="">
16 15

  
17 16
    <link rel="shortcut icon" href="favicon.ico">
18 17

  
19 18
    <title>{% block title %}{% endblock %}</title>
20

  
21
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-CE7TFX9ZEL"></script>
22
    <script>
23
      window.dataLayer = window.dataLayer || [];
24
      function gtag(){dataLayer.push(arguments);}
25
      gtag('js', new Date());
26
      gtag('config', 'G-CE7TFX9ZEL');
27
    </script>
28 19
    
29 20
    {% block stylesheets %}{% endblock %}
30 21
    {% block style %}{% endblock %}
31
 </head>
32
 <body{% block bodyClass %}{% endblock %}>
22
  </head>
23
  <body{% block bodyClass %}{% endblock %}>
33 24
    {% block body %}{% endblock %}
34 25
    {% block javascripts %}{% endblock %}
35 26

  

Také k dispozici: Unified diff