Skip to content

Commit

Permalink
Release v1.1.1
Browse files Browse the repository at this point in the history
Changelog:

1. Change the webpage hit counter to a custom database retrieve counter
  • Loading branch information
az7jh2 committed Nov 6, 2021
1 parent 6da7857 commit 1d04aa9
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 44 deletions.
1 change: 1 addition & 0 deletions static/count.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
52 changes: 44 additions & 8 deletions tRFapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import json
import os
import pandas as pd
from multiprocessing import Value


#####################数据库相关##################################################
Expand Down Expand Up @@ -461,6 +462,37 @@ def doSearch(search_organism, search_table, search_type, search_item, mfe_th, le
dtype = {'Site_Level': str, 'Gene_Level': str,
'Functionality Study Refs': str})

# define a function to get value from count file
def get_val_from_file():
# read saved count value
with open(r'./static/count.txt') as f:
# read all lines into a list
count_num = f.readlines()
assert(len(count_num) == 1)
return int(count_num[0])

# define a counter shared by thread based on a multiprocessing value for thread-safe operations
# but it does not work well

class counter_obj(object):
def __init__(self):
# read saved count value
self.val = Value('i', get_val_from_file())

def increment(self):
with self.val.get_lock():
tmp_value = int(get_val_from_file() + 1)
# save result
with open(r'./static/count.txt', 'w') as f:
f.write(str(tmp_value))

def get_value(self):
with self.val.get_lock():
# return the value in counter file
return get_val_from_file()

my_counter = counter_obj()


