Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d6020fb
initial commit
Sep 15, 2020
1630176
Add average function
Sep 15, 2020
33ba87c
Add max value in tab function
Sep 15, 2020
981fac8
Add reverse function
Fabien-V Sep 15, 2020
91ab204
Add reverse function V2
Fabien-V Sep 16, 2020
d4c9444
Add Bounding Box function
Fabien-V Sep 16, 2020
dc548e0
Add travis and requirements
Fabien-V Sep 16, 2020
7892cae
Update requirements versions
Fabien-Vauclin Sep 17, 2020
810fee2
Add coveralls config
Fabien-Vauclin Sep 17, 2020
e1e371f
Add Tests My Addition
Fabien-Vauclin Sep 17, 2020
900fe0b
Add Coveralls Badge
Fabien-Vauclin Sep 20, 2020
691b0eb
Add My Addition function
Fabien-Vauclin Sep 20, 2020
76883c2
Update organization for Sonar in travis config
Fabien-Vauclin Sep 26, 2020
89dd667
Update Reverse a table V2
Fabien-Vauclin Sep 26, 2020
71ba476
Fix Reverse a table V2
Fabien-Vauclin Sep 26, 2020
5524f70
Add Remove whitespace function
Fabien-Vauclin Sep 26, 2020
b36743d
Add Test for Remove whitespace function
Fabien-Vauclin Sep 26, 2020
5c8aaf3
Add Random item function
Fabien-Vauclin Sep 26, 2020
0048068
Add Shuffle function (in progress)
Fabien-Vauclin Sep 26, 2020
c0a1f1d
Update Dice Game (in progress)
Fabien-Vauclin Sep 27, 2020
5c936c6
Add Load an image using the OpenCV library
Fabien-Vauclin Sep 29, 2020
6eb8349
Add Inv Gray Levels function
Fabien-Vauclin Sep 29, 2020
465623d
Add Tests for S3 Imgproc
Fabien-Vauclin Sep 29, 2020
fa1a96c
Fix Tests for S3 Imgproc
Fabien-Vauclin Sep 29, 2020
893000c
Add Simple queue publish and read
Fabien-Vauclin Oct 13, 2020
79f873a
Add Queue Publish and Read
Fabien-Vauclin Nov 11, 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Algorithms, code writing and continuous integration @ DIM Bachelor, Université
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.

