Skip to content

Commit

Permalink
Format natural datetime using pypi humanize package
Browse files Browse the repository at this point in the history
  • Loading branch information
prihoda committed Aug 10, 2021
1 parent 4231e5e commit fe10162
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ so you will have to restart the services after each code update.

#### 1. Install Docker

See https://docs.docker.com/docker-for-mac/install/
See https://docs.docker.com/get-docker/

#### 2. Build all images using Docker Compose

Expand Down Expand Up @@ -190,9 +190,9 @@ On Mac, you can [install Redis using Brew](https://medium.com/@petehouston/insta
# Install dependencies using the provided Makefile
make env
# Or directly using
conda env create -n biophi-dev -f environment.yml
conda activate biophi-dev
pip install -e .
conda env create -n biophi -f environment.yml
conda activate biophi
pip install -e . --no-deps
```

#### 4. Run all services
Expand Down
2 changes: 1 addition & 1 deletion biophi/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.0'
__version__ = '1.0.1'
2 changes: 1 addition & 1 deletion biophi/common/web/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h1 class="fs-2 fw-light mb-3">News</h1>
<div class="list-group-item">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{ item.title }}</h5>
<small>{{ item.date | humanize() }}</small>
<small>{{ item.date | naturalday }}</small>
</div>
<p class="mb-1">{{ item.body | safe }}</p>
</div>
Expand Down
6 changes: 3 additions & 3 deletions biophi/common/web/templates/stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h2>Past 24 hours</h2>
<div class="col-4">
<p class="lead">Last request errors</p>
{% for i, row in access_log[access_log['exception'].isna() == False][::-1].head().iterrows() %}
<div class="text-danger fs-smaller">{{ row.name | humanize() }}: {{ row['exception'][:50] + ('...' if (row['exception'] | length) > 50 else '') }}</div>
<div class="text-danger fs-smaller">{{ row.name | naturaltime }}: {{ row['exception'][:50] + ('...' if (row['exception'] | length) > 50 else '') }}</div>
{% endfor %}
</div>
<div class="col-5">
Expand All @@ -92,7 +92,7 @@ <h2>Past 24 hours</h2>
<div class="col-4">
<p class="lead">Last task errors</p>
{% for i, row in task_log[task_log['exception'].isna() == False][::-1].head().iterrows() %}
<div class="text-danger fs-smaller">{{ row.name | humanize() }}: {{ row['exception'][:50] + ('...' if (row['exception'] | length) > 50 else '') }}</div>
<div class="text-danger fs-smaller">{{ row.name | naturaltime }}: {{ row['exception'][:50] + ('...' if (row['exception'] | length) > 50 else '') }}</div>
{% endfor %}
</div>
<div class="col-5">
Expand All @@ -114,7 +114,7 @@ <h2>Past 24 hours</h2>
</div>
</div>
<div class="col-{{ key_width }} fs-smaller">
{{ key | humanize() }}
{{ key | naturaltime }}
</div>
</div>
{% endfor %}
Expand Down
16 changes: 12 additions & 4 deletions biophi/common/web/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import datetime
import json

import humanize
from Bio.SeqUtils import seq3
from flask_humanize import Humanize
import pandas as pd
from markupsafe import Markup
from werkzeug.urls import url_encode
Expand Down Expand Up @@ -45,9 +46,6 @@
app.jinja_env.globals.update(max=max)


# Enable human-readable date functions
humanize = Humanize(app)

app.register_blueprint(biophi_humanization, url_prefix='/humanization')

use_scheduler('celery')
Expand Down Expand Up @@ -128,6 +126,16 @@ def info_icon(text, filled=False, secondary=True, delay=100, s=16):
f'data-bs-delay="{delay}" data-bs-toggle="tooltip" title="{text}">{icon(name, s=s)}</span>')


@app.template_filter()
def naturalday(v):
return humanize.naturalday(v)


@app.template_filter()
def naturaltime(v):
return humanize.naturaltime(v)


@app.template_global()
def big_number_format(num, precision=1):
if pd.isna(num) or num is None:
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ dependencies:
- requests
- tqdm
- xlsxwriter
- flask-humanize
- humanize
- fairseq == 0.10.2

0 comments on commit fe10162

Please sign in to comment.