Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
62332e3
testReadMe
Sep 15, 2020
8bc8e11
Average
Sep 15, 2020
c5e4e00
MaximumValue
Sep 15, 2020
5d75dbb
Reverse
Sep 15, 2020
def8616
bbox_enCours
Sep 15, 2020
ad9fb35
Bounding Box
Sep 16, 2020
5dbbc06
BoundingBox
Sep 16, 2020
ae57106
RandomFillSparse
Sep 16, 2020
98d180f
RemoveWhiteSpace
Sep 16, 2020
9fef80d
Shuffle
Sep 16, 2020
c8d5d14
DeEnCours
Sep 16, 2020
aa5854c
Merge branch 'master' of https://github.com/albenoit/BachelorDIM-Lect…
Sep 16, 2020
f43450a
S2
Sep 16, 2020
4cb45f3
Ajout des fichiers existants
Sep 16, 2020
27afc72
session2
Sep 16, 2020
2cedbe9
remove mycodesamples file
Sep 16, 2020
bef1e31
remove myfunctionfile file
Sep 16, 2020
ce5bc56
TestUnit
Sep 16, 2020
750cf15
S3_invert_color_manual
Sep 29, 2020
eb5534b
'restruct'
Sep 29, 2020
e8594d6
test_and_treshold_image_manual
Sep 29, 2020
950ffd5
Fin_de_session
Sep 29, 2020
f795892
pull
Oct 13, 2020
9eb612a
Ajout simple_queue_publish.py
Oct 13, 2020
07d4462
Ajout du script simple_queue_read.py
Oct 13, 2020
fed910b
Fonctionnalité qui compte les messages lus
Oct 13, 2020
d4bfbd4
Ajout queue_publish_read.py
Oct 13, 2020
1a8274e
Commentaires sur queue_publish_read.py
Oct 13, 2020
2c0c55c
Ajout Concurrency à Publish_Reader
Oct 13, 2020
b4e7e3e
Ajout du gitignore
Oct 20, 2020
c9b9772
Multiple Readers
Oct 20, 2020
51d8cc0
Fanout EnCours
Oct 20, 2020
2aae27c
Ajout Dice Game
corentyndormoy Nov 3, 2020
3bdaa40
Ajout sort_selective
corentyndormoy Nov 3, 2020
2c5f9f1
Ajout sort_bubble
corentyndormoy Nov 7, 2020
fb02f0b
Ajout Test alea Right
corentyndormoy Nov 7, 2020
4c72836
Ajout test sort_selective Right
corentyndormoy Nov 7, 2020
bf55c08
Ajout test sort_selective SameNumbers
corentyndormoy Nov 7, 2020
ec08752
Ajout test sort_selective NegativeValues
corentyndormoy Nov 7, 2020
05258e0
Test ajout sort_bubble Right
corentyndormoy Nov 7, 2020
0fec4be
Ajout test sort_bubble SameNumbers
corentyndormoy Nov 7, 2020
96192f2
Ajout test sort_bubble NegativeValues
corentyndormoy Nov 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Session4/mykeys.py
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ addons:
script:
- pytest -v --cov .
#- sonar-scanner
- coveralls
#- coveralls

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
test

# BachelorDIM-Lectures-Algorithms-2020
Algorithms, code writing and continuous integration @ DIM Bachelor, Université Savoie Mont Blanc, France

Expand Down
241 changes: 241 additions & 0 deletions Session1/S1_algotools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
# -*- coding: utf-8 -*-
"""
Éditeur de Spyder

Ceci est un script temporaire.
"""



#Q1 : Si 'som' n'est pas initialisé, le code va planter lorsqy'on fait
#som = som + p_list[i] car lors de la première addition, som n'aura pas de valeur.

#Q2: Si la liste ne contient que des 0, alors le code va planter car n vaudra 0
#or on ne peut pas faire de division par 0.

#Fonction permettant de calculer la moyenne d'une liste dont la valeur est
#supérieur à 0

# @brief : permet de faire la moyenne d'une liste dont les valeurs supérieur à 0
# @param table contient une liste de nombre (float)
# @return retourne la moyenne (float)
def average_below_zero(table:list):
'''
This function calculs the average of a list
Args:
table: a float list
Returns the average of a list
'''
som = 0
n = 0
for i in range(len(table)): #for element in p_list
if(table[i] > 0):
n = n +1
som = som + table[i]
if(n > 0):
moy = som / n
else:
raise ValueError("Division par 0")
print(moy)
return moy

#Test
z = [1,2,5,4]
if(average_below_zero(z) == 3):
print("test1 average_below_zero: Correct")
else:
print("test1 average_below_zero: Incorrect")
#test raise
#z = [-1]