# Coveralls Badge
[![Coverage Status](https://coveralls.io/repos/github/Fabien-Vauclin/BachelorDIM-Lectures-Algorithms-2020/badge.svg?branch=master)](https://coveralls.io/github/Fabien-Vauclin/BachelorDIM-Lectures-Algorithms-2020?branch=master)

**Lessons organisation draft :**

1. Get familiar with maintainable codes using git, sonarcloud and doxygen. *Introduction* slides [here](https://docs.google.com/presentation/d/1xXrdokfxOUP-3b1fEPRfieUhOEez7FJeUtauMpjV4bk/edit?usp=sharing)
Expand Down
2 changes: 2 additions & 0 deletions assignements/.coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
service_name: travis-pro
repo_token: z9ivIKMPKpXWWp1TiUR46oKvPMzRXqclQ
14 changes: 14 additions & 0 deletions assignements/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: python
python:
- "3.8"
# command to install dependencies
install:
- pip install -r requirements.txt
addons:
sonarcloud:
organization: Fabien-Vauclin-github
# command to run tests
script:
- pytest -v --cov
#- sonar-scanner
- coveralls
142 changes: 142 additions & 0 deletions assignements/S1_algotools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Average
def average(tab):
"""
Calculate the average of a list
Parameters
tab
Returns the average of the list
"""
som = 0
n = 0
for i in range(len(tab)):
if tab[i] > 0:
som = som + tab[i]
n = n + 1
moy = som / n
print(moy)


average([100, 20, 30])


# Maximum value
def max_value_in_tab(tab):
"""
Get the maximum value of a tab
Parameters
tab
Returns the maximum value of a tab
"""
max = tab[0]
for a in tab:
if a > max:
max = a
return max


print(max_value_in_tab([1, 12, -8, 300]))


# Reverse a table
tab = [100, 'abc', 437, 'def', 123]
tab.reverse()
print(tab)

# Reverse a table V2
def reverse_table(tab):
"""
Reverse a table
Parameters
table of numbers
Returns reversed table
"""
for i in range(len(tab)//2):
list_len = len(tab)
tmp = tab[i]
endid = list_len - i - 1
tab[i] = tab[list_len - 1]
tab[i] = tab[endid]
tab[endid] = tmp
return tab


print(reverse_table([100, 200, 300, 400]))


# Bounding box

import numpy as np

def bounding_box(matrix):
"""
Compute the bounding box coordinates of an object
Parameters
matrix
Returns numpy array of shape 4x2 filled with the four 2d coordinates
"""
w = matrix.shape[1]
h = matrix.shape[0]
x1 = w
y1 = h
x2 = 0
y2 = 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)

# Random array filling

#Remove whitespace characters in a string:
def remove_whitespace(string):
"""
Parse a string and remove all its whitespace
Parameters
string
Returns string without whitespaces
"""
return string.replace(" ", "")


string = ' l p d i m '
print(remove_whitespace(string))

# Random item selection
import random

def random_item(list:any):

"""
Randomly select item of a list
Parameters
list
Returns one item of the list
"""
return random.choice(list)


list = 1, 6, "b", 12, "k", 8, "LP DIM", 2020, "Overkiz", "Hr Team"
print(random_item(list))

# Personal test for testing numpy with Pycharm
a = np.array([1, 2, 4])
print(a)

# My Addition function
def my_addition(a, b):
return a+b

print('10+2=12 ?',my_addition(10,2))
56 changes: 56 additions & 0 deletions assignements/S1_dice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""
@author: fabien-v
"""

# Dice Game


def shuffle():

import random
user_score = 0
computer_score = 0
minimum = 1
maximum = 6
user_roll = random.randint(minimum, maximum)
computer_roll = random.randint(minimum, maximum)

if user_roll == 1:
user_score += 1
elif user_roll == 2:
user_score += 2
elif user_roll == 3:
user_score += 3
elif user_roll == 4:
user_score += 4
elif user_roll == 5:
user_score += 5
elif user_roll == 6:
user_score += 6

if user_score == 100:
print("user win !")
if computer_score == 100:
print("computer win !")

# idea / in progress

# boucle avec
# Tant que user_try > 1
# roll_again (continue ?)

# Si user_try == 1
# alors c'est au tour de à computer_try et ainsi de suite













55 changes: 55 additions & 0 deletions assignements/S3_imgproc_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import cv2
import numpy as np
img = cv2.imread('/home/fabien/Pictures/algo_img.jpg')

print("input image shape", img.shape)

cv2.imshow('input', img)
cv2.waitKey()

img_out = np.zeros(img.shape, dtype=np.uint8)

for row in range(img.shape[0]):
for col in range(img.shape[1]):
for channel in range (img.shape[2]):
img_out[row, col, channel] = 255-img[row, col, channel]

cv2.imshow("output", img_out)
cv2.waitKey()


def invert_colors_numpy(input_img):
'''

This function reverse the color of an image
Parameters:
input_img: an image
Returns: a reversed image. It's the optimal solution.

'''
return 255 - input_img


img_gray = cv2.imread("/home/fabien/Pictures/algo_img.jpg", 0)
img_bgr = cv2.imread("/home/fabien/Pictures/algo_img.jpg", 1)
img_bgr_reversed = invert_colors_numpy(cv2.imread("/home/fabien/Pictures/algo_img.jpg", 1))

cv2.imshow("Gray levels image", img_gray)
cv2.imshow("BGR image", img_bgr)
cv2.imshow("BGR image inverted", img_bgr_reversed)
cv2.waitKey()


img = cv2.imread("/home/fabien/Pictures/algo_img.jpg")
def inv_gray_levels(img):
if img is None:
raise ValueError("expected an uint8 and array")
if not (isinstance(img, np.ndarray)):
raise TypeError("expected and nd array")
if img.dtype!=np.dtype(np.uint8):
raise TypeError("expected uint8 typed nd array")
return 255-img
print(inv_gray_levels(img))



22 changes: 22 additions & 0 deletions assignements/queue_publish_read.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import argparse
import pika, os
from assignements import simple_queue_publish
from assignements import simple_queue_read
from assignements import mykey

url = os.environ.get('CLOUDAMQP_URL', mykey.myKey)
params = pika.URLParameters(url)
params.socket_timeout = 5
connection = pika.BlockingConnection(params)
channel = connection.channel() # start a channel
channel.queue_declare(queue='hello') # Declare a queue

parser = argparse.ArgumentParser(description='How to')
parser.add_argument('-read', action='store_true')
flags = parser.parse_args()

if(flags.read):
simple_queue_read.read_queue(channel)
else:
simple_queue_publish.publish_queue(channel)
connection.close()
9 changes: 9 additions & 0 deletions assignements/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
matplotlib>=3.3.2
numpy>=1.19.2
pika>=1.1.0
pytest>=6.0.2
python-dateutil>=2.8.1
scipy>=1.5.2
urllib3>=1.25.10
pytest-cov>=2.10.1
coveralls>=2.1.2
20 changes: 20 additions & 0 deletions assignements/simple_queue_publish.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# publish.py
import pika
import os
from assignements import mykey


# Access the CLODUAMQP_URL environment variable and parse it (fallback to localhost)


url = os.environ.get('CLOUDAMQP_URL', mykey.myKey)
params = pika.URLParameters(url)
connection = pika.BlockingConnection(params)
channel = connection.channel() # start a channel
channel.queue_declare(queue='hello') # Declare a queue
channel.basic_publish(exchange='',
routing_key='hello',
body='Hello CloudAMQP!')

print(" [x] Sent 'Hello World!'")
connection.close()
21 changes: 21 additions & 0 deletions assignements/simple_queue_read.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# consume.py
import pika, os

# Access the CLODUAMQP_URL environment variable and parse it (fallback to localhost)
from assignements import mykey

url = os.environ.get('CLOUDAMQP_URL', mykey.myKey)
params = pika.URLParameters(url)
connection = pika.BlockingConnection(params)
channel = connection.channel() # start a channel
channel.queue_declare(queue='hello') # Declare a queue
def callback(ch, method, properties, body):
print(" [x] Received " + str(body))

channel.basic_consume('hello',
callback,
auto_ack=True)

print(' [*] Waiting for messages:')
channel.start_consuming()
connection.close()
15 changes: 15 additions & 0 deletions assignements/test_S2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import S1_algotools as tobetested
import pytest

def test_myaddition_integers_1():
assert tobetested.my_addition(10,2) == 12

def test_myaddition_integers_2():
assert tobetested.my_addition(-1,2) == 1

def test_myaddition_wrong_input():
with pytest.raises(TypeError):
tobetested.my_addition('a',2)

def test_remove_whitespace():
assert tobetested.remove_whitespace("t e s t m y f u n c t i o n")
17 changes: 17 additions & 0 deletions assignements/test_S3_imgproc_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import numpy as np
import pytest
import S3_imgproc_tools as algo
null_matrix = np.zeros((10, 10), dtype = bool)

def test_invert_colors_numpy_None():
with pytest.raises(ValueError):
algo.inv_gray_levels(None)


def test_invert_colors_numpy_Aray():
with pytest.raises(TypeError):
algo.inv_gray_levels(1)

def test_invert_colors_numpy_uint8():
with pytest.raises(TypeError):
algo.inv_gray_levels(null_matrix)