from PIL import Image from PIL import ImageFont from PIL import ImageDraw from sqlhandling import Sql from text import Text import random picture = Image.new("RGB", (1500, 1500), "Cyan") Sql.openDataBase('TothBalint', 'postgres', 'localhost', 'pw') Sql.writeQuery(''' SELECT name, budget_value, budget_currency, main_color FROM project WHERE project IS NOT NULL;''') first_tuple_list = Sql.getData() fonttype_list = ["Fonts/Capture_it.ttf", "Fonts/OpenSans-Bold.ttf", "Fonts/AlexBrush-Regular.ttf", "Fonts/Capture_it_2.ttf", "Fonts/FFF_Tusj.ttf", "Fonts/Pacifico.ttf", "Fonts/SEASRN__.ttf"] # Formatting the SQL data so the text object can be created first_list = [list(tuple) for tuple in first_tuple_list] # Changing the currency to EUR for project in first_list: if project[2] == "USD": project[1] = int(float(project[1]) * 0.9) elif project[2] == "GBP": project[1] = int(float(project[1]) * 1.17) else: project[1] = int(float(project[1])) project[2] = "EUR" # Getting rid of the "#" symbol and making a list from the color string project[3] = list(project[3].replace("#", ""))
from PIL import Image from PIL import ImageFont from PIL import ImageDraw from sqlhandling import Sql from text import Text Sql.openDataBase('TothBalint', 'postgres', 'localhost', 'pw') Sql.writeQuery(''' SELECT company_name as "Companies", count(company_name) as "Projects" FROM project GROUP BY company_name ORDER BY count(company_name) DESC''') first_tuple_list = Sql.getData() first_list = [list(tuple) for tuple in first_tuple_list] for i in range(len(first_list)): Sql.writeQuery(''' SELECT main_color FROM project WHERE company_name='%s' and main_color IS NOT NUll;''' % str(first_list[i][0])) new_list = Sql.getData() first_list[i].append(new_list) for color_list in first_list: # [company_name, projects, [(hex1,), (hex2)...]] for i in range(len(color_list[2])): color_list[2][i] = list(color_list[2][i][0][1:]) for y in range(len(color_list[2][i])): color_list[2][i][y] = (int(color_list[2][i][y], 16))*17 r, g, b = 0, 0, 0 r += color_list[2][i][0] g += color_list[2][i][1] b += color_list[2][i][2] if color_list[2] != []: r = int(r/len(color_list[2])) g = int(g / len(color_list[2])) b = int(b / len(color_list[2])) color_list[2] = [r, g, b] else:
from PIL import Image from PIL import ImageFont from PIL import ImageDraw from sqlhandling import Sql from text import Text Sql.openDataBase('TothBalint', 'postgres', 'localhost', 'pw') Sql.writeQuery(''' SELECT company_name as "Companies", count(company_name) as "Projects" FROM project GROUP BY company_name ORDER BY count(company_name) DESC''') first_tuple_list = Sql.getData() first_list = [list(tuple) for tuple in first_tuple_list] picture = Image.new("RGB", (5000, 5000), "black") for text_info in first_list: text = Text(text_info[0], (text_info[1])*30, (255, 0, 0), "Fonts/Capture_it.ttf", 255) for text in Text.text_object_list: text.calculate_length(picture) Text.checkOccupyRatio() Text.order_list() percent = 0 count = 0 for text in Text.ordered_list: picture = text.randomPlace(picture) count += 1 percent = int(count/len(first_list)*100) print(str(percent) + " % completed\nWorking...")
from PIL import Image from PIL import ImageFont from PIL import ImageDraw from sqlhandling import Sql from text import Text Sql.openDataBase('TothBalint', 'postgres', 'localhost', 'pw') Sql.writeQuery('''select manager, max(budget_value) from project group by manager order by max(budget_value) desc limit 5''') first_tuple_list = Sql.getData() first_list = [list(tuple) for tuple in first_tuple_list] picture = Image.new("RGB", (400, 1000), "white") for text_info in first_list: text = Text(text_info[0], 10*(first_list.index(text_info)+1), (255, 255, 255), "Fonts/Capture_it.ttf", 255) for text in Text.text_object_list: text.calculate_length(picture) Text.order_list() for text in Text.ordered_list: text.findPlace_halfPyramid() how_high = int((Text.ordered_list[-1].y + Text.ordered_list[-1].size)*3.5) how_wide = int(Text.ordered_list[0].length*1.5) picture = Image.new("RGB", (how_wide, how_high), "black") rotate_rates = [0, 90, 180, 270]
from PIL import Image from PIL import ImageFont from PIL import ImageDraw from sqlhandling import Sql from text import Text Sql.openDataBase('TothBalint', 'postgres', 'localhost', 'pw') Sql.writeQuery('''SELECT company_name , MAX(CAST(budget_value AS FLOAT)) AS max_budget FROM project GROUP BY company_name ORDER BY max_budget DESC''') first_tuple_list = Sql.getData() first_list = [list(tuple) for tuple in first_tuple_list] picture = Image.new("RGB", (1000, 1000), "gold") for text_info in first_list: text = Text((text_info[0] + ":" + str(text_info[1])), (int(float(text_info[1])/700))+1, (0,0,0), "Fonts/FFF_Tusj.ttf", 255) for text in Text.text_object_list: text.calculate_length(picture) Text.checkOccupyRatio() Text.order_list() percent = 0 count = 0 for text in Text.ordered_list: picture = text.randomPlace(picture) count += 1 percent = int(count/len(first_list)*100) print(str(percent) + " % completed\nWorking...")