Commit 5dc64728 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Add table to gallery, Implements #112

parent 584b40ec
...@@ -56,6 +56,8 @@ def parse_args(): ...@@ -56,6 +56,8 @@ def parse_args():
gallery_add.add_argument("-i", "--id-job", type=str, required=True, gallery_add.add_argument("-i", "--id-job", type=str, required=True,
help="Id (name) of the job to add to the gallery") help="Id (name) of the job to add to the gallery")
gallery_add.add_argument("-n", "--name", type=str, required=True, help="Name to show in the gallery for the job") gallery_add.add_argument("-n", "--name", type=str, required=True, help="Name to show in the gallery for the job")
gallery_add.add_argument("-q", "--query", type=str, required=True, help="Name of the query")
gallery_add.add_argument("-t", "--target", type=str, required=True, help="Name of the target")
gallery_add.add_argument("-p", "--pict", type=str, required=True, help="Name of the file that illustrate the job") gallery_add.add_argument("-p", "--pict", type=str, required=True, help="Name of the file that illustrate the job")
# Gallery del: # Gallery del:
...@@ -163,18 +165,19 @@ def clear_jobs(max_data_age=7): ...@@ -163,18 +165,19 @@ def clear_jobs(max_data_age=7):
print("") print("")
def add_to_gallery(id_job, name, picture): def add_to_gallery(id_job, name, picture, query, target):
try: try:
job = Job.get(id_job=id_job) job = Job.get(id_job=id_job)
except DoesNotExist: except DoesNotExist:
print("Error: job \"%s\" does not exists!" % id_job) print("Error: job \"%s\" does not exists!" % id_job)
exit(1) exit(1)
pict_file = os.path.join(config.app_data, "gallery", picture) else:
if not os.path.exists(pict_file): pict_file = os.path.join(config.app_data, "gallery", picture)
print("Error: file \"%s\" does not exists!" % pict_file) if not os.path.exists(pict_file):
exit(1) print("Error: file \"%s\" does not exists!" % pict_file)
item = Gallery.create(job=job, name=name, picture=picture) exit(1)
item.save() item = Gallery.create(job=job, name=name, picture=picture, query=query, target=target)
item.save()
def del_from_gallery_by_id(id_job): def del_from_gallery_by_id(id_job):
...@@ -210,7 +213,7 @@ if __name__ == "__main__": ...@@ -210,7 +213,7 @@ if __name__ == "__main__":
print("Cleaning jobs...") print("Cleaning jobs...")
clear_jobs(args.max_age) clear_jobs(args.max_age)
elif command == "gallery_add": elif command == "gallery_add":
add_to_gallery(args.id_job, args.name, args.pict) add_to_gallery(args.id_job, args.name, args.pict, args.query, args.target)
elif command == "gallery_del": elif command == "gallery_del":
if args.id_job is None and args.name is None: if args.id_job is None and args.name is None:
print("Error: please give an id or a name for the job!") print("Error: please give an id or a name for the job!")
......
...@@ -68,6 +68,8 @@ class Job(BaseModel): ...@@ -68,6 +68,8 @@ class Job(BaseModel):
class Gallery(BaseModel): class Gallery(BaseModel):
job = ForeignKeyField(Job) job = ForeignKeyField(Job)
name = CharField() name = CharField()
query = CharField()
target = CharField()
picture = CharField() picture = CharField()
......
...@@ -191,6 +191,16 @@ class Functions: ...@@ -191,6 +191,16 @@ class Functions:
index, sample_name = Functions.read_index(index_file) index, sample_name = Functions.read_index(index_file)
Functions.send_fasta_ready(mailer, job_name, sample_name, compressed) Functions.send_fasta_ready(mailer, job_name, sample_name, compressed)
@staticmethod
def get_readable_size(size):
units = ["Kb", "Mb", "Gb"]
i = 0
while size >= 1024 and i < 3:
size /= 1024.0
i += 1
return "%.1f %s" % (size, units[i])
@staticmethod @staticmethod
def get_gallery_items(): def get_gallery_items():
items = [] items = []
...@@ -198,7 +208,11 @@ class Functions: ...@@ -198,7 +208,11 @@ class Functions:
items.append({ items.append({
"name": item.name, "name": item.name,
"id_job": item.job.id_job, "id_job": item.job.id_job,
"picture": item.picture "picture": item.picture,
"query": item.query,
"target": item.target,
"mem_peak": Functions.get_readable_size(item.job.mem_peak),
"time_elapsed": item.job.time_elapsed
}) })
return items return items
...@@ -30,6 +30,42 @@ ...@@ -30,6 +30,42 @@
</div> </div>
</a> </a>
{% endfor %} {% endfor %}
<table class="table table-striped">
<thead>
<tr>
<th>
Reference genome
</th>
<th>
Query genome
</th>
<th>
Time elapsed
</th>
<th>
Maximum RAM usage
</th>
</tr>
</thead>
<tbody>
{% for item in items %}
<tr>
<td>
{{ item.target }}
</td>
<td>
{{ item.query }}
</td>
<td>
{{ item.time_elapsed }}
</td>
<td>
{{ item.mem_peak }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %} {% else %}
<p class="empty">Gallery is empty!</p> <p class="empty">Gallery is empty!</p>
{% endif %} {% endif %}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment