From 1bca7f7a515c0467a50981e2c3a0e67bbb56ba1e Mon Sep 17 00:00:00 2001 From: turulomio Date: Thu, 24 Aug 2023 14:27:34 +0200 Subject: [PATCH 1/2] Works --- poetry.lock | 85 ++++++++++++++++++++++- pyproject.toml | 2 + tests/percentil_color.py | 142 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 tests/percentil_color.py diff --git a/poetry.lock b/poetry.lock index 2fccb84..eecdd1a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -257,6 +257,20 @@ files = [ {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] +[[package]] +name = "colour" +version = "0.1.5" +description = "converts and manipulates various color representation (HSL, RVB, web, X11, ...)" +optional = false +python-versions = "*" +files = [ + {file = "colour-0.1.5-py2.py3-none-any.whl", hash = "sha256:33f6db9d564fadc16e59921a56999b79571160ce09916303d35346dddc17978c"}, + {file = "colour-0.1.5.tar.gz", hash = "sha256:af20120fefd2afede8b001fbef2ea9da70ad7d49fafdb6489025dae8745c3aee"}, +] + +[package.extras] +test = ["nose"] + [[package]] name = "crashtest" version = "0.4.1" @@ -710,6 +724,75 @@ files = [ [package.dependencies] ptyprocess = ">=0.5" +[[package]] +name = "pillow" +version = "10.0.0" +description = "Python Imaging Library (Fork)" +optional = false +python-versions = ">=3.8" +files = [ + {file = "Pillow-10.0.0-cp310-cp310-macosx_10_10_x86_64.whl", hash = "sha256:1f62406a884ae75fb2f818694469519fb685cc7eaff05d3451a9ebe55c646891"}, + {file = "Pillow-10.0.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d5db32e2a6ccbb3d34d87c87b432959e0db29755727afb37290e10f6e8e62614"}, + {file = "Pillow-10.0.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:edf4392b77bdc81f36e92d3a07a5cd072f90253197f4a52a55a8cec48a12483b"}, + {file = "Pillow-10.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:520f2a520dc040512699f20fa1c363eed506e94248d71f85412b625026f6142c"}, + {file = "Pillow-10.0.0-cp310-cp310-manylinux_2_28_aarch64.whl", hash = "sha256:8c11160913e3dd06c8ffdb5f233a4f254cb449f4dfc0f8f4549eda9e542c93d1"}, + {file = "Pillow-10.0.0-cp310-cp310-manylinux_2_28_x86_64.whl", hash = "sha256:a74ba0c356aaa3bb8e3eb79606a87669e7ec6444be352870623025d75a14a2bf"}, + {file = "Pillow-10.0.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:d5d0dae4cfd56969d23d94dc8e89fb6a217be461c69090768227beb8ed28c0a3"}, + {file = "Pillow-10.0.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:22c10cc517668d44b211717fd9775799ccec4124b9a7f7b3635fc5386e584992"}, + {file = "Pillow-10.0.0-cp310-cp310-win_amd64.whl", hash = "sha256:dffe31a7f47b603318c609f378ebcd57f1554a3a6a8effbc59c3c69f804296de"}, + {file = "Pillow-10.0.0-cp311-cp311-macosx_10_10_x86_64.whl", hash = "sha256:9fb218c8a12e51d7ead2a7c9e101a04982237d4855716af2e9499306728fb485"}, + {file = "Pillow-10.0.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:d35e3c8d9b1268cbf5d3670285feb3528f6680420eafe35cccc686b73c1e330f"}, + {file = "Pillow-10.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3ed64f9ca2f0a95411e88a4efbd7a29e5ce2cea36072c53dd9d26d9c76f753b3"}, + {file = "Pillow-10.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0b6eb5502f45a60a3f411c63187db83a3d3107887ad0d036c13ce836f8a36f1d"}, + {file = "Pillow-10.0.0-cp311-cp311-manylinux_2_28_aarch64.whl", hash = "sha256:c1fbe7621c167ecaa38ad29643d77a9ce7311583761abf7836e1510c580bf3dd"}, + {file = "Pillow-10.0.0-cp311-cp311-manylinux_2_28_x86_64.whl", hash = "sha256:cd25d2a9d2b36fcb318882481367956d2cf91329f6892fe5d385c346c0649629"}, + {file = "Pillow-10.0.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:3b08d4cc24f471b2c8ca24ec060abf4bebc6b144cb89cba638c720546b1cf538"}, + {file = "Pillow-10.0.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:d737a602fbd82afd892ca746392401b634e278cb65d55c4b7a8f48e9ef8d008d"}, + {file = "Pillow-10.0.0-cp311-cp311-win_amd64.whl", hash = "sha256:3a82c40d706d9aa9734289740ce26460a11aeec2d9c79b7af87bb35f0073c12f"}, + {file = "Pillow-10.0.0-cp311-cp311-win_arm64.whl", hash = "sha256:bc2ec7c7b5d66b8ec9ce9f720dbb5fa4bace0f545acd34870eff4a369b44bf37"}, + {file = "Pillow-10.0.0-cp312-cp312-macosx_10_10_x86_64.whl", hash = "sha256:d80cf684b541685fccdd84c485b31ce73fc5c9b5d7523bf1394ce134a60c6883"}, + {file = "Pillow-10.0.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:76de421f9c326da8f43d690110f0e79fe3ad1e54be811545d7d91898b4c8493e"}, + {file = "Pillow-10.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:81ff539a12457809666fef6624684c008e00ff6bf455b4b89fd00a140eecd640"}, + {file = "Pillow-10.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ce543ed15570eedbb85df19b0a1a7314a9c8141a36ce089c0a894adbfccb4568"}, + {file = "Pillow-10.0.0-cp312-cp312-manylinux_2_28_aarch64.whl", hash = "sha256:685ac03cc4ed5ebc15ad5c23bc555d68a87777586d970c2c3e216619a5476223"}, + {file = "Pillow-10.0.0-cp312-cp312-manylinux_2_28_x86_64.whl", hash = "sha256:d72e2ecc68a942e8cf9739619b7f408cc7b272b279b56b2c83c6123fcfa5cdff"}, + {file = "Pillow-10.0.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:d50b6aec14bc737742ca96e85d6d0a5f9bfbded018264b3b70ff9d8c33485551"}, + {file = "Pillow-10.0.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:00e65f5e822decd501e374b0650146063fbb30a7264b4d2744bdd7b913e0cab5"}, + {file = "Pillow-10.0.0-cp312-cp312-win_amd64.whl", hash = "sha256:f31f9fdbfecb042d046f9d91270a0ba28368a723302786c0009ee9b9f1f60199"}, + {file = "Pillow-10.0.0-cp312-cp312-win_arm64.whl", hash = "sha256:1ce91b6ec08d866b14413d3f0bbdea7e24dfdc8e59f562bb77bc3fe60b6144ca"}, + {file = "Pillow-10.0.0-cp38-cp38-macosx_10_10_x86_64.whl", hash = "sha256:349930d6e9c685c089284b013478d6f76e3a534e36ddfa912cde493f235372f3"}, + {file = "Pillow-10.0.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:3a684105f7c32488f7153905a4e3015a3b6c7182e106fe3c37fbb5ef3e6994c3"}, + {file = "Pillow-10.0.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b4f69b3700201b80bb82c3a97d5e9254084f6dd5fb5b16fc1a7b974260f89f43"}, + {file = "Pillow-10.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3f07ea8d2f827d7d2a49ecf1639ec02d75ffd1b88dcc5b3a61bbb37a8759ad8d"}, + {file = "Pillow-10.0.0-cp38-cp38-manylinux_2_28_aarch64.whl", hash = "sha256:040586f7d37b34547153fa383f7f9aed68b738992380ac911447bb78f2abe530"}, + {file = "Pillow-10.0.0-cp38-cp38-manylinux_2_28_x86_64.whl", hash = "sha256:f88a0b92277de8e3ca715a0d79d68dc82807457dae3ab8699c758f07c20b3c51"}, + {file = "Pillow-10.0.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:c7cf14a27b0d6adfaebb3ae4153f1e516df54e47e42dcc073d7b3d76111a8d86"}, + {file = "Pillow-10.0.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:3400aae60685b06bb96f99a21e1ada7bc7a413d5f49bce739828ecd9391bb8f7"}, + {file = "Pillow-10.0.0-cp38-cp38-win_amd64.whl", hash = "sha256:dbc02381779d412145331789b40cc7b11fdf449e5d94f6bc0b080db0a56ea3f0"}, + {file = "Pillow-10.0.0-cp39-cp39-macosx_10_10_x86_64.whl", hash = "sha256:9211e7ad69d7c9401cfc0e23d49b69ca65ddd898976d660a2fa5904e3d7a9baa"}, + {file = "Pillow-10.0.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:faaf07ea35355b01a35cb442dd950d8f1bb5b040a7787791a535de13db15ed90"}, + {file = "Pillow-10.0.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c9f72a021fbb792ce98306ffb0c348b3c9cb967dce0f12a49aa4c3d3fdefa967"}, + {file = "Pillow-10.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9f7c16705f44e0504a3a2a14197c1f0b32a95731d251777dcb060aa83022cb2d"}, + {file = "Pillow-10.0.0-cp39-cp39-manylinux_2_28_aarch64.whl", hash = "sha256:76edb0a1fa2b4745fb0c99fb9fb98f8b180a1bbceb8be49b087e0b21867e77d3"}, + {file = "Pillow-10.0.0-cp39-cp39-manylinux_2_28_x86_64.whl", hash = "sha256:368ab3dfb5f49e312231b6f27b8820c823652b7cd29cfbd34090565a015e99ba"}, + {file = "Pillow-10.0.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:608bfdee0d57cf297d32bcbb3c728dc1da0907519d1784962c5f0c68bb93e5a3"}, + {file = "Pillow-10.0.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:5c6e3df6bdd396749bafd45314871b3d0af81ff935b2d188385e970052091017"}, + {file = "Pillow-10.0.0-cp39-cp39-win_amd64.whl", hash = "sha256:7be600823e4c8631b74e4a0d38384c73f680e6105a7d3c6824fcf226c178c7e6"}, + {file = "Pillow-10.0.0-pp310-pypy310_pp73-macosx_10_10_x86_64.whl", hash = "sha256:92be919bbc9f7d09f7ae343c38f5bb21c973d2576c1d45600fce4b74bafa7ac0"}, + {file = "Pillow-10.0.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8f8182b523b2289f7c415f589118228d30ac8c355baa2f3194ced084dac2dbba"}, + {file = "Pillow-10.0.0-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:38250a349b6b390ee6047a62c086d3817ac69022c127f8a5dc058c31ccef17f3"}, + {file = "Pillow-10.0.0-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:88af2003543cc40c80f6fca01411892ec52b11021b3dc22ec3bc9d5afd1c5334"}, + {file = "Pillow-10.0.0-pp39-pypy39_pp73-macosx_10_10_x86_64.whl", hash = "sha256:c189af0545965fa8d3b9613cfdb0cd37f9d71349e0f7750e1fd704648d475ed2"}, + {file = "Pillow-10.0.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ce7b031a6fc11365970e6a5686d7ba8c63e4c1cf1ea143811acbb524295eabed"}, + {file = "Pillow-10.0.0-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:db24668940f82321e746773a4bc617bfac06ec831e5c88b643f91f122a785684"}, + {file = "Pillow-10.0.0-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:efe8c0681042536e0d06c11f48cebe759707c9e9abf880ee213541c5b46c5bf3"}, + {file = "Pillow-10.0.0.tar.gz", hash = "sha256:9c82b5b3e043c7af0d95792d0d20ccf68f61a1fec6b3530e718b688422727396"}, +] + +[package.extras] +docs = ["furo", "olefile", "sphinx (>=2.4)", "sphinx-copybutton", "sphinx-inline-tabs", "sphinx-removed-in", "sphinxext-opengraph"] +tests = ["check-manifest", "coverage", "defusedxml", "markdown2", "olefile", "packaging", "pyroma", "pytest", "pytest-cov", "pytest-timeout"] + [[package]] name = "pkginfo" version = "1.9.6" @@ -1413,4 +1496,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "49203a79fa8102559ef54005dd665d839d8b0fc624b7399b84d8dd7f9efb44f8" +content-hash = "f6364f32d7e6e86b1ac9ba9e867b6a97f8ae9b05ce8bfeafb30912d100c2d2f6" diff --git a/pyproject.toml b/pyproject.toml index d0b8304..4b3936b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,8 @@ colorama = "^0.4.6" polib = "^1.2.0" psutil = "^5.9.5" pytz = "^2023.3" +pillow = "^10.0.0" +colour = "^0.1.5" [tool.poetry.group.dev.dependencies] poetry = "^1.5.1" diff --git a/tests/percentil_color.py b/tests/percentil_color.py new file mode 100644 index 0000000..59715c9 --- /dev/null +++ b/tests/percentil_color.py @@ -0,0 +1,142 @@ +from unogenerator import ODS_Standard +from unogenerator.commons import Coord as C +from decimal import Decimal +from PIL import ImageColor +from ast import literal_eval +from colour import Color + + +def hexstring_to_rgb(color_in_hex): + return ImageColor.getcolor(color_in_hex, "RGB") + +def rgb_to_hexstring(rgb): + r = rgb[0] + g = rgb[1] + b = rgb[2] + return '#%02X%02X%02X' % (r,g,b) + +def rgb_to_hex(rgb_tuple): + r = rgb_tuple[0] + g = rgb_tuple[1] + b = rgb_tuple[2] + s= '0x%02X%02X%02X' % (r,g,b) +# print(literal_eval(s)) +# print("AJR", hex(literal_eval(s))) + return hex(literal_eval(s)) +def rgb_to_int(rgb_tuple): + r = rgb_tuple[0] + g = rgb_tuple[1] + b = rgb_tuple[2] + s= '0x%02X%02X%02X' % (r,g,b) +# print(s, r, g, b) +# print("RGB_TO_INT", rgb_tuple, s, literal_eval(s)) +# print("AJR", hex(literal_eval(s))) + return literal_eval(s) + + +def setCellBackgroundColor(doc, coord, color_int): + coord=C.assertCoord(coord) +# print("COLOR_INT", color_int) + + cell=doc.sheet.getCellByPosition(coord.letterIndex(), coord.numberIndex()) + cell.setPropertyValue("CellBackColor", color_int) + +#def color(from_, to_, value): +# """ +# Value entre 0 y 1 +# """ +# r1, g1, b1=from_ +# r2, g2, b2=to_ +# +## if r1>r2: +## r=r1-int((r1-r2)*value) +## else: +# r=r1+int(abs(r1-r2)*value) +## if g1>g2: +## g=g1-int((g1-g2)*value) +## else: +# g=g1+int(abs(g1-g2)*value) +## if b1>b2: +## b=b1-int((b1-b2)*value) +## else: +# b=b1+int(abs(b1-b2)*value) +# +# return r, g, b +# + + +def list_ordered_without_none(list_): + r=[] + for o in list_: + if o is None or o.__class__==str: + continue + r.append(o) + r.sort() + return r + +def ordered_position_0_100(list_, item): + """ + Function List must bue ordered + """ + if item is None or item=="": + return 0 + index=list_.index(item) + return int(100*index/len(list_)) + + + +def percentil_color(doc, letter, skip_up=0, skip_down=0, cast=Decimal): + """ + row_from and row_to are integers + """ + values=doc.getValuesByColumn(letter, skip_up=skip_up, skip_down=skip_down) + print(values, values.__class__) + + +# from_=(255, 0, 0) +# to_=(0, 255, 0) + + #Cast all values + for i in range(len(values)): + if values[i] is None or values[i]=="": + continue + values[i]=cast(values[i]) + print(values) + ordered_values=list_ordered_without_none(values) + + #Calculate percentil + #colors=list(Color("green").range_to(Color("white"), 50))+ [Color("white")]+ list(Color("white").range_to(Color("red"), 50)) + colors=list(Color("green").range_to(Color("red"), 101)) + # Set colors + for i in range(len(values)): + coord=f"{letter}{i+skip_up+1}" + i_color_hex=colors[ordered_position_0_100(ordered_values, values[i])].get_hex()# + i_color_rgb=hexstring_to_rgb(i_color_hex) + print(i_color_rgb) + + setCellBackgroundColor(doc, coord, rgb_to_int(i_color_rgb)) + + +################################# +# +#rgb=hexstring_to_rgb("#23a9dd".upper()) +#print(rgb) +#rrggbb=rgb_to_hexstring(rgb) +#print(rrggbb) +#print(rgb_to_hex(rgb)) +#print("MIDDLE") +#middle=color((255, 0, 0), (0, 0, 0), 0.5) +#print(middle) +#print( rgb_to_hex(middle), rgb_to_int(middle)) + +Red=0xFF9999 +Green=0xc0FFc0 + +with ODS_Standard() as doc: + doc.createSheet("Get Values") + doc.addColumnWithStyle("A1", [1, 2, 3, 4, "=A4+1", 6, 7, None, 9, 10]) + percentil_color(doc, "A") + doc.createSheet("Get Values2") + doc.addColumnWithStyle("A1", range(100)) + percentil_color(doc, "A") + doc.export_pdf("percentil_color.pdf") From b78d6981745474620045c90617f62188d6c8b834 Mon Sep 17 00:00:00 2001 From: turulomio Date: Thu, 24 Aug 2023 14:49:39 +0200 Subject: [PATCH 2/2] Works --- unogenerator.epj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unogenerator.epj b/unogenerator.epj index c14351c..d7f5da6 100644 --- a/unogenerator.epj +++ b/unogenerator.epj @@ -2,7 +2,7 @@ "header": { "comment": "eric project file for project unogenerator", "copyright": "Copyright (C) 2023 , ", - "saved": "2023-07-12, 08:04:29" + "saved": "2023-08-24, 14:49:34" }, "project": { "AUTHOR": "", @@ -52,6 +52,7 @@ }, "MIXEDLANGUAGE": false, "OTHERS": [ + "DOCKER.md", "INSTALL.md", "README.md", "unogenerator.epj" @@ -73,6 +74,7 @@ "tests/benchmark.py", "tests/get_values.py", "tests/metadata.py", + "tests/percentil_color.py", "tests/pregunta.py", "tests/pruebasetcolors.py", "tests/range.py",