Browse Source

Analytics project structure improvement #215 (#228)

* bin & analytics folders

* sys path & config relocation

* fix analytics path in node
pull/1/head
Alexey Velikiy 6 years ago committed by GitHub
parent
commit
005097dde0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      analytics/Compilation.md
  2. 2
      analytics/Dockerfile
  3. 0
      analytics/analytics/analytic_unit_manager.py
  4. 0
      analytics/analytics/analytic_unit_worker.py
  5. 4
      analytics/analytics/config.py
  6. 0
      analytics/analytics/detectors/__init__.py
  7. 0
      analytics/analytics/detectors/detector.py
  8. 0
      analytics/analytics/detectors/pattern_detector.py
  9. 0
      analytics/analytics/models/__init__.py
  10. 0
      analytics/analytics/models/custom_model.py
  11. 0
      analytics/analytics/models/drop_model.py
  12. 0
      analytics/analytics/models/general_model.py
  13. 0
      analytics/analytics/models/jump_model.py
  14. 0
      analytics/analytics/models/model.py
  15. 0
      analytics/analytics/models/peak_model.py
  16. 0
      analytics/analytics/models/trough_model.py
  17. 0
      analytics/analytics/services/__init__.py
  18. 0
      analytics/analytics/services/data_service.py
  19. 0
      analytics/analytics/services/server_service.py
  20. 2
      analytics/analytics/utils/__init__.py
  21. 0
      analytics/analytics/utils/common.py
  22. 2
      analytics/analytics/utils/segments.py
  23. 13
      analytics/bin/server
  24. 1
      analytics/tests/test_utils.py
  25. 2
      analytics/utils/__init__.py
  26. 6
      server/src/services/analytics_service.ts

2
analytics/Compilation.md

@ -7,6 +7,6 @@ Compiled module is supported by all *nix systems.
```bash
pip3 install pyinstaller
cd $HASTIC_SERVER_PATH/analytics
pyinstaller --additional-hooks-dir=pyinstaller_hooks server.py
pyinstaller --additional-hooks-dir=pyinstaller_hooks bin/server
```

2
analytics/Dockerfile

@ -17,4 +17,4 @@ VOLUME [ "/var/www/data" ]
COPY . /var/www/analytics/
CMD ["python", "server.py"]
CMD ["python", "bin/server"]

0
analytics/analytic_unit_manager.py → analytics/analytics/analytic_unit_manager.py

0
analytics/analytic_unit_worker.py → analytics/analytics/analytic_unit_worker.py

4
analytics/config.py → analytics/analytics/config.py

@ -2,7 +2,7 @@ import os
import json
PARENT_FOLDER = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
PARENT_FOLDER = os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
CONFIG_FILE = os.path.join(PARENT_FOLDER, 'config.json')
@ -10,6 +10,8 @@ config_exists = os.path.isfile(CONFIG_FILE)
if config_exists:
with open(CONFIG_FILE) as f:
config = json.load(f)
else:
print('Config file %s doesn`t exist, using defaults' % CONFIG_FILE)
def get_config_field(field, default_val = None):

0
analytics/detectors/__init__.py → analytics/analytics/detectors/__init__.py

0
analytics/detectors/detector.py → analytics/analytics/detectors/detector.py

0
analytics/detectors/pattern_detector.py → analytics/analytics/detectors/pattern_detector.py

0
analytics/models/__init__.py → analytics/analytics/models/__init__.py

0
analytics/models/custom_model.py → analytics/analytics/models/custom_model.py

0
analytics/models/drop_model.py → analytics/analytics/models/drop_model.py

0
analytics/models/general_model.py → analytics/analytics/models/general_model.py

0
analytics/models/jump_model.py → analytics/analytics/models/jump_model.py

0
analytics/models/model.py → analytics/analytics/models/model.py

0
analytics/models/peak_model.py → analytics/analytics/models/peak_model.py

0
analytics/models/trough_model.py → analytics/analytics/models/trough_model.py

0
analytics/services/__init__.py → analytics/analytics/services/__init__.py

0
analytics/services/data_service.py → analytics/analytics/services/data_service.py

0
analytics/services/server_service.py → analytics/analytics/services/server_service.py

2
analytics/analytics/utils/__init__.py

@ -0,0 +1,2 @@
from utils.common import *
from utils.segments import *

0
analytics/utils/common.py → analytics/analytics/utils/common.py

2
analytics/utils/segments.py → analytics/analytics/utils/segments.py

@ -1,6 +1,6 @@
import pandas as pd
from common import timestamp_to_index
from utils.common import timestamp_to_index
def parse_segment(segment, dataframe):
start = timestamp_to_index(dataframe, pd.to_datetime(segment['from'], unit='ms'))

13
analytics/server.py → analytics/bin/server

@ -1,13 +1,16 @@
#!/usr/bin/env python3
import sys
import os
#TODO: make wrapper script that set PYTHONPATH instead
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'analytics'))
import config
import json
import logging
import sys
import asyncio
import traceback
import os
#TODO: make wrapper script that set PYTHONPATH instead
sys.path.append(os.path.join(os.path.dirname(__file__), 'utils'))
import services
from analytic_unit_manager import handle_analytic_task

1
analytics/tests/test_utils.py

@ -7,6 +7,5 @@ class TestUtils(unittest.TestCase):
self.assertTrue(True)
if __name__ == '__main__':
unittest.main()

2
analytics/utils/__init__.py

@ -1,2 +0,0 @@
from common import *
from segments import *

6
server/src/services/analytics_service.ts

@ -122,10 +122,12 @@ export class AnalyticsService {
console.log('dist/server/server');
cp = childProcess.spawn('dist/server/server', [], cpOptions);
} else {
console.log('python3 server.py');
const ANALYTICS_SERVER_PATH = path.join('bin', 'server');
console.log('python3 ' + ANALYTICS_SERVER_PATH);
// If compiled analytics script doesn't exist - fallback to regular python
console.log(config.ANALYTICS_PATH);
cp = childProcess.spawn('python3', ['server.py'], cpOptions);
// maybe starting it via bash better that put python3
cp = childProcess.spawn('python3', [ANALYTICS_SERVER_PATH], cpOptions);
}
if(cp.pid === undefined) {

Loading…
Cancel
Save