summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dealconvert/__init__.py2
-rw-r--r--dealconvert/formats/__init__.py3
-rw-r--r--dealconvert/formats/pbn.py19
-rw-r--r--dealconvert/formats/stdout.py2
-rw-r--r--http/api/api.py1
-rw-r--r--http/dealconvert.js10
-rw-r--r--http/index.html4
7 files changed, 28 insertions, 13 deletions
diff --git a/dealconvert/__init__.py b/dealconvert/__init__.py
index e25db66..530990f 100644
--- a/dealconvert/__init__.py
+++ b/dealconvert/__init__.py
@@ -10,7 +10,7 @@ class DealConverter(object):
def output(self, output_files):
deal_set = sorted(self.parser.parse(self.input), key=lambda d:d.number)
for output in output_files:
- self.detect_format(output).output(output, deal_set)
+ self.detect_format(output).output(output, deal_set, True)
def detect_format(self, filename, interactive=True):
for deal_format in globals()['formats'].__all__:
diff --git a/dealconvert/formats/__init__.py b/dealconvert/formats/__init__.py
index cdd8703..2d3d983 100644
--- a/dealconvert/formats/__init__.py
+++ b/dealconvert/formats/__init__.py
@@ -11,7 +11,8 @@ class DealFormat(object):
with open(input_file, 'rb') as content:
return self.parse_content(content)
- def output(self, output_file, deal):
+ def output(self, output_file, deal, analyze=False):
+ self.analyze = analyze
if not len(deal):
raise RuntimeError('Dealset is empty')
with open(output_file, 'wb') as out_file:
diff --git a/dealconvert/formats/pbn.py b/dealconvert/formats/pbn.py
index bc52462..b6c30ed 100644
--- a/dealconvert/formats/pbn.py
+++ b/dealconvert/formats/pbn.py
@@ -137,14 +137,15 @@ class PBNFormat(DealFormat):
])))
for field in board.extra_fields:
lines.append(field)
- try:
- dd_board = PBNBoard(lines)
- dd_table = DDTable(dd_board).get_dd_table(self.interactive)
- dd_contract = ParScore(dd_board).get_par_contract(dd_table)
- dd_board.save_dd_table(dd_table)
- dd_board.save_par_contract(dd_contract)
- lines = [field.raw_field for field in dd_board.fields]
- except Exception as e:
- warnings.warn('unable to determine double-dummy data: %s' % e)
+ if self.analyze:
+ try:
+ dd_board = PBNBoard(lines)
+ dd_table = DDTable(dd_board).get_dd_table(self.interactive)
+ dd_contract = ParScore(dd_board).get_par_contract(dd_table)
+ dd_board.save_dd_table(dd_table)
+ dd_board.save_par_contract(dd_contract)
+ lines = [field.raw_field for field in dd_board.fields]
+ except Exception as e:
+ warnings.warn('unable to determine double-dummy data: %s' % e)
for line in lines + ['']:
out_file.write(line + '\r\n')
diff --git a/dealconvert/formats/stdout.py b/dealconvert/formats/stdout.py
index b9df341..9725c06 100644
--- a/dealconvert/formats/stdout.py
+++ b/dealconvert/formats/stdout.py
@@ -9,7 +9,7 @@ class STDOUTFormat(DealFormat):
def parse(self, input_file):
return []
- def output(self, output_file, deal):
+ def output(self, output_file, deal, analyze=False):
width = 9
for board in deal:
lines = []
diff --git a/http/api/api.py b/http/api/api.py
index 6a9a785..0e5da8d 100644
--- a/http/api/api.py
+++ b/http/api/api.py
@@ -102,6 +102,7 @@ def handle_upload(response, request):
output_id, output_path = _get_file_id()
token = _get_rand_string(16)
output_buffer = StringIO()
+ output.analyze = params.get('analyze_deals', False)
output.output_content(output_buffer, dealset)
with file(output_path, 'w') as output_file:
json.dump({
diff --git a/http/dealconvert.js b/http/dealconvert.js
index 2478fe9..ab8e90b 100644
--- a/http/dealconvert.js
+++ b/http/dealconvert.js
@@ -3,8 +3,14 @@ $(document).ready(function() {
$('input[name="output"]').change(function() {
if ($('input[name="output"]:checked').length > 0) {
$('#submit-btn').removeAttr('disabled');
+ if ($('input[name="output"][value="pbn"]').is(':checked')) {
+ $('#analyze-boards').removeAttr('disabled');
+ } else {
+ $('#analyze-boards').attr('disabled', 'disabled').prop('checked', false);
+ }
} else {
$('#submit-btn').attr('disabled', 'disabled');
+ $('#analyze-boards').attr('disabled', 'disabled').prop('checked', false);
}
});
$('#input-files').change(function() {
@@ -17,6 +23,7 @@ $(document).ready(function() {
output.push(this.value);
});
var display = that.find('input[name="display"]').is(':checked');
+ var analyze = that.find('input[name="analyze"]').is(':checked');
var files = {};
var formFiles = this['input-files'].files;
if (formFiles.length) {
@@ -42,7 +49,8 @@ $(document).ready(function() {
'name': file,
'content': files[file],
'output': output,
- 'display_deals': display
+ 'display_deals': display,
+ 'analyze_deals': analyze
};
$.ajax(
'api/upload/',
diff --git a/http/index.html b/http/index.html
index c43a2ac..51c6b34 100644
--- a/http/index.html
+++ b/http/index.html
@@ -149,6 +149,10 @@
<input class="form-check-input" type="checkbox" name="display" value="yes" id="display-boards" />
<label class="form-check-label" for="display-boards">Wyświetl podgląd rozkładów</label>
</div>
+ <div class="form-check-inline">
+ <input class="form-check-input" type="checkbox" name="analyze" value="yes" id="analyze-boards" disabled="disabled" />
+ <label class="form-check-label" for="analyze-boards">Przeanalizuj rozkłady w widne</label>
+ </div>
</div>
</form>
</div>