This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The worst things I ever had to write. | |
# Origin multi-line from : https://www.geeksforgeeks.org/changing-the-contrast-and-brightness-of-an-image-using-python-opencv/ | |
import cv2 as cv | |
def transform(image, contrast=[0-255](default=128), luminosity=[0-255](default=255)): | |
return (cv.addWeighted(((cv.addWeighted(image, ((255 if (int((brightness - 0) * (255 - (-255)) / (510 - 0) + (-255)))>0 else 255+(int((brightness - 0) * (255 - (-255)) / (510 - 0) + (-255)))) - ((int((brightness - 0) * (255 - (-255)) / (510 - 0) + (-255))) if (int((brightness - 0) * (255 - (-255)) / (510 - 0) + (-255)))>0 else 0)) / 255, image, 0, (int((brightness - 0) * (255 - (-255)) / (510 - 0) + (-255))) if (int((brightness - 0) * (255 - (-255)) / (510 - 0) + (-255)))>0 else 0) if (int((brightness - 0) * (255 - (-255)) / (510 - 0) + (-255))) != 0 else image)), float(131 * ((int((contrast - 0) * (127 - (-127)) / (254 - 0) + (-127))) + 127)) / (127 * (131 - (int((contrast - 0) * (127 - (-127)) / (254 - 0) + (-127))))), ((cv.addWeighted(i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_files_recursive_folder(folder_path:str, file_extension:str) -> list: | |
list_filepath = list() | |
for dirpath, _, filenames in os.walk(folder_path): | |
for filename in [f for f in filenames if f.endswith(file_extension)]: | |
filepath = dirpath.replace("\\","/") + "/" + filename | |
list_filepath.append(filepath) | |
return list_filepath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ijson import items | |
from tqdm import tqdm | |
def count_json_items(filepath:str, path_in_json:str) -> int: | |
with open(filepath, 'r') as file: | |
parser = items(file, path_in_json) | |
i=0 | |
for _ in tqdm(parser, desc="Counting number of items", leave=False): | |
i=i+1 | |
return i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import takewhile, repeat | |
def rawincount(filepath:str) -> int: | |
f = open(filepath, 'rb') | |
bufgen = takewhile(lambda x: x, (f.raw.read(1024*1024) for _ in repeat(None))) | |
return sum(buf.count(b'\n') for buf in bufgen) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from networkx import Graph | |
def print_graph_summary(graph:Graph): | |
nb_node = graph.number_of_nodes() | |
nb_edge = graph.number_of_edges() | |
print("Number of nodes : ", nb_node, "Number of edges : ", nb_edge) | |
return nb_node, nb_edge |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
SHOW = False | |
SAVE = True | |
def display_save_plt(title:str): | |
if SAVE: | |
plt.gcf().set_size_inches(25, 13) | |
plt.savefig("data/stats/" + title + ".png", dpi=200) | |
if SHOW: | |
plt.gcf().set_size_inches(20, 11) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for filename in os.listdir(directory): | |
f = directory + "/" + filename | |
if os.path.isfile(f): | |
print(f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# meta | |
%matplotlib widget # interactive matplotlib for jupyter notebook | |
matplotlib.use('agg') # change backend ('agg' is a static backend => only for saving the image, plt.show() will not work) | |
# Size & Position | |
plt.gcf().set_size_inches(25, 13) # set the size of the chart | |
plt.get_current_fig_manager().window.setGeometry(50,100,640, 545) # configure position & size of the screen (posX, posY, dX, dY) | |
# Chart organisation | |
plt.subplots_adjust(bottom=0.25) # add space at the bottom of the chart for axis title(s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open(filepath, 'rb+') as f: | |
f.seek(-1, 2) | |
f.truncate() |
OlderNewer