-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
77cda42
commit 211d970
Showing
55 changed files
with
799 additions
and
790 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
11 changes: 0 additions & 11 deletions
11
infrastructure/migrations/20180308_01_zvLE8-add-projects-table.py
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
infrastructure/migrations/20180602_01_pwfJI-add-downloads-per-day-table.py
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
|
||
[webservers] | ||
root@174.138.5.205 ansible_python_interpreter=/usr/bin/python3 | ||
root@88.99.125.23 ansible_python_interpreter=/usr/bin/python3 |
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,20 @@ | ||
--- | ||
|
||
# https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ | ||
- block: | ||
- name: Import MongoDB public GPG Key | ||
apt_key: | ||
url: https://www.mongodb.org/static/pgp/server-4.2.asc | ||
- name: Add MongoDB repository into sources list | ||
apt_repository: | ||
repo: deb http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse | ||
state: present | ||
- name: Install MongoDB package | ||
apt: | ||
name: mongodb-org | ||
update_cache: yes | ||
- name: Make sure mongo is running | ||
systemd: | ||
state: started | ||
name: mongod | ||
enabled: yes |
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 was deleted.
Oops, something went wrong.
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
10 changes: 8 additions & 2 deletions
10
infrastructure/playbooks/roles/web/tasks/install_dependencies.yml
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
--- | ||
- include: copy_code.yml | ||
- include: install_dependencies.yml | ||
- include: migrations.yml | ||
- include: webserver.yml | ||
- include: supervisor.yml | ||
- include: crons.yml |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
50 changes: 22 additions & 28 deletions
50
pepy/application/query.py → pepy/application/badge_service.py
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 |
---|---|---|
@@ -1,63 +1,57 @@ | ||
import math | ||
from typing import List | ||
from datetime import datetime, timedelta | ||
|
||
import requests | ||
|
||
from pepy.domain.exception import ProjectNotFoundException | ||
from pepy.domain.model import Badge | ||
from pepy.domain.read_model import ProjectProjection, ProjectListProjection | ||
from pepy.domain.view import ProjectView | ||
from pepy.domain.model import Badge, Project, Downloads | ||
from pepy.domain.repository import ProjectRepository | ||
|
||
|
||
class DownloadsNumberFormatter: | ||
_METRIC_PREFIX = ["", "k", "M", "G", "T", "P"] | ||
|
||
def format(self, downloads: int) -> str: | ||
digits = int(math.log10(abs(downloads)) if downloads else 0) | ||
def format(self, downloads: Downloads) -> str: | ||
digits = int(math.log10(abs(downloads.value)) if downloads else 0) | ||
millidx = max(0, min(len(self._METRIC_PREFIX) - 1, digits // 3)) | ||
rounded_value = downloads // (10 ** (3 * millidx)) | ||
rounded_value = downloads.value // (10 ** (3 * millidx)) | ||
return "{}{}".format(rounded_value, self._METRIC_PREFIX[millidx]) | ||
|
||
|
||
class BadgeProvider: | ||
def __init__(self, project_view: ProjectView, downloads_formatter: DownloadsNumberFormatter): | ||
self._project_repository = project_view | ||
class BadgeService: | ||
def __init__(self, project_repository: ProjectRepository, downloads_formatter: DownloadsNumberFormatter): | ||
self._project_repository = project_repository | ||
self._downloads_formatter = downloads_formatter | ||
|
||
def generate_badge(self, project_name: str) -> Badge: | ||
project = self._project_repository.find(project_name) | ||
project = self._project_repository.get(project_name) | ||
if project is None: | ||
raise ProjectNotFoundException(project_name) | ||
downloads = self._downloads_formatter.format(project.total_downloads) | ||
r = requests.get("https://img.shields.io/badge/downloads-{}-blue.svg".format(downloads)) | ||
return Badge(project_name, r.content.decode("utf-8")) | ||
|
||
def generate_last_30_days_badge(self, project_name: str) -> Badge: | ||
project = self._project_repository.find(project_name) | ||
project = self._project_repository.get(project_name) | ||
if project is None: | ||
raise ProjectNotFoundException(project_name) | ||
downloads = self._downloads_formatter.format(project.total_downloads_last_30_days) | ||
downloads = self._downloads_formatter.format(self._last_downloads(project, 30)) | ||
r = requests.get("https://img.shields.io/badge/downloads/month-{}-blue.svg".format(downloads)) | ||
return Badge(project_name, r.content.decode("utf-8")) | ||
|
||
def generate_last_7_days_badge(self, project_name: str) -> Badge: | ||
project = self._project_repository.find(project_name) | ||
project = self._project_repository.get(project_name) | ||
if project is None: | ||
raise ProjectNotFoundException(project_name) | ||
downloads = self._downloads_formatter.format(project.total_downloads_last_7_days) | ||
downloads = self._downloads_formatter.format(self._last_downloads(project, 7)) | ||
r = requests.get("https://img.shields.io/badge/downloads/week-{}-blue.svg".format(downloads)) | ||
return Badge(project_name, r.content.decode("utf-8")) | ||
|
||
|
||
class ProjectProvider: | ||
def __init__(self, project_view: ProjectView): | ||
self._project_view = project_view | ||
|
||
def find(self, project_name: str) -> ProjectProjection: | ||
project = self._project_view.find(project_name) | ||
if project is None: | ||
raise ProjectNotFoundException(project_name) | ||
return project | ||
|
||
def for_home(self) -> List[ProjectListProjection]: | ||
return self._project_view.find_random_projects(10) | ||
@staticmethod | ||
def _last_downloads(project: Project, days: int) -> Downloads: | ||
min_date = datetime.now().date() - timedelta(days=days) | ||
total_downloads = 0 | ||
for d in project.last_downloads(): | ||
if d.date >= min_date: | ||
total_downloads += d.downloads.value | ||
return Downloads(total_downloads) |
Oops, something went wrong.