# @brief : permet de trouver la valeur maximale d'une liste de float, ainsi que son index
# @param table contient une liste de nombre (float)
# @return maxi : la valeur maximale; maxiIndex : index de la valeur maximale de la liste table
def max_value(table:list):
'''
This function finds the highest value of a list
Args:
table: a float list
Returns the highest value of a list and its index
Raises
'''
maxi = 0
maxiIndex = None
for i in range(len(table)):
if(table[i] > maxi):
maxi = table[i]
maxiIndex = i
return maxi, maxiIndex

#Test
z = [5,1,3,12,4,7,8,9,2]
if(max_value(z) == (12,3)):
print("test1 max_value: Correct")
else:
print("test1 max_value: Incorrect")


def reverse_table(table:list):
'''
This function reverse a list
Args:
table: a float list
Returns a reversed list
'''
for i in range(len(table)//2): # // permet de faire une division entière
tmp = table[i]
table[i] = table[len(table) - i -1]
table[len(table) - i -1] = tmp

#return table[::-1]
return table

z = [1,2,3,4,5,6,7,8,9]
if(reverse_table(z) == [9,8,7,6,5,4,3,2,1]):
print("test1 reverse_table: Correct")
else:
print("test1 reverse_table: Incorrect")


import numpy as np
def roi_bbox(input_image: np.array):
'''
This function find out the coordinate of a square which got the entire
'1' area
Args:
input_image: is a numpy.array of 0 and 1 values
Returns a 4x2 numpy.array which got the coordinate (X,Y) of the square
which got the entire '1' area
'''
if(1 in input_image):
maxX = 0
maxY = 0
minX = input_image.shape[0]
minY = input_image.shape[1]
for i in range(input_image.shape[0]):
for j in range(input_image.shape[1]):
if(input_image[i,j] == 1):
if(i < minX):
minX = i
if(i > maxX):
maxX = i
if(j < minY):
minY = j
if(j > maxY):
maxY = j
else:
raise ValueError("La matrice ne possède pas de '1'")
#return np.array([[minX,minY],[maxX,minY],[minX,maxY],[maxX,maxY]])
return minX,maxX,minY,maxY
#On peut, en python, renvoyer plusieurs données comme ceci:
#return x,y,z
#Pour les récupérer, il suffit de faire:
#a,b,c = roi_bbox(Xin)
#ou
#mybbox = roi_bbox(Xin)
#a = mybbox[0]
#b = mybbox[1]
#c = mybbox[2]

#Test
W = 100
H = 100
Xin = np.zeros((H,W),dtype=float)

for c in range(45,56):
for l in range(70,91):
Xin[l,c] = 1

for c in range(5,11):
for l in range(75,86):
Xin[l,c] = 1
'''
ou
Xin [70:91,45:56] = npones((20,10)dtype=float)
'''

#Test
#if(roi_bbox(Xin) == np.array([[70,5],[90,5],[70,90],[90,55]])):
# print("test1 roi_bbox: Correct")
#else:
# print("test1 roi_bbox: Incorrect")
print(roi_bbox(Xin))


from random import *
def alea(v):
'''
This function generates a random int
Arg:
v: int, this is the maximum value of the random
Returns an int, a random number between 0 and v
'''
return randint(0,v)

def random_fill_sparse(table:np.array, k:int):
'''
This function fill a chosen number of cell with a 'X' in a matrice
Args:
table: numpy.array, is a matrice
k: int, is the number of cell we want to fill with a 'X'
Returns the matrice with k 'X'
'''
if(k > table.size): #dans le cas où K est supérieur à la taille de la matrice
#alors on remplit toute la matrice
table = np.full(shape=(table.shape[0],table.shape[0]),fill_value="X")
else:
for i in range(k):
rdmX = alea(table.shape[0]-1)
rdmY = alea(table.shape[0]-1)
while(table[rdmX,rdmY] == "X"):
rdmX = alea(table.shape[0]-1)
rdmY = alea(table.shape[0]-1)
table[rdmX,rdmY] = "X"
return table

#Test
W = 5
H = 5
Xin = np.zeros((H,W),dtype=str)
print(random_fill_sparse(Xin,5))


def remove_whitespace(table:str):
'''
This function removes white space
Arg:
table: string, is a sentence
Return a string, table without white space
'''
return table.replace(' ','')

#Test
print(remove_whitespace("bonjour les amis"))


def shuffle(list_in:list):
'''
This function shuffle a list
Arg:
list_in: a list of items
Return a suffled list
'''
rdmIndex = alea(len(list_in) -1)
resultat = [list_in[rdmIndex]]
listIndex = [rdmIndex]
for i in range(len(list_in) -1):
while rdmIndex in(listIndex):
rdmIndex = alea(len(list_in) -1)
resultat.append(list_in[rdmIndex])
listIndex.append(rdmIndex)
return resultat

#Test
#z = [5,1,2,3,4,9,4,7,5]
z = [1,2,3,4,5,6,7,8,9]
print(shuffle(z))


def my_addition(a,b):
return a+b
Loading