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
1a957b8
Editing Readme
YoanRouleau Sep 15, 2020
a7cd2a3
Printing table average + first question answer
YoanRouleau Sep 15, 2020
57d22cb
getAverage() function ready + 2 firsts question answers
YoanRouleau Sep 15, 2020
9a494c5
Printing table average + first question answer(edited)
YoanRouleau Sep 15, 2020
8c879cc
Max value retriever function is done.
YoanRouleau Sep 15, 2020
dc50f04
Adjustments on average calc function
YoanRouleau Sep 15, 2020
42d4350
Array reverse is now working with a proper approach
YoanRouleau Sep 16, 2020
b5cefcc
Wow this bounding box stuff now works
YoanRouleau Sep 16, 2020
40a043a
Starting randomfillparse() (not done)
YoanRouleau Sep 16, 2020
32c9ed1
Random fill parse improvements
YoanRouleau Sep 16, 2020
f2d7064
Merge branch 'master' of https://github.com/albenoit/BachelorDIM-Lect…
YoanRouleau Sep 16, 2020
60221b6
Tests script added
YoanRouleau Sep 16, 2020
bac1781
Update README.md
YoanRouleau Sep 16, 2020
39175ca
First tests written in the test script
YoanRouleau Sep 16, 2020
6a3e73c
Merge remote-tracking branch 'origin/master'
YoanRouleau Sep 16, 2020
fdec559
Other extra tests
YoanRouleau Sep 16, 2020
e85b78e
Starting unit tests dealing with the averageAboveZero function
YoanRouleau Sep 16, 2020
0f3c70e
Unit tests on max_value
YoanRouleau Sep 16, 2020
3024292
Added some unit tests and finished the random_fill_parse function so …
YoanRouleau Sep 16, 2020
6d8841d
(Better version of last commit) Added some unit tests and finished th…
YoanRouleau Sep 16, 2020
acb74ae
S3 created
YoanRouleau Sep 29, 2020
11747f0
First reverse working properly
YoanRouleau Sep 29, 2020
bb9fdd5
Rerversion but with loops for each pixels
YoanRouleau Sep 29, 2020
4384f3a
Adding a few more reverse function (numpy, cv2)
YoanRouleau Sep 29, 2020
cab6770
Thresholding + UT
YoanRouleau Sep 29, 2020
8feead3
fixes
YoanRouleau Sep 29, 2020
1ffdc27
Threshold that works
YoanRouleau Sep 29, 2020
fc2b47c
Creating 4th assignment
YoanRouleau Oct 13, 2020
3dc7e2d
Merge remote-tracking branch 'teacherFork/master'
YoanRouleau Oct 13, 2020
bbc5388
Creating 4th assignment after merging
YoanRouleau Oct 13, 2020
3b965a2
Testing the publisher out
YoanRouleau Oct 13, 2020
e58a24d
Queue reader implemented
YoanRouleau Oct 13, 2020
1aeaf4a
Getting/sending messages properly. HEy who's the boss now!
YoanRouleau Oct 13, 2020
d241902
Counter OK
YoanRouleau Oct 13, 2020
625e171
Counter + queue_publish_read
YoanRouleau Oct 13, 2020
373de2a
Adding doxygen comments on queue_publish_read
YoanRouleau Oct 13, 2020
017ae5b
Setting up concurrency
YoanRouleau Oct 13, 2020
3004ac4
Setting up the multiple readers in simple_queue_read
YoanRouleau Oct 20, 2020
c264bdd
Fixing previous commit
YoanRouleau Oct 20, 2020
b2eb980
Adding durable=true
YoanRouleau Oct 20, 2020
6f67347
Creating fanout scripts (read/publish)
YoanRouleau Oct 20, 2020
eafb79a
Dice game v1 (missing comments)
YoanRouleau Nov 12, 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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<<<<<<< HEAD
[![Coverage Status](https://coveralls.io/repos/github/YoanRouleau/BachelorDIM-Lectures-Algorithms-2020/badge.svg?branch=master)](https://coveralls.io/github/YoanRouleau/BachelorDIM-Lectures-Algorithms-2020?branch=master)
=======
[![Coverage Status](https://coveralls.io/repos/github/albenoit/BachelorDIM-Lectures-Algorithms-2020/badge.svg?branch=master)](https://coveralls.io/github/albenoit/BachelorDIM-Lectures-Algorithms-2020?branch=master)
>>>>>>> master

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

OOFOOFOOF

Those lessons are addressed to the "Développeur Informatique Multisupports" (DIM) Bachelor proposed at Université Savoie Mont Blanc in France.
Students are expected to be familiar with programming. The aim is to get more familiar with code quality, maintainability and efficacy... and Python.
Expand Down
3 changes: 3 additions & 0 deletions assignements/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions assignements/.idea/assignements.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions assignements/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions assignements/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions assignements/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions assignements/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

171 changes: 171 additions & 0 deletions assignements/S1_algotools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
"""
Created by Yoan ROULEAU
@author: myself
"""
from random import randint

import numpy as np

def average_above_zero(array):
'''
Receives an array as a parameter and calculates its average.

:arg
array: an array
:returns
moy: Its average
'''
som = 0
positive_element_count=0
for i in array:
if i > 0:
som += i
positive_element_count+=1

if positive_element_count > 0:
average = som/positive_element_count
else:
raise ValueError('No positive values found in the array.')
return average


def max_value(array):
'''
Receives an array as a parameter and returns is biggest value

:arg
array: an array
:returns
max: the biggest value of the array
'''
max = 0
for value in array:
if value > max:
max = value

return max


def reverse_table(array):
'''
Gets an array and reverses its values.

:param
array: An array
:return:
Reversed array
'''
arrlength = len(array)
for i in range(arrlength//2):
tmp = array[i]
endValueIndex = arrlength - i - 1
array[i] = array[endValueIndex]
array[endValueIndex] = tmp
return array

def roi_bbox(matrix):
'''
Get the bounds of an "square" assembly in a matrix.

:param
matrix: A matrix
w: matrix's width
h: matrix's height
x1: right bound x coord
y1: right bound y coord
x2: left bound x coord
y2: left bound y coord
:return:
x1, y1, x2, y2
'''
w = matrix.shape[1]
h = matrix.shape[0]
x1 = w
y1 = h
x2 = 0
y2 = 0
x = 0
y = 0
for x in range(w):
for y in range(h):
if matrix[y, x]:
if x < x1:
x1 = x
print("bound entry x1: ", x1)
if y < y1:
y1 = y
print("bound entry y1: ", y1)
if x2 < x:
x2 = x
print("bound entry x2: ", x2)
if y2 < y:
y2 = y
print("bound entry y2: ", y2)
return(x1, y1, x2, y2)


def random_fill_parse(matrix, K):
'''
Function that fills an empty matrix with a specific number of Xs given with the function.

:param
matrix: Empty matrix given with the function call
K: Numbers of awaited Xs in the matrix
:return:
Filled matrix with Xs
'''
if K < matrix.shape[0] * matrix.shape[1]:
i = 0
while i < K:
randH = randint(0, matrix.shape[0]-1)
randW = randint(0, matrix.shape[1]-1)
if matrix[randH, randW] != 'X':
matrix[randH, randW] = 'X'
i += 1
else:
raise ValueError('Numbers of Xs exceeding matrix size.')

return matrix

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

#Matrix used for bbox
H = 12
W = 10
matrix = np.zeros((H,W), dtype=bool)
for c in range(7, 10):
for l in range(6, 9):
matrix[l, c] = 1
matrix[2:4, 2:5] = np.ones((2, 3), dtype=bool)

#Matrix used for randomFillParse
H2 = 15
W2 = 15
matrix = np.zeros((H2,W2), dtype=str)

Tab = [50, 1, 2, 85]
average = average_above_zero(Tab)
print('Average: ', average)
print('Max: ' + str(max_value(Tab)))
print('Reverse: ' + str(reverse_table(Tab)))


bbox = roi_bbox(matrix)
print(bbox)

randomXMatrix = random_fill_parse(matrix, 25)
print(randomXMatrix)



"""
WHAT HAPPENS IF "SOM" INITIALIZATION IS FORGOTTEN ?
-> You get an error saying that Som isn't defined.

WHAT CAN YOU EXPECT IF ALL THE VALUES ARE BELLOW ZERO ?
-> If your values are bellow zero, you wont be able to access the average calculation since you're testing each
values in the array are bellow zero. In the end, the function will attempt to divide 0 by 0 (default values), and throw
and error back.
"""

69 changes: 69 additions & 0 deletions assignements/S1_dice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import random

def dicegame():

#Player data
playerRoll = 0
playerResult = 0
playerRound = 0

#Bot data
botRoll = 0
botRound = 0
botResult = 0

#Game data
interact = 'y'
game = True
botKeepPlaying = 1

while(game):
while(interact == 'y' and playerRoll != 1):
botRound=0
botKeepPlaying = 1
playerRoll = random.randrange(1,7)
playerRound += playerRoll
interact = input("Would you like to keep rolling ? (y or n)")
if(interact == 'q'):
game = False
if(interact != 'y'):
playerResult = playerResult
elif(playerRoll == 1):
playerResult -= playerRound - 1
playerRound = 0
print('Player dice: ',playerRoll)
print('Oh no! you rolled a 1! Your score for this round is reset.')
else:
playerResult += playerRoll
print('Player dice: ',playerRoll)
print('Player total = ',playerResult)
botRoll = 0
if(playerResult >= 100):
interact = 2
game = False
botKeepPlaying = 0
print('PLAYER WINS!!')

while(botRoll != 1 and botKeepPlaying != 0):
playerRound = 0
botRoll = random.randrange(1,7)
botRound += botRoll
botKeepPlaying = random.randrange(0,3)
if(botRoll == 1):
botResult -= botRound - 1
botRound = 0
print('Lucky for you, the bot just rolled a 1 and lost his points...')
else:
botResult += botRoll
print('Bot dice: ', botRoll)
print('Bot total = ', botResult)
playerRoll = 0
interact = 'y'
if (botResult >= 100):
interact = 2
botRoll = 0
game = False
interact='n'
print('BOT WINS...')

dicegame()
Loading