Commit dce818c6 authored by Philippe Bardou's avatar Philippe Bardou
Browse files

Venn from upload file...

parent 0c851ed6
......@@ -35,8 +35,11 @@ class AppServer(object):
@cherrypy.expose
def process_venn(self, **kwargs):
delimiter = '\t'
if (kwargs["delimiter"] == "," or kwargs["delimiter"] == ";") :
delimiter = kwargs["delimiter"]
file_path = self.__upload(**kwargs)
return self.__compare_lists(file_path, True, "\t")
return self.__compare_lists(file_path, kwargs["header"], delimiter)
def __upload(self, **kwargs):
......@@ -59,17 +62,20 @@ class AppServer(object):
return(filepath)
def __compare_lists ( self, file , header, spliter):
def __compare_lists ( self, file, header, spliter):
FH = open(file,'r')
names = {}
samples = {}
for i, line in enumerate(FH.readlines()):
if i == 0 and header:
for j, val in enumerate(line.split(spliter)):
names[string.ascii_uppercase[j]] = val
names[string.ascii_uppercase[j]] = val.rstrip('\n\r')
else:
for j, val in enumerate(line.split(spliter)):
if i == 0:
names[string.ascii_uppercase[j]] = "List " + str(j+1)
if j in samples:
samples[j].append(val)
else:
......@@ -78,6 +84,9 @@ class AppServer(object):
d = {}
j = 1
if len(names)>6:
return json.dumps([{'error':"Error: too many columns (" + str(len(names)) + ">6) in input file!"}])
for s in samples:
for line in samples[s]:
if line.rstrip('\n\r') in d:
......@@ -85,6 +94,7 @@ class AppServer(object):
if d[line.rstrip('\n\r')] - j < 0:
d[line.rstrip('\n\r')] += j
else:
if line.rstrip('\n\r') != "":
d[line.rstrip('\n\r')] = j
j *= 10
......@@ -104,8 +114,7 @@ class AppServer(object):
k = k + string.ascii_uppercase[i]
values[k] = len(d2[key])
data[k] = []
data[k].append(','.join(d2[key]))
data[k].append('\n'.join(d2[key]))
return json.dumps([{'name': names, 'values' : values, 'data':data}], indent=4, sort_keys=True)
......
......@@ -40,9 +40,7 @@
uploadSeries = new Array();
function updateJvenn() {
if ($("#paste-tab").hasClass("active")) {
var type = "pa",
seriesTable = new Array(),
num = 0;
......@@ -59,11 +57,17 @@
data: getArrayFromArea("area_pa_"+i)
});
}
} else {
var type = "up",
seriesTable = uploadSeries;
if(seriesTable.length > 0) {
if("A" in seriesTable[0].name) { seriesTable[0].name["A"] = $("#name_up_1").val(); }
if("B" in seriesTable[0].name) { seriesTable[0].name["B"] = $("#name_up_2").val(); }
if("C" in seriesTable[0].name) { seriesTable[0].name["C"] = $("#name_up_3").val(); }
if("D" in seriesTable[0].name) { seriesTable[0].name["D"] = $("#name_up_4").val(); }
if("E" in seriesTable[0].name) { seriesTable[0].name["E"] = $("#name_up_5").val(); }
if("F" in seriesTable[0].name) { seriesTable[0].name["F"] = $("#name_up_6").val(); }
}
}
var colorsTable = new Array();
......@@ -196,26 +200,36 @@
});
$('#clear-all').click(function() {
$('[id^="name_"]').each(function() {
var type = $(this).attr("id").split("_")[1],
index = $(this).attr("id").split("_")[2];
if (type == "pa") {
$("#area_" + type + "_" + index).val("");
}
$("#name_" + type + "_" + index).val("List " + index);
});
$('#search-field').val("");
$('#search-status').html("");
$('#venn-type').val("classic");
updateJvenn();
location.reload(true);
});
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
updateJvenn();
$("#names").val("");
$("#search-field").val("");
$("#search-status").html("");
});
function switchListOn(index, switchon, value) {
if(switchon) {
$("#name_up_" + index).val(value);
$("#name_up_" + index).prop("disabled", false);
$("#colorp_up_" + index).colorpicker('enable');
$("#colord_up_" + index).prop("disabled", false);
$("#colorp_up_" + index).colorpicker('setValue', colorDefault[index-1]);
}
else {
$("#name_up_" + index).prop("disabled", true);
$("#colorp_up_" + index).colorpicker('setValue', "lightgrey");
$("#colorp_up_" + index).colorpicker('disable');
$("#colord_up_" + index).prop("disabled", true);
}
}
$("#upload_and_draw").click(function(){
$('.progress-bar').removeClass("bar-danger");
$('.bar').css('width', '0%');
$('.sr-only').html('0%');
$("#browse_upload").click();
});
......@@ -225,22 +239,37 @@
data.submit();
},
done: function (e, data) {
var vennData = jQuery.extend(true, {}, data);
if ("error" in data.result[0]) {
$('.progress-bar').addClass("bar-danger");
$('.sr-only').html("100% - " + data.result[0].error);
}
else {
$('.sr-only').html("100% - Upload file: " + vennData.files[0].name);
uploadSeries = new Array({name: data.result[0].name, data: data.result[0].data, values: data.result[0].values});
$("#name_up_1").val(data.result[0].name["A"]);
$("#name_up_2").val(data.result[0].name["B"]);
$("#name_up_3").val(data.result[0].name["C"]);
$("#name_up_4").val(data.result[0].name["D"]);
$("#name_up_5").val(data.result[0].name["E"]);
$("#name_up_6").val(data.result[0].name["F"]);
if(vennData.result[0].name["A"]) { switchListOn(1, true, vennData.result[0].name["A"]); }
else { switchListOn(1, false, ""); }
if(vennData.result[0].name["B"]) { switchListOn(2, true, vennData.result[0].name["B"]); }
else { switchListOn(2, false, ""); }
if(vennData.result[0].name["C"]) { switchListOn(3, true, vennData.result[0].name["C"]); }
else { switchListOn(3, false, ""); }
if(vennData.result[0].name["D"]) { switchListOn(4, true, vennData.result[0].name["D"]); }
else { switchListOn(4, false, ""); }
if(vennData.result[0].name["E"]) { switchListOn(5, true, vennData.result[0].name["E"]); }
else { switchListOn(5, false, ""); }
if(vennData.result[0].name["F"]) { switchListOn(6, true, vennData.result[0].name["F"]); }
else { switchListOn(6, false, ""); }
updateJvenn();
}/*,
}
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .bar').css(
'width',
progress + '%'
);
}*/
$('.bar').css('width', progress + '%');
$('.sr-only').html(progress + '%');
}
});
$('#browse_upload').bind('fileuploadsubmit', function (e, data) {
data.formData = {delimiter: $('[id^="sep_"].active').attr("name"), header: $('[id^="header_"].active').attr("name")};
});
function getArrayFromArea(areaID) {
......@@ -762,7 +791,7 @@
/* Venn conf pane css */
.bs-docs-example {
position: relative;
margin: 0 0 35px 0;
margin: 0 0 25px 0;
padding: 39px 19px 14px;
*padding-top: 19px;
background-color: #fff;
......@@ -774,7 +803,7 @@
/* Echo out a label for the example */
.bs-docs-example:after {
content: "Venn global configuration";
content: attr(content-value); /*"Venn global configuration";*/
position: absolute;
top: -1px;
left: -1px;
......@@ -856,7 +885,7 @@
</div>
<div class="span6">
<div class="bs-docs-example">
<div class="bs-docs-example" content-value="Venn global configuration">
<img src="img/bullet.png" style="vertical-align:initial;padding-top:10px">
Display mode:
<div class="btn-group" data-toggle="buttons-radio">
......@@ -910,13 +939,12 @@
<div class="span6">
<ul class="nav nav-tabs">
<ul class="nav nav-tabs" style="margin:0px">
<li role="presentation" id="paste-tab" class="active"><a data-toggle="tab" href="#paste">Paste lists</a></li>
<li role="presentation" id="upload-tab"><a data-toggle="tab" href="#upload">Upload lists</a></li>
</ul>
<div class="tab-content clearfix">
<div class="tab-content clearfix" style="margin:0px;padding:20px 0 0 20px;border-left:1px solid #ddd;border-right:1px solid #ddd;border-bottom:1px solid #ddd;border-radius:0 0 4px 4px">
<div class="tab-pane active" id="paste">
<div class="row-fluid">
......@@ -1026,15 +1054,45 @@
</div>
<div class="tab-pane" id="upload">
<img src="img/bullet.png" style="vertical-align:initial;padding-top:10px">
<b>Step1</b> - Define upload parameters
<br/>
<img src="img/bullet.png" style="vertical-align:initial;margin-left:10px;padding-top:10px">
Field separator:
<div class="btn-group" data-toggle="buttons-radio">
<button id="sep_tab" name="\t" type="button" class="btn btn-mini active">tabular</button>
<button id="sep_comma" name="," type="button" class="btn btn-mini">comma</button>
<button id="sep_semicolon" name=";" type="button" class="btn btn-mini">semicolon</button>
</div>
<br/>
<img src="img/bullet.png" style="vertical-align:initial;margin-left:10px;padding-top:10px">
Use the first row as headers:
<div class="btn-group" data-toggle="buttons-radio">
<button id="header_yes" name="True" type="button" class="btn btn-mini active">Yes</button>
<button id="header_no" name="" type="button" class="btn btn-mini">No</button>
</div>
<div class="row-fluid">
Upload a file, <div class="span6">
<button id="upload_and_draw" class="btn btn-mini">Upload and draw Venn</button>
<br/>
<img src="img/bullet.png" style="vertical-align:initial;padding-top:20px">
<b>Step2</b> - Browse to select a file
<div class="row-fluid" style="margin-top:5px;">
<div class="control-group">
<div id="progress" class="span8 progress" style="width:93%">
<div class="bar progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="padding-top:5px;min-width: 2em;">
<span class="sr-only">0%</span>
</div>
</div>
<div class="input-append">
<input style="display: none;" name="browse_upload" id="browse_upload" type="file" data-url="/process_venn" >
<span id="upload_and_draw" class="add-on btn btn-default" style="border-radius:0 4px 4px 0;"><i class="icon-folder-open"></i></span>
</div>
</div>
</div>
<hr style="margin:0 50px 20px 50px"/>
<div class="row-fluid">
<div class="span6">
<div class="control-group color1">
<input class="span6" id="name_up_1" type="text" style="font-weight: bold;" value="List 1" maxlength="11"/>
<div id="colorp_up_1" class="input-append colorpicker-component colorpicker-element">
......@@ -1046,8 +1104,7 @@
</div>
</div>
</div>
<div class="row-fluid">
<div class="span6">
<div class="control-group color2">
<input class="span6" id="name_up_2" type="text" style="font-weight: bold;" value="List 2" maxlength="11"/>
<div id="colorp_up_2" class="input-append colorpicker-component colorpicker-element">
......@@ -1059,8 +1116,10 @@
</div>
</div>
</div>
</div>
<div class="row-fluid">
<div class="span6">
<div class="control-group color3">
<input class="span6" id="name_up_3" type="text" style="font-weight: bold;" value="List 3" maxlength="11"/>
<div id="colorp_up_3" class="input-append colorpicker-component colorpicker-element">
......@@ -1072,8 +1131,7 @@
</div>
</div>
</div>
<div class="row-fluid">
<div class="span6">
<div class="control-group color4">
<input class="span6" id="name_up_4" type="text" style="font-weight: bold;" value="List 4" maxlength="11"/>
<div id="colorp_up_4" class="input-append colorpicker-component colorpicker-element">
......@@ -1085,8 +1143,10 @@
</div>
</div>
</div>
</div>
<div class="row-fluid">
<div class="span6">
<div class="control-group color5">
<input class="span6" id="name_up_5" type="text" style="font-weight: bold;" value="List 5" maxlength="11"/>
<div id="colorp_up_5" class="input-append colorpicker-component colorpicker-element">
......@@ -1098,8 +1158,7 @@
</div>
</div>
</div>
<div class="row-fluid">
<div class="span6">
<div class="control-group color6">
<input class="span6" id="name_up_6" type="text" style="font-weight: bold;" value="List 6" maxlength="11"/>
<div id="colorp_up_6" class="input-append colorpicker-component colorpicker-element">
......@@ -1111,6 +1170,7 @@
</div>
</div>
</div>
</div>
</div>
</div>
......
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