Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample data and unit tests #2

Open
s-celles opened this issue Jun 13, 2018 · 10 comments
Open

Sample data and unit tests #2

s-celles opened this issue Jun 13, 2018 · 10 comments

Comments

@s-celles
Copy link

Hello,

It will be great if this project could provide sample data
and use these data as unit tests.

Kind regards

@wavexx
Copy link
Collaborator

wavexx commented Jun 13, 2018 via email

@s-celles
Copy link
Author

I haven't found also Gimp template file and exported file template-it.png
Being able to download marks-it.svg could help to follow tutorial more quickly

@wavexx
Copy link
Collaborator

wavexx commented Jun 14, 2018 via email

@s-celles
Copy link
Author

ok
I have a large form with 25 rows and 5 columns ie 125 questions with 1 possible answer out of 4 ie 4 check boxes (A, B, C, D).
Do you have a script to generate such svg file?
Such script could accept the following parameters

  • png template file
  • box_width
  • box_height
  • offset_x
  • offset_y
  • space_x
  • space_y
  • rows
  • columns
    This script will output svg file that could them be edited using Inkscape for adjustments
    If you don't have such a script I will try to create one using yattag http://www.yattag.org or svgwrite https://svgwrite.readthedocs.io/

@wavexx
Copy link
Collaborator

wavexx commented Jun 15, 2018 via email

@s-celles
Copy link
Author

Under Mac OS X and Inkscape 0.92.2, when I copy a rectangle it pastes as image

  <rect
     style="opacity:0.7;fill:#ffb534;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
     id="q4_no"
     width="62"
     height="62"
     x="240"
     y="436" />
  <image
     y="145.87442"
     x="121.4196"
     id="image4178"
     xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABHNCSVQICAgIfAhkiAAAAN1JREFU
eJzt26ENAlEARMGFnEGQKwGPQJDfAA5x1V1CHQi6ogkQhBYYwU4FL+t3syzLK39qjLFOSXI57XM8
7HTPT90ezyTJlCTHwy7X80yDfu07wBZ3cB1AB2gdQAdoHUAHaB1AB2gdQAdoHUAHaB1AB2gdQAdo
HUAHaB1AB2gdQAdoHUAHaB1AB2gdQAdoHUAHaB1AB2gdQAdoHUAHaB1AB2gdQAdoHUAHaB1AB2gd
QAdoHUAHaB1AB2gdQAdoHUAHaB1AB2gdQAdoU/L50X6/tP9mGmOsOkKZ5/n+BmkBEBSn2NeOAAAA
AElFTkSuQmCC
"
     preserveAspectRatio="none"
     height="64"
     width="64" />

capture d ecran 2018-06-15 a 12 50 12

@wavexx
Copy link
Collaborator

wavexx commented Jun 15, 2018 via email

@s-celles
Copy link
Author

Thanks for the tip.

Here is my code to create a SVG template with many aligned checkboxes from a png file:

#!/usr/bin/env python

import click
import os
import svgwrite
import base64
from PIL import Image


@click.command()
@click.option('--img', default='', help='Image filename')
@click.option('--box-width', default=28.1, help='')
@click.option('--box-height', default=22.6, help='')
@click.option('--offset-x', default=29, help='')
@click.option('--offset-y', default=22, help='')
@click.option('--space-x', default=0, help='')
@click.option('--space-y', default=0, help='')
@click.option('--space-columns', default=143, help='')
@click.option('--rows', default=20, help='')
@click.option('--answers', default=4, help='')
@click.option('--columns', default=5, help='')
@click.option('--color', default='#ffb534', help='')
@click.option('--opacity', default=0.7, help='')
@click.option('--stroke', default='#000000', help='')
@click.option('--stroke-width', default='1px', help='')
def main(img, 
         box_width, box_height, 
         offset_x, offset_y, 
         space_x, space_y, space_columns,
         rows, answers, columns,
         color, opacity,
         stroke, stroke_width):
    if space_x == 0:
        space_x = box_width
    if space_y == 0:
        space_y = box_height
    # if space_columns == 0:
    #     space_columns = 10
     
    if img != '':
        (img_root, img_ext) = os.path.splitext(img)
        allowed_ext = ['.png']
        if img_ext not in allowed_ext:
            raise NotImplementedError("File extension %r not supported" % img_ext)
        filename_out = img_root + '.svg'
    else:
        filename_out = 'marks.svg'

    dwg = svgwrite.Drawing(filename_out, profile='tiny')

    if img != '':
        with open(img, "rb") as fd_img:
            encoded_string = base64.b64encode(fd_img.read())
        im = Image.open(img)
        img_width, img_height = im.size
        im.close()
        data = "data:image/png;base64,%s" % encoded_string.decode('ascii')
        dwg.add(dwg.image(data, id='image', x=0, y=0, preserveAspectRatio="none", width=im.width, height=im.height))
    
    offset_x_for_col = offset_x
    pos_x, pos_y = offset_x, offset_y
    for column in range(1, columns + 1):
        print("Column: %d" % column)
        for row in range(1, rows + 1):
            print("  Row: %d" % row)
            for answer in range(1, answers + 1):
                id = "q_%02d_%02d_%02d" % (column, row, answer)
                print("     Answer: %d - %s" % (answer, id))
                dwg.add(dwg.rect(insert=(pos_x, pos_y), size=(box_width, box_height),
                    fill=color, opacity=opacity, id=id,
                    stroke=stroke, stroke_width=stroke_width)
                )
                pos_x = pos_x + space_x
            pos_x = offset_x_for_col
            pos_y = pos_y + space_y
        pos_y = offset_y
        pos_x += space_columns
        offset_x_for_col = pos_x

    print("Save to %r" % filename_out)
    dwg.save()


if __name__ == '__main__':
    main()

@wavexx
Copy link
Collaborator

wavexx commented Jun 25, 2018

Were you able to get going?

@wavexx
Copy link
Collaborator

wavexx commented Jun 25, 2018

I don't know if this would be possible, but if you have the chance to share some of the pages to add to the sample data would be nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants