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): ...@@ -35,8 +35,11 @@ class AppServer(object):
@cherrypy.expose @cherrypy.expose
def process_venn(self, **kwargs): def process_venn(self, **kwargs):
delimiter = '\t'
if (kwargs["delimiter"] == "," or kwargs["delimiter"] == ";") :
delimiter = kwargs["delimiter"]
file_path = self.__upload(**kwargs) 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): def __upload(self, **kwargs):
...@@ -59,17 +62,20 @@ class AppServer(object): ...@@ -59,17 +62,20 @@ class AppServer(object):
return(filepath) return(filepath)
def __compare_lists ( self, file , header, spliter): def __compare_lists ( self, file, header, spliter):
FH = open(file,'r') FH = open(file,'r')
names = {} names = {}
samples = {} samples = {}
for i, line in enumerate(FH.readlines()): for i, line in enumerate(FH.readlines()):
if i == 0 and header: if i == 0 and header:
for j, val in enumerate(line.split(spliter)): for j, val in enumerate(line.split(spliter)):
names[string.ascii_uppercase[j]] = val names[string.ascii_uppercase[j]] = val.rstrip('\n\r')
else: else:
for j, val in enumerate(line.split(spliter)): for j, val in enumerate(line.split(spliter)):
if i == 0:
names[string.ascii_uppercase[j]] = "List " + str(j+1)
if j in samples: if j in samples:
samples[j].append(val) samples[j].append(val)
else: else:
...@@ -78,6 +84,9 @@ class AppServer(object): ...@@ -78,6 +84,9 @@ class AppServer(object):
d = {} d = {}
j = 1 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 s in samples:
for line in samples[s]: for line in samples[s]:
if line.rstrip('\n\r') in d: if line.rstrip('\n\r') in d:
...@@ -85,7 +94,8 @@ class AppServer(object): ...@@ -85,7 +94,8 @@ class AppServer(object):
if d[line.rstrip('\n\r')] - j < 0: if d[line.rstrip('\n\r')] - j < 0:
d[line.rstrip('\n\r')] += j d[line.rstrip('\n\r')] += j
else: else:
d[line.rstrip('\n\r')] = j if line.rstrip('\n\r') != "":
d[line.rstrip('\n\r')] = j
j *= 10 j *= 10
d2 = {} d2 = {}
...@@ -104,8 +114,7 @@ class AppServer(object): ...@@ -104,8 +114,7 @@ class AppServer(object):
k = k + string.ascii_uppercase[i] k = k + string.ascii_uppercase[i]
values[k] = len(d2[key]) values[k] = len(d2[key])
data[k] = [] 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) return json.dumps([{'name': names, 'values' : values, 'data':data}], indent=4, sort_keys=True)
......
...@@ -40,9 +40,7 @@ ...@@ -40,9 +40,7 @@
uploadSeries = new Array(); uploadSeries = new Array();
function updateJvenn() { function updateJvenn() {
if ($("#paste-tab").hasClass("active")) { if ($("#paste-tab").hasClass("active")) {
var type = "pa", var type = "pa",
seriesTable = new Array(), seriesTable = new Array(),
num = 0; num = 0;
...@@ -59,11 +57,17 @@ ...@@ -59,11 +57,17 @@
data: getArrayFromArea("area_pa_"+i) data: getArrayFromArea("area_pa_"+i)
}); });
} }
} else { } else {
var type = "up", var type = "up",
seriesTable = uploadSeries; 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(); var colorsTable = new Array();
...@@ -196,51 +200,76 @@ ...@@ -196,51 +200,76 @@
}); });
$('#clear-all').click(function() { $('#clear-all').click(function() {
$('[id^="name_"]').each(function() { location.reload(true);
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();
}); });
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
updateJvenn(); updateJvenn();
$("#names").val(""); $("#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(){ $("#upload_and_draw").click(function(){
$('.progress-bar').removeClass("bar-danger");
$('.bar').css('width', '0%');
$('.sr-only').html('0%');
$("#browse_upload").click(); $("#browse_upload").click();
}); });
$('#browse_upload').fileupload({ $('#browse_upload').fileupload({
dataType: 'json', dataType: 'json',
add: function (e, data) { add: function (e, data) {
data.submit(); data.submit();
}, },
done: function (e, data) { done: function (e, data) {
uploadSeries = new Array({name: data.result[0].name, data: data.result[0].data, values: data.result[0].values}); var vennData = jQuery.extend(true, {}, data);
$("#name_up_1").val(data.result[0].name["A"]); if ("error" in data.result[0]) {
$("#name_up_2").val(data.result[0].name["B"]); $('.progress-bar').addClass("bar-danger");
$("#name_up_3").val(data.result[0].name["C"]); $('.sr-only').html("100% - " + data.result[0].error);
$("#name_up_4").val(data.result[0].name["D"]); }
$("#name_up_5").val(data.result[0].name["E"]); else {
$("#name_up_6").val(data.result[0].name["F"]); $('.sr-only').html("100% - Upload file: " + vennData.files[0].name);
updateJvenn(); uploadSeries = new Array({name: data.result[0].name, data: data.result[0].data, values: data.result[0].values});
}/*, 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) { progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10); var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .bar').css( $('.bar').css('width', progress + '%');
'width', $('.sr-only').html(progress + '%');
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) { function getArrayFromArea(areaID) {
...@@ -762,7 +791,7 @@ ...@@ -762,7 +791,7 @@
/* Venn conf pane css */ /* Venn conf pane css */
.bs-docs-example { .bs-docs-example {
position: relative; position: relative;
margin: 0 0 35px 0; margin: 0 0 25px 0;
padding: 39px 19px 14px; padding: 39px 19px 14px;
*padding-top: 19px; *padding-top: 19px;
background-color: #fff; background-color: #fff;
...@@ -774,7 +803,7 @@ ...@@ -774,7 +803,7 @@
/* Echo out a label for the example */ /* Echo out a label for the example */
.bs-docs-example:after { .bs-docs-example:after {
content: "Venn global configuration"; content: attr(content-value); /*"Venn global configuration";*/
position: absolute; position: absolute;
top: -1px; top: -1px;
left: -1px; left: -1px;
...@@ -856,7 +885,7 @@ ...@@ -856,7 +885,7 @@
</div> </div>
<div class="span6"> <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"> <img src="img/bullet.png" style="vertical-align:initial;padding-top:10px">
Display mode: Display mode:
<div class="btn-group" data-toggle="buttons-radio"> <div class="btn-group" data-toggle="buttons-radio">
...@@ -910,13 +939,12 @@ ...@@ -910,13 +939,12 @@
<div class="span6"> <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="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> <li role="presentation" id="upload-tab"><a data-toggle="tab" href="#upload">Upload lists</a></li>
</ul> </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="tab-pane active" id="paste">
<div class="row-fluid"> <div class="row-fluid">
...@@ -1026,89 +1054,121 @@ ...@@ -1026,89 +1054,121 @@
</div> </div>
<div class="tab-pane" id="upload"> <div class="tab-pane" id="upload">
<img src="img/bullet.png" style="vertical-align:initial;padding-top:10px">
<div class="row-fluid"> <b>Step1</b> - Define upload parameters
Upload a file, <div class="span6"> <br/>
<button id="upload_and_draw" class="btn btn-mini">Upload and draw Venn</button> <img src="img/bullet.png" style="vertical-align:initial;margin-left:10px;padding-top:10px">
<input style="display: none;" name="browse_upload" id="browse_upload" type="file" data-url="/process_venn" > Field separator:
</div> <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>
<div class="row-fluid"> <br/>
<div class="control-group color1"> <img src="img/bullet.png" style="vertical-align:initial;padding-top:20px">
<input class="span6" id="name_up_1" type="text" style="font-weight: bold;" value="List 1" maxlength="11"/> <b>Step2</b> - Browse to select a file
<div id="colorp_up_1" class="input-append colorpicker-component colorpicker-element"> <div class="row-fluid" style="margin-top:5px;">
<input type="text" value="#006600" class="form-control" style="display:none"/> <div class="control-group">
<span class="add-on"><i></i></span> <div id="progress" class="span8 progress" style="width:93%">
</div> <div class="bar progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="padding-top:5px;min-width: 2em;">
<div class="btn-group" style="margin-left:15px"> <span class="sr-only">0%</span>
<button id="colord_up_1" style="margin-bottom:10px" class="btn btn-mini"><i class="icon-refresh"></i></button> </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> </div>
</div> </div>
<hr style="margin:0 50px 20px 50px"/>
<div class="row-fluid"> <div class="row-fluid">
<div class="control-group color2"> <div class="span6">
<input class="span6" id="name_up_2" type="text" style="font-weight: bold;" value="List 2" maxlength="11"/> <div class="control-group color1">
<div id="colorp_up_2" class="input-append colorpicker-component colorpicker-element"> <input class="span6" id="name_up_1" type="text" style="font-weight: bold;" value="List 1" maxlength="11"/>
<input type="text" value="#5a9bd4" class="form-control" style="display:none"/> <div id="colorp_up_1" class="input-append colorpicker-component colorpicker-element">
<span class="add-on"><i></i></span> <input type="text" value="#006600" class="form-control" style="display:none"/>
</div> <span class="add-on"><i></i></span>
<div class="btn-group" style="margin-left:15px"> </div>
<button id="colord_up_2" style="margin-bottom:10px" class="btn btn-mini"><i class="icon-refresh"></i></button> <div class="btn-group" style="margin-left:15px">
</div> <button id="colord_up_1" style="margin-bottom:10px" class="btn btn-mini"><i class="icon-refresh"></i></button>
</div>
</div>
</div>
<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">
<input type="text" value="#5a9bd4" class="form-control" style="display:none"/>
<span class="add-on"><i></i></span>
</div>
<div class="btn-group" style="margin-left:15px">
<button id="colord_up_2" style="margin-bottom:10px" class="btn btn-mini"><i class="icon-refresh"></i></button>
</div>
</div>
</div> </div>
</div> </div>
<div class="row-fluid"> <div class="row-fluid">
<div class="control-group color3"> <div class="span6">
<input class="span6" id="name_up_3" type="text" style="font-weight: bold;" value="List 3" maxlength="11"/> <div class="control-group color3">
<div id="colorp_up_3" class="input-append colorpicker-component colorpicker-element"> <input class="span6" id="name_up_3" type="text" style="font-weight: bold;" value="List 3" maxlength="11"/>
<input type="text" value="#f15a60" class="form-control" style="display:none"/> <div id="colorp_up_3" class="input-append colorpicker-component colorpicker-element">
<span class="add-on"><i></i></span> <input type="text" value="#f15a60" class="form-control" style="display:none"/>
</div> <span class="add-on"><i></i></span>
<div class="btn-group" style="margin-left:15px"> </div>
<button id="colord_up_3" style="margin-bottom:10px" class="btn btn-mini"><i class="icon-refresh"></i></button> <div class="btn-group" style="margin-left:15px">
</div> <button id="colord_up_3" style="margin-bottom:10px" class="btn btn-mini"><i class="icon-refresh"></i></button>
</div>
</div>
</div> </div>
</div> <div class="span6">
<div class="control-group color4">
<div class="row-fluid"> <input class="span6" id="name_up_4" type="text" style="font-weight: bold;" value="List 4" maxlength="11"/>
<div class="control-group color4"> <div id="colorp_up_4" class="input-append colorpicker-component colorpicker-element">
<input class="span6" id="name_up_4" type="text" style="font-weight: bold;" value="List 4" maxlength="11"/> <input type="text" value="#cfcf1b" class="form-control" style="display:none"/>
<div id="colorp_up_4" class="input-append colorpicker-component colorpicker-element"> <span class="add-on"><i></i></span>
<input type="text" value="#cfcf1b" class="form-control" style="display:none"/> </div>
<span class="add-on"><i></i></span> <div class="btn-group" style="margin-left:15px">
</div> <button id="colord_up_4" style="margin-bottom:10px" class="btn btn-mini"><i class="icon-refresh"></i></button>
<div class="btn-group" style="margin-left:15px"> </div>
<button id="colord_up_4" style="margin-bottom:10px" class="btn btn-mini"><i class="icon-refresh"></i></button> </div>
</div>
</div> </div>
</div> </div>
<div class="row-fluid"> <div class="row-fluid">
<div class="control-group color5"> <div class="span6">
<input class="span6" id="name_up_5" type="text" style="font-weight: bold;" value="List 5" maxlength="11"/> <div class="control-group color5">
<div id="colorp_up_5" class="input-append colorpicker-component colorpicker-element"> <input class="span6" id="name_up_5" type="text" style="font-weight: bold;" value="List 5" maxlength="11"/>
<input type="text" value="#ff7500" class="form-control" style="display:none"/> <div id="colorp_up_5" class="input-append colorpicker-component colorpicker-element">
<span class="add-on"><i></i></span> <input type="text" value="#ff7500" class="form-control" style="display:none"/>
</div> <span class="add-on"><i></i></span>
<div class="btn-group" style="margin-left:15px"> </div>
<button id="colord_up_5" style="margin-bottom:10px" class="btn btn-mini"><i class="icon-refresh"></i></button> <div class="btn-group" style="margin-left:15px">
</div> <button id="colord_up_5" style="margin-bottom:10px" class="btn btn-mini"><i class="icon-refresh"></i></button>
</div>
</div>
</div> </div>
</div> <div class="span6">
<div class="control-group color6">
<div class="row-fluid"> <input class="span6" id="name_up_6" type="text" style="font-weight: bold;" value="List 6" maxlength="11"/>
<div class="control-group color6"> <div id="colorp_up_6" class="input-append colorpicker-component colorpicker-element">
<input class="span6" id="name_up_6" type="text" style="font-weight: bold;" value="List 6" maxlength="11"/> <input type="text" value="#c09853" class="form-control" style="display:none"/>
<div id="colorp_up_6" class="input-append colorpicker-component colorpicker-element"> <span class="add-on"><i></i></span>
<input type="text" value="#c09853" class="form-control" style="display:none"/> </div>
<span class="add-on"><i></i></span> <div class="btn-group" style="margin-left:15px">
</div> <button id="colord_up_6" style="margin-bottom:10px" class="btn btn-mini"><i class="icon-refresh"></i></button>
<div class="btn-group" style="margin-left:15px"> </div>
<button id="colord_up_6" style="margin-bottom:10px" class="btn btn-mini"><i class="icon-refresh"></i></button> </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