def transform(string):
'''replace nan with None
Expand Down Expand Up @@ -582,20 +614,20 @@ def favicon():
# Home page
@app.route('/')
def index():
return render_template('index.html')
return render_template('index.html', count=my_counter.get_value())

# Other pages
@app.route('/<string:page>')
def show(page):
return render_template('{}.html'.format(page))
return render_template('{}.html'.format(page), count=my_counter.get_value())

# Evidence page
@app.route('/evidence')
def evidence():

th_list = ['Organism', 'tRF ID', 'Transcript', 'Gene',
'Gene Level Evidence', 'Site Level Evidence', 'Functionality/Disease Study Refs']
return render_template('evidence.html', th_list=th_list, td_list = EVI_LIST)
return render_template('evidence.html', th_list=th_list, td_list = EVI_LIST, count=my_counter.get_value())

# Search database
@app.route('/search', methods=['GET', 'POST'])
Expand All @@ -616,6 +648,10 @@ def search():


if form.validate_on_submit() and request.method == 'POST':

# one search, count += 1
my_counter.increment()

search_type = form.search_type.data
search_organism = form.search_organism.data

Expand All @@ -630,7 +666,7 @@ def search():
if len(search_regions) < 1:
success = False
for_print = 'Please select at least one binding region!'
return render_template('search.html', form=form, success=success, for_print=for_print, display_table=False)
return render_template('search.html', form=form, success=success, for_print=for_print, display_table=False, count=my_counter.get_value())

if search_type == 'trf':
search_item = form.trf.data
Expand All @@ -643,7 +679,7 @@ def search():
# search item is null
success = False
for_print = 'Invalid search way.\nPlease select the correct search way!'
return render_template('search.html', form=form, success=success, for_print=for_print, display_table=False)
return render_template('search.html', form=form, success=success, for_print=for_print, display_table=False, count=my_counter.get_value())

# Do search
td_list = doSearch(search_organism, form.search_table.data,
Expand Down Expand Up @@ -673,15 +709,15 @@ def search():
return render_template('search.html', form=form, success=success,
for_print=for_print, th_list=th_list,
td_list = td_list, display_table=True,
show_pathway = show_pathway)
show_pathway = show_pathway, count=my_counter.get_value())
else:
success = False
for_print = 'No {} results for {}: {}'.format(form.search_table.data,
search_type.upper(), search_item) + filter_infos

return render_template('search.html', form=form, success=success, for_print=for_print, display_table=False)
return render_template('search.html', form=form, success=success, for_print=for_print, display_table=False, count=my_counter.get_value())

return render_template('search.html', form=form, display_table=False)
return render_template('search.html', form=form, display_table=False, count=my_counter.get_value())

if __name__ == '__main__':
# 对应intenal IP
Expand Down
7 changes: 2 additions & 5 deletions templates/evidence.html
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,11 @@ <h3>List of exprimental evidence for tRF targets</h3>

<div class="row mx-auto">
<div class="col" style="padding-right: 0px">
<p style="margin-top: 0px; margin-right: 0px; text-align: right">
<!-- hitwebcounter Code START -->
<a href="https://www.hitwebcounter.com" target="_blank">
<img src="https://hitwebcounter.com/counter/counter.php?page=7889155&style=0006&nbdigits=9&type=page&initCount=0" title="Free Counter" Alt="web counter" border="0" /></a></p>
<p style="margin-top: 0px; margin-right: 0px; text-align: right; color: white; font-weight: bold">{{ count }}</p>
</div>

<div class="col" style="padding-left: 5px">
<p style="margin-top: 0px; margin-left: 0px; text-align: left">Total Hits</p>
<p style="margin-top: 0px; margin-left: 0px; text-align: left">Total Database Retrieves</p>
</div>
</div>

Expand Down
9 changes: 3 additions & 6 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,11 @@ <h3>Contact Us</h3>

<div class="row mx-auto">
<div class="col" style="padding-right: 0px">
<p style="margin-top: 0px; margin-right: 0px; text-align: right">
<!-- hitwebcounter Code START -->
<a href="https://www.hitwebcounter.com" target="_blank">
<img src="https://hitwebcounter.com/counter/counter.php?page=7889155&style=0006&nbdigits=9&type=page&initCount=0" title="Free Counter" Alt="web counter" border="0" /></a></p>
<p style="margin-top: 0px; margin-right: 0px; text-align: right; color: white; font-weight: bold">{{ count }}</p>
</div>

<div class="col" style="padding-left: 5px">
<p style="margin-top: 0px; margin-left: 0px; text-align: left">Total Hits</p>
<p style="margin-top: 0px; margin-left: 0px; text-align: left">Total Database Retrieves</p>
</div>
</div>

Expand All @@ -163,7 +160,7 @@ <h3>Contact Us</h3>
<p style="margin-top: 0px; margin-right: 0px; text-align: right">
<!-- hitwebcounter Code START -->
<a href="https://www.hitwebcounter.com" target="_blank">
<img src="https://hitwebcounter.com/counter/counter.php?page=7737095&style=0006&nbdigits=9&type=ip&initCount=0" title="Free Counter" Alt="web counter" border="0" /></a></p>
<img src="https://hitwebcounter.com/counter/counter.php?page=7737095&style=0006&nbdigits=7&type=ip&initCount=0" title="Free Counter" Alt="web counter" border="0" /></a></p>
</div>

<div class="col" style="padding-left: 5px">
Expand Down
7 changes: 2 additions & 5 deletions templates/manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,11 @@ <h3>Definition of consensus entries in <i>RNAhybrid</i> and <i>IntaRNA</i> predi

<div class="row mx-auto">
<div class="col" style="padding-right: 0px">
<p style="margin-top: 0px; margin-right: 0px; text-align: right">
<!-- hitwebcounter Code START -->
<a href="https://www.hitwebcounter.com" target="_blank">
<img src="https://hitwebcounter.com/counter/counter.php?page=7889155&style=0006&nbdigits=9&type=page&initCount=0" title="Free Counter" Alt="web counter" border="0" /></a></p>
<p style="margin-top: 0px; margin-right: 0px; text-align: right; color: white; font-weight: bold">{{ count }}</p>
</div>

<div class="col" style="padding-left: 5px">
<p style="margin-top: 0px; margin-left: 0px; text-align: left">Total Hits</p>
<p style="margin-top: 0px; margin-left: 0px; text-align: left">Total Database Retrieves</p>
</div>
</div>

Expand Down
7 changes: 2 additions & 5 deletions templates/method.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,11 @@ <h4>IntaRNA</h4>

<div class="row mx-auto">
<div class="col" style="padding-right: 0px">
<p style="margin-top: 0px; margin-right: 0px; text-align: right">
<!-- hitwebcounter Code START -->
<a href="https://www.hitwebcounter.com" target="_blank">
<img src="https://hitwebcounter.com/counter/counter.php?page=7889155&style=0006&nbdigits=9&type=page&initCount=0" title="Free Counter" Alt="web counter" border="0" /></a></p>
<p style="margin-top: 0px; margin-right: 0px; text-align: right; color: white; font-weight: bold">{{ count }}</p>
</div>

<div class="col" style="padding-left: 5px">
<p style="margin-top: 0px; margin-left: 0px; text-align: left">Total Hits</p>
<p style="margin-top: 0px; margin-left: 0px; text-align: left">Total Database Retrieves</p>
</div>
</div>

Expand Down
7 changes: 2 additions & 5 deletions templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,11 @@ <h4 class="d-inline-block align-middle text-success">Use top {{ form.mrna_num(cl

<div class="row mx-auto">
<div class="col" style="padding-right: 0px">
<p style="margin-top: 0px; margin-right: 0px; text-align: right">
<!-- hitwebcounter Code START -->
<a href="https://www.hitwebcounter.com" target="_blank">
<img src="https://hitwebcounter.com/counter/counter.php?page=7889155&style=0006&nbdigits=9&type=page&initCount=0" title="Free Counter" Alt="web counter" border="0" /></a></p>
<p style="margin-top: 0px; margin-right: 0px; text-align: right; color: white; font-weight: bold">{{ count }}</p>
</div>

<div class="col" style="padding-left: 5px">
<p style="margin-top: 0px; margin-left: 0px; text-align: left">Total Hits</p>
<p style="margin-top: 0px; margin-left: 0px; text-align: left">Total Database Retrieves</p>
</div>
</div>

Expand Down
7 changes: 2 additions & 5 deletions templates/statistics.html
Original file line number Diff line number Diff line change
Expand Up @@ -643,14 +643,11 @@ <h4>Zebrafish</h4>

<div class="row mx-auto">
<div class="col" style="padding-right: 0px">
<p style="margin-top: 0px; margin-right: 0px; text-align: right">
<!-- hitwebcounter Code START -->
<a href="https://www.hitwebcounter.com" target="_blank">
<img src="https://hitwebcounter.com/counter/counter.php?page=7889155&style=0006&nbdigits=9&type=page&initCount=0" title="Free Counter" Alt="web counter" border="0" /></a></p>
<p style="margin-top: 0px; margin-right: 0px; text-align: right; color: white; font-weight: bold">{{ count }}</p>
</div>

<div class="col" style="padding-left: 5px">
<p style="margin-top: 0px; margin-left: 0px; text-align: left">Total Hits</p>
<p style="margin-top: 0px; margin-left: 0px; text-align: left">Total Database Retrieves</p>
</div>
</div>

Expand Down
7 changes: 2 additions & 5 deletions templates/team.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,11 @@ <h5>Ningshan Li, ME</h5>

<div class="row mx-auto">
<div class="col" style="padding-right: 0px">
<p style="margin-top: 0px; margin-right: 0px; text-align: right">
<!-- hitwebcounter Code START -->
<a href="https://www.hitwebcounter.com" target="_blank">
<img src="https://hitwebcounter.com/counter/counter.php?page=7889155&style=0006&nbdigits=9&type=page&initCount=0" title="Free Counter" Alt="web counter" border="0" /></a></p>
<p style="margin-top: 0px; margin-right: 0px; text-align: right; color: white; font-weight: bold">{{ count }}</p>
</div>

<div class="col" style="padding-left: 5px">
<p style="margin-top: 0px; margin-left: 0px; text-align: left">Total Hits</p>
<p style="margin-top: 0px; margin-left: 0px; text-align: left">Total Database Retrieves</p>
</div>
</div>

Expand Down

0 comments on commit 1d04aa9

Please sign in to comment.