Commit 9911b0e6 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Merge branch 'master' into multitools

parents ec33e669 af6e0e23
...@@ -94,4 +94,7 @@ max_concurrent_dl = 5 ...@@ -94,4 +94,7 @@ max_concurrent_dl = 5
[example] [example]
query = query =
target = target =
[analytics]
enable_logging_runs = False
...@@ -388,3 +388,9 @@ class AppConfigReader: ...@@ -388,3 +388,9 @@ class AppConfigReader:
return self.reader.get("example", "target") return self.reader.get("example", "target")
except (NoOptionError, NoSectionError): except (NoOptionError, NoSectionError):
return "" return ""
def _get_analytics_enabled(self):
try:
return self.reader.get("analytics", "enable_logging_runs").lower() == "true"
except (NoOptionError, NoSectionError):
return False
...@@ -125,7 +125,17 @@ if MODE == "webserver": ...@@ -125,7 +125,17 @@ if MODE == "webserver":
self.save() self.save()
if config.analytics_enabled:
class Analytics(BaseModel):
date_created = DateTimeField()
target_size = IntegerField()
query_size = IntegerField(null=True)
mail_client = CharField()
batch_type = CharField(max_length=20)
if not Analytics.table_exists():
Analytics.create_table()
if not Job.table_exists(): if not Job.table_exists():
Job.create_table() Job.create_table()
......
...@@ -926,6 +926,22 @@ class JobManager: ...@@ -926,6 +926,22 @@ class JobManager:
if MODE == "webserver" and self.config.send_mail_status: if MODE == "webserver" and self.config.send_mail_status:
self.send_mail_post() self.send_mail_post()
def _save_analytics_data(self):
from dgenies.database import Analytics
with Job.connect():
job = Job.get(Job.id_job == self.id_job)
target_size = os.path.getsize(self.target.get_path())
query_size = None
if self.query is not None:
query_size = os.path.getsize(self.query.get_path())
log = Analytics.create(
date_created=datetime.now(),
target_size=target_size,
query_size=query_size,
mail_client=job.email,
batch_type=job.batch_type)
log.save()
def _after_start(self, success, error_set): def _after_start(self, success, error_set):
with Job.connect(): with Job.connect():
if success: if success:
...@@ -934,6 +950,8 @@ class JobManager: ...@@ -934,6 +950,8 @@ class JobManager:
job = Job.get(Job.id_job == self.id_job) job = Job.get(Job.id_job == self.id_job)
job.status = status job.status = status
job.save() job.save()
if self.config.analytics_enabled:
self._save_analytics_data()
else: else:
self.set_status_standalone("waiting") self.set_status_standalone("waiting")
self.prepare_data_in_thread() self.prepare_data_in_thread()
......
...@@ -262,8 +262,6 @@ d3.boxplot.draw_left_axis = function (y_max, y_min = 0) { ...@@ -262,8 +262,6 @@ d3.boxplot.draw_left_axis = function (y_max, y_min = 0) {
.attr("preserveAspectRatio", "none"); .attr("preserveAspectRatio", "none");
let container_left = svg_left.append("g") let container_left = svg_left.append("g")
.attr("width", axis_length)
.attr("height", 20)
.attr("transform", "translate(0," + axis_length + ")rotate(-90)"); .attr("transform", "translate(0," + axis_length + ")rotate(-90)");
let y_size = y_max - y_min; let y_size = y_max - y_min;
...@@ -491,8 +489,6 @@ d3.boxplot.draw_right_axis = function (y_zones=d3.boxplot.y_zones) { ...@@ -491,8 +489,6 @@ d3.boxplot.draw_right_axis = function (y_zones=d3.boxplot.y_zones) {
.attr("preserveAspectRatio", "none"); .attr("preserveAspectRatio", "none");
let container_right = svg_right.append("g") let container_right = svg_right.append("g")
.attr("width", axis_length)
.attr("height", 20)
.attr("transform", "translate(20)rotate(90)"); .attr("transform", "translate(20)rotate(90)");
container_right.append("text") container_right.append("text")
......
...@@ -4,8 +4,8 @@ if (!dgenies || !dgenies.result) { ...@@ -4,8 +4,8 @@ if (!dgenies || !dgenies.result) {
dgenies.result.export = {}; dgenies.result.export = {};
dgenies.result.export.get_svg = function () { dgenies.result.export.get_svg = function (width="5000px") {
return "<svg width='5000px' height='5000px' viewBox='0 0 100 100'>" + $("#draw-in").find(">svg").html() + "</svg>"; return `<svg version='1.1' xmlns='http://www.w3.org/2000/svg' width='${width}' height='${width}' viewBox='0 0 100 100'>${$("#draw-in").find(">svg").html()}</svg>`;
}; };
dgenies.result.export.save_file = function(blob, format) { dgenies.result.export.save_file = function(blob, format) {
...@@ -32,7 +32,10 @@ dgenies.result.export.export_svg = function () { ...@@ -32,7 +32,10 @@ dgenies.result.export.export_svg = function () {
window.setTimeout(() => { window.setTimeout(() => {
let transform = d3.boxplot.container.attr("transform"); let transform = d3.boxplot.container.attr("transform");
let after = function () { let after = function () {
let blob = new Blob([dgenies.result.export.get_svg()], {type: "image/svg+xml"}); let svg = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" " +
"\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">";
svg += dgenies.result.export.get_svg("1000px");
let blob = new Blob([svg], {type: "image/svg+xml"});
d3.boxplot.zoom.restore_scale(transform); d3.boxplot.zoom.restore_scale(transform);
dgenies.result.export.save_file(blob, "svg"); dgenies.result.export.save_file(blob, "svg");
}; };
......
This diff is collapsed.
Markdown is supported
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