def put_extras(path, form_dict, uid, quiet=True): html_file_name = os.path.join(path, uid.replace('-', 'm') + '_drawings.html') image_file_base_name = os.path.join(path, uid.replace('-', 'm') + '_image_') stroke_file_base_name = os.path.join(path, uid.replace('-', 'm') + '_stroke_') tasks_data = turkutil.form_dict_to_tasks_dict(form_dict)['task'] html = [r"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Images Drawn By %s</title> <style type="text/css"> div { display: inline-block; border: thin solid black; } </style> </head> <body>""" % uid] for n, task in tasks_data.iteritems(): image_name = image_file_base_name + '%d.png' % (int(n) + 1) uri_to_png(task['image'], '%s%d.png' % (image_file_base_name, int(n) + 1)) html.append(r"""<div><img src="%s" alt="given" title="given"/><img src="%s_image_%d.png" alt="drawn" title="drawn"/></div>""" % (task['completion-image-anonymous_url'], uid.replace('-', 'm'), int(n) + 1)) with open('%s%d.cstroke' % (stroke_file_base_name, int(n) + 1), 'wb') as f: f.write(compress_stroke(task['strokes'])) html.append(r"""</body> </html>""") with open(html_file_name, 'w') as f: f.write('\n'.join(html))
def put_extras(path, form_dict, uid, quiet=True): html_file_name = os.path.join(path, uid.replace('-', 'm') + '_drawings.html') image_file_base_name = os.path.join(path, uid.replace('-', 'm') + '_image_') stroke_file_base_name = os.path.join(path, uid.replace('-', 'm') + '_stroke_') tasks_data = turkutil.form_dict_to_tasks_dict(form_dict)['task'] html = [ r"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Images Drawn By %s</title> <style type="text/css"> div { display: inline-block; border: thin solid black; } </style> </head> <body>""" % uid ] for n, task in tasks_data.iteritems(): image_name = image_file_base_name + '%d.png' % (int(n) + 1) uri_to_png(task['image'], '%s%d.png' % (image_file_base_name, int(n) + 1)) html.append( r"""<div><img src="%s" alt="given" title="given"/><img src="%s_image_%d.png" alt="drawn" title="drawn"/></div>""" % (task['completion-image-anonymous_url'], uid.replace( '-', 'm'), int(n) + 1)) with open('%s%d.cstroke' % (stroke_file_base_name, int(n) + 1), 'wb') as f: f.write(compress_stroke(task['strokes'])) html.append(r"""</body> </html>""") with open(html_file_name, 'w') as f: f.write('\n'.join(html))
def put_extras(path, form_dict, uid, quiet=True): html_file_name = os.path.join(path, uid.replace('-', 'm') + '_drawings.html') image_file_base_name = os.path.join(path, uid.replace('-', 'm') + '_image_') stroke_file_base_name = os.path.join(path, uid.replace('-', 'm') + '_stroke_') tasks_data = turkutil.form_dict_to_tasks_dict(form_dict)['task'] html = [r"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Images Drawn By %s</title> <style type="text/css"> div.task { display: inline-block; border: thin solid black; } .image-holder { padding: 2.5px; width: 100px; height: 100px; } .class-holder { display: inline-block; padding: 0px; } .class-box { display: inline-block; padding: 0px; } .image-box { margin: 2.5px; border: thin solid #C0C0C0; //lightgray text-align: center; vertical-align: middle; display: block; } .class-box-untimed { border: thin black solid; } </style> </head> <body>""" % uid] for n, task in tasks_data.iteritems(): image_name = image_file_base_name + '%d.png' % (int(n) + 1) uri_to_png(task['image'], '%s%d.png' % (image_file_base_name, int(n) + 1)) drawn_image = r"""<img src="%s_image_%d.png" alt="drawn" title="drawn"/>""" % (uid.replace('-', 'm'), int(n) + 1) if 'class-0-example-image-1-anonymous_url' in task or \ 'class-1-example-image-0-anonymous_url' in task: # untimed, multiple images task_html = [] class_urls = {} for key, value in task.iteritems(): if '-anonymous_url' not in key: continue match = CLASS_REGEX.match(key) if not match: continue class_i, example_i = map(int, match.groups()) if class_i not in class_urls: class_urls[class_i] = {} class_urls[class_i][example_i] = value for class_i in sorted(class_urls.keys()): task_html.append('<div class="class-box class-box-untimed">') for example_i in sorted(class_urls[class_i].keys()): task_html.append(r"""<div class="image-box"> <span class="wraptocenter image-holder"> <img src="%s" /> </span> </div>""" % class_urls[class_i][example_i]) task_html.append('</div>') task_html.append(r'<br />') task_html.append(drawn_image) task_html = '\n'.join(task_html) else: # timed, single image task_html = r"""<img src="%s" alt="given" title="given"/>%s</div>""" % (task['class-0-example-image-0-anonymous_url'], drawn_image) html.append(r"""<div class="task">%s</div>""" % task_html) with open('%s%d.cstroke' % (stroke_file_base_name, int(n) + 1), 'wb') as f: f.write(compress_stroke(task['strokes'])) html.append(r"""</body> </html>""") with open(html_file_name, 'w') as f: f.write('\n'.join(html))
def put_extras(path, form_dict, uid, quiet=True): html_file_name = os.path.join(path, uid.replace("-", "m") + "_drawings.html") image_file_base_name = os.path.join(path, uid.replace("-", "m") + "_image_") stroke_file_base_name = os.path.join(path, uid.replace("-", "m") + "_stroke_") tasks_data = turkutil.form_dict_to_tasks_dict(form_dict)["task"] html = [ r"""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Images Drawn By %s</title> <style type="text/css"> div.task { display: inline-block; border: thin solid black; } .image-holder { padding: 2.5px; width: 100px; height: 100px; } .class-holder { display: inline-block; padding: 0px; } .class-box { display: inline-block; padding: 0px; } .image-box { margin: 2.5px; border: thin solid #C0C0C0; //lightgray text-align: center; vertical-align: middle; display: block; } .class-box-untimed { border: thin black solid; } </style> </head> <body>""" % uid ] for n, task in tasks_data.iteritems(): image_name = image_file_base_name + "%d.png" % (int(n) + 1) uri_to_png(task["image"], "%s%d.png" % (image_file_base_name, int(n) + 1)) drawn_image = r"""<img src="%s_image_%d.png" alt="drawn" title="drawn"/>""" % ( uid.replace("-", "m"), int(n) + 1, ) if ( "class-0-example-image-1-anonymous_url" in task or "class-1-example-image-0-anonymous_url" in task ): # untimed, multiple images task_html = [] class_urls = {} for key, value in task.iteritems(): if "-anonymous_url" not in key: continue match = CLASS_REGEX.match(key) if not match: continue class_i, example_i = map(int, match.groups()) if class_i not in class_urls: class_urls[class_i] = {} class_urls[class_i][example_i] = value for class_i in sorted(class_urls.keys()): task_html.append('<div class="class-box class-box-untimed">') for example_i in sorted(class_urls[class_i].keys()): task_html.append( r"""<div class="image-box"> <span class="wraptocenter image-holder"> <img src="%s" /> </span> </div>""" % class_urls[class_i][example_i] ) task_html.append("</div>") task_html.append(r"<br />") task_html.append(drawn_image) task_html = "\n".join(task_html) else: # timed, single image task_html = r"""<img src="%s" alt="given" title="given"/>%s</div>""" % ( task["class-0-example-image-0-anonymous_url"], drawn_image, ) html.append(r"""<div class="task">%s</div>""" % task_html) with open("%s%d.cstroke" % (stroke_file_base_name, int(n) + 1), "wb") as f: f.write(compress_stroke(task["strokes"])) html.append( r"""</body> </html>""" ) with open(html_file_name, "w") as f: f.write("\n".join(html))