-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce1edc1
commit 4cde87d
Showing
19 changed files
with
284 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from core.blueprints.base_blueprint import BaseBlueprint | ||
|
||
statistics_bp = BaseBlueprint('statistics', __name__, template_folder='templates') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("Hi, I am a script loaded from statistics module"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from flask_wtf import FlaskForm | ||
from wtforms import SubmitField | ||
|
||
|
||
class StatisticsForm(FlaskForm): | ||
submit = SubmitField('Save statistics') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from app import db | ||
|
||
|
||
class Statistics(db.Model): | ||
id = db.Column(db.Integer, primary_key=True) | ||
datasets_viewed = db.Column(db.Integer, default=0) | ||
feature_models_viewed = db.Column(db.Integer, default=0) | ||
datasets_downloaded = db.Column(db.Integer, default=0) | ||
feature_models_downloaded = db.Column(db.Integer, default=0) | ||
|
||
def __repr__(self): | ||
return ( | ||
f'Statistics<id={self.id}, datasets_viewed={self.datasets_viewed}, ' | ||
f'feature_models_viewed={self.feature_models_viewed}, datasets_downloaded={self.datasets_downloaded}, ' | ||
f'feature_models_downloaded={self.feature_models_downloaded}>' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from app.modules.statistics.models import Statistics | ||
from core.repositories.BaseRepository import BaseRepository | ||
|
||
|
||
class StatisticsRepository(BaseRepository): | ||
def __init__(self): | ||
super().__init__(Statistics) | ||
|
||
def get_statistics(self) -> Statistics: | ||
statistics = self.model.query.first() | ||
if statistics is None: | ||
# If no registry exists, create a new registry with default values | ||
statistics = Statistics(datasets_viewed=0, feature_models_viewed=0, | ||
datasets_downloaded=0, feature_models_downloaded=0) | ||
self.session.add(statistics) | ||
self.session.commit() | ||
return statistics | ||
|
||
# Incremental methods | ||
def increment_datasets_viewed(self) -> int: | ||
return self._increment_field('datasets_viewed') | ||
|
||
def increment_feature_models_viewed(self) -> int: | ||
return self._increment_field('feature_models_viewed') | ||
|
||
def increment_datasets_downloaded(self) -> int: | ||
return self._increment_field('datasets_downloaded') | ||
|
||
def increment_feature_models_downloaded(self) -> int: | ||
return self._increment_field('feature_models_downloaded') | ||
|
||
def _increment_field(self, field_name: str) -> int: | ||
statistics = self.get_statistics() | ||
current_value = getattr(statistics, field_name) | ||
new_value = current_value + 1 | ||
setattr(statistics, field_name, new_value) | ||
self.session.commit() | ||
return new_value | ||
|
||
# Consultation methods | ||
def get_datasets_viewed(self) -> int: | ||
statistics = self.get_statistics() | ||
return statistics.datasets_viewed | ||
|
||
def get_feature_models_viewed(self) -> int: | ||
statistics = self.get_statistics() | ||
return statistics.feature_models_viewed | ||
|
||
def get_datasets_downloaded(self) -> int: | ||
statistics = self.get_statistics() | ||
return statistics.datasets_downloaded | ||
|
||
def get_feature_models_downloaded(self) -> int: | ||
statistics = self.get_statistics() | ||
return statistics.feature_models_downloaded |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from flask import render_template | ||
from app.modules.statistics import statistics_bp | ||
|
||
|
||
@statistics_bp.route('/statistics', methods=['GET']) | ||
def index(): | ||
return render_template('statistics/index.html') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from app.modules.statistics.models import Statistics | ||
from core.seeders.BaseSeeder import BaseSeeder | ||
|
||
|
||
class StatisticsSeeder(BaseSeeder): | ||
|
||
def run(self): | ||
|
||
data = [ | ||
Statistics(datasets_viewed=0, feature_models_viewed=0, | ||
datasets_downloaded=0, feature_models_downloaded=0) | ||
] | ||
|
||
self.seed(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from app.modules.statistics.models import Statistics | ||
from app.modules.statistics.repositories import StatisticsRepository | ||
from core.services.BaseService import BaseService | ||
|
||
|
||
class StatisticsService(BaseService): | ||
def __init__(self): | ||
super().__init__(StatisticsRepository()) | ||
|
||
def get_statistics(self) -> Statistics: | ||
return self.repository.get_statistics() | ||
|
||
# Incremental methods | ||
def increment_datasets_viewed(self) -> int: | ||
return self.repository.increment_datasets_viewed() | ||
|
||
def increment_feature_models_viewed(self) -> int: | ||
return self.repository.increment_feature_models_viewed() | ||
|
||
def increment_datasets_downloaded(self) -> int: | ||
return self.repository.increment_datasets_downloaded() | ||
|
||
def increment_feature_models_downloaded(self) -> int: | ||
return self.repository.increment_feature_models_downloaded() | ||
|
||
# Consultation methods | ||
def get_datasets_viewed(self) -> int: | ||
return self.repository.get_datasets_viewed() | ||
|
||
def get_feature_models_viewed(self) -> int: | ||
return self.repository.get_feature_models_viewed() | ||
|
||
def get_datasets_downloaded(self) -> int: | ||
return self.repository.get_datasets_downloaded() | ||
|
||
def get_feature_models_downloaded(self) -> int: | ||
return self.repository.get_feature_models_downloaded() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends "base_template.html" %} | ||
|
||
{% block title %}View statistics{% endblock %} | ||
|
||
{% block content %} | ||
|
||
{% endblock %} | ||
|
||
{% block scripts %} | ||
<script src="{{ url_for('statistics.scripts') }}"></script> | ||
{% endblock %} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from locust import HttpUser, TaskSet, task | ||
from core.environment.host import get_host_for_locust_testing | ||
|
||
|
||
class StatisticsBehavior(TaskSet): | ||
def on_start(self): | ||
self.index() | ||
|
||
@task | ||
def index(self): | ||
response = self.client.get("/statistics") | ||
|
||
if response.status_code != 200: | ||
print(f"Statistics index failed: {response.status_code}") | ||
|
||
|
||
class StatisticsUser(HttpUser): | ||
tasks = [StatisticsBehavior] | ||
min_wait = 5000 | ||
max_wait = 9000 | ||
host = get_host_for_locust_testing() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from selenium.common.exceptions import NoSuchElementException | ||
import time | ||
|
||
from core.environment.host import get_host_for_selenium_testing | ||
from core.selenium.common import initialize_driver, close_driver | ||
|
||
|
||
def test_statistics_index(): | ||
|
||
driver = initialize_driver() | ||
|
||
try: | ||
host = get_host_for_selenium_testing() | ||
|
||
# Open the index page | ||
driver.get(f'{host}/statistics') | ||
|
||
# Wait a little while to make sure the page has loaded completely | ||
time.sleep(4) | ||
|
||
try: | ||
|
||
pass | ||
|
||
except NoSuchElementException: | ||
raise AssertionError('Test failed!') | ||
|
||
finally: | ||
|
||
# Close the browser | ||
close_driver(driver) | ||
|
||
|
||
# Call the test function | ||
test_statistics_index() |
Oops, something went wrong.