Skip to content
This repository has been archived by the owner on Jul 29, 2020. It is now read-only.

Commit

Permalink
Merge b250d16 into 58b1e81
Browse files Browse the repository at this point in the history
  • Loading branch information
wasade committed Mar 15, 2019
2 parents 58b1e81 + b250d16 commit 1f56a54
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 2 deletions.
31 changes: 31 additions & 0 deletions knimin/handlers/barcode_util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
from tornado.web import authenticated
from tornado.escape import json_encode
from knimin.handlers.base import BaseHandler
from datetime import datetime

Expand Down Expand Up @@ -172,8 +173,35 @@ def _build_email(self, login_user, barcode, email_type,
return subject, body_message


@set_access(['Scan Barcodes'])
class PushQiitaHandler(BaseHandler):
@authenticated
def get(self):
barcodes = db.get_unsent_barcodes_from_qiita_buffer()
status = db.get_send_qiita_buffer_status()
dat = {'status': status, "barcodes": barcodes}
self.write(json_encode(dat))
self.finish()

@authenticated
def post(self):
barcodes = db.get_unsent_barcodes_from_qiita_buffer()
db.set_send_qiita_buffer_status("Pushing...")

try:
print("Sending: %s" % str(barcodes))
except:
db.set_send_qiita_buffer_status("Failed!")
else:
db.mark_barcodes_sent_to_qiita(barcodes)
db.set_send_qiita_buffer_status("Idle")

self.finish()


@set_access(['Scan Barcodes'])
class BarcodeUtilHandler(BaseHandler, BarcodeUtilHelper):

@authenticated
def get(self):
barcode = self.get_argument('barcode', None)
Expand Down Expand Up @@ -293,9 +321,12 @@ def post(self):

new_proj, parent_project = db.getBarcodeProjType(barcode)
if parent_project == 'American Gut':
db.push_barcode_to_qiita_buffer(barcode)

email_msg, ag_update_msg = self.update_ag_barcode(
barcode, login_user, login_email, email_type, sent_date,
send_mail, sample_date, sample_time, other_text)

self.render("barcode_util.html", div_and_msg=None,
barcode_projects=[],
parent_project=None,
Expand Down
54 changes: 54 additions & 0 deletions knimin/lib/data_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,60 @@ def getAGKitDetails(self, supplied_kit_id):
else:
return {}

def push_barcode_to_qiita_buffer(self, barcode):
"""Adds barcode to the qiita buffer
Parameters
----------
barcode : str
The identifier to stage
"""
sql = """SELECT barcode
FROM project_qiita_buffer"""
present = {i[0] for i in self._con.execute_fetchall(sql)}

if barcode in present:
return "Barcode in queue or already sent to Qiita"

else:
sql = """INSERT INTO project_qiita_buffer (barcode)
VALUES (%s)"""
self._con.execute(sql, [barcode])
return "Barcode inserted"

def get_send_qiita_buffer_status(self):
"""Obtain the present status of the Qiita submission buffer"""
sql = """SELECT state FROM project_qiita_buffer_status"""
return self._con.execute_fetchone(sql)

def set_send_qiita_buffer_status(self, state):
"""Obtain the present status of the Qiita submission buffer"""
sql = """UPDATE project_qiita_buffer_status
SET state = %s
WHERE id = 0"""
self._con.execute(sql, [state])

def get_unsent_barcodes_from_qiita_buffer(self):
"""Extract the barcodes that have not been sent to Qiita"""
sql = """SELECT barcode
FROM project_qiita_buffer
WHERE pushed_to_qiita='N'"""
return [i[0] for i in self._con.execute_fetchall(sql)]

def mark_barcodes_sent_to_qiita(self, barcodes):
"""Mark the provided barcodes as sent
Parameters
----------
barcodes : list of str
The identifiers to mark a successfully sent to qiita
"""
if barcodes:
sql = """UPDATE project_qiita_buffer
SET pushed_to_qiita = 'Y'
WHERE barcode IN %s"""
self._con.execute(sql, [tuple(barcodes)])

def add_barcodes_to_kit(self, ag_kit_id, num_barcodes=1):
"""Attaches barcodes to an existing american gut kit
Expand Down
20 changes: 20 additions & 0 deletions knimin/static/css/qiime.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ html, body {
width: 200px;
}

#qiita_buffer_window {
position: fixed;
top: 8px;
right: 8px;
margin: 8px;
background: #fff;
opacity: 0.8;
padding: 8px;
border: 2px black solid;
border-radius: 5px;
font: 15px normal Arial, Helvetica, sans-serif;
word-wrap: break-word;
width: 300px;
}

.login {
float:left;
margin: 8px;
Expand Down Expand Up @@ -294,6 +309,11 @@ h2.verification_text{
width: 100%;
}

h3.qiita_buffer_warning_text{
font-style: italic;
width: 100%;
}

#invalid_barcode {
background-color: #f00;
}
Expand Down
56 changes: 55 additions & 1 deletion knimin/templates/barcode_util.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,51 @@
}
});
});

function update_qiita_buffer(data, status) {
// update the buffer sending status and the buffer level
document.getElementById("qiita_buffer_status").innerHTML = "Send status: " + data['status'];
document.getElementById("qiita_buffer_level").innerHTML = "Samples queued: " + data['barcodes'].length;
console.log(status);
}

function immediate_update_qiita_buffer() {
// immediate update of buffer and status
$.get("/notify-qiita/", function(data, status) {
data = JSON.parse(data);
update_qiita_buffer(data, status);
} );
}

function submit_qiita_buffer() {
// issue a request to the knimin server to push data to qiita
$.post("/notify-qiita/", function(data, status) {
console.log("POST /notify-qiita/");
console.log(data);
console.log(status);
} );
immediate_update_qiita_buffer();
}

(function poll() {
// poll for buffer and submission status on a 5 second interval
setTimeout(function() {
$.ajax({
url: "/notify-qiita/",
type: "GET",
success: function(data, status) {
console.log("polling");
update_qiita_buffer(data, status);
},
dataType: "json",
complete: poll,
timeout: 5000
})
}, 5000);
})();

immediate_update_qiita_buffer();

</script>
{% end %}

Expand Down Expand Up @@ -42,7 +87,16 @@ <h3>Barcode Scanner </h3>
document.check_barcode.barcode.focus()
</script>
</form>
<div>
</div>

<div id="qiita_buffer_window">
<h3 id="qiita_buffer_level">Samples queued: refreshing...</h3>
<h3 id="qiita_buffer_status">Send status: refreshing...</h3>
<h3 class="qiita_buffer_warning_text">
Note: queued samples will be inaccessible to LabControl <br>
</h3>
<button onClick="submit_qiita_buffer()">Send to Qiita</button>
</div>

{% if barcode is not None%}
<div id="{{div_and_msg[0]}}" class="verification_color">
Expand Down
3 changes: 2 additions & 1 deletion knimin/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from knimin.handlers.auth_handlers import AuthLoginHandler, AuthLogoutHandler
from knimin.handlers.ag_search import AGSearchHandler
from knimin.handlers.logged_in_index import LoggedInIndexHandler
from knimin.handlers.barcode_util import BarcodeUtilHandler
from knimin.handlers.barcode_util import BarcodeUtilHandler, PushQiitaHandler
from knimin.handlers.ag_stats import AGStatsHandler
from knimin.handlers.ag_edit_participant import AGEditParticipantHandler
from knimin.handlers.ag_new_kit import AGNewKitHandler, AGNewKitDLHandler
Expand Down Expand Up @@ -53,6 +53,7 @@ def __init__(self):
(r"/logged_in_index/", LoggedInIndexHandler),
(r"/ag_search/", AGSearchHandler),
(r"/barcode_util/", BarcodeUtilHandler),
(r"/notify-qiita/", PushQiitaHandler),
(r"/ag_add_barcode_kit/", AGAddBarcodeKitHandler),
(r"/ag_stats/", AGStatsHandler),
(r"/ag_edit_participant/", AGEditParticipantHandler),
Expand Down

0 comments on commit 1f56a54

Please sign in to comment.