-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/TobiasSchaeuble-EH/LunchHeroes
- Loading branch information
Showing
17 changed files
with
625 additions
and
14 deletions.
There are no files selected for viewing
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
Binary file not shown.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
"""Subpackage related to calculation of distances between users.""" | ||
|
||
from lunchheros.distance._distances import EuclideanDistance, MahattanDistance | ||
|
||
__all__ = ["EuclideanDistances"] | ||
from lunchheros.distance._utils import calculate_distance_matrix | ||
|
||
__all__ = ["EuclideanDistance", "MahattanDistance", "calculate_distance_matrix"] |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Temporarily existing module with utility functions. | ||
When the structure of the subpackage starts to appear, | ||
we will move the functions here to the right packages. | ||
Note: | ||
Treat this submodule as a part of the *private* API. | ||
""" | ||
|
||
from lunchheros.distance._interface import Distance | ||
|
||
import numpy as np | ||
|
||
|
||
def calculate_distance_matrix( | ||
users: list[list], | ||
*, | ||
distance: Distance, | ||
) -> np.ndarray: | ||
"""Calculates a cross-distance matrix | ||
``d[i, j] = distance(trees1[i], trees2[j])`` | ||
Args: | ||
vec1: sequence of trees in one set, length m | ||
vec1: sequence of trees in the second set, length n | ||
distance: distance or similarity function | ||
Returns: | ||
distance matrix, shape (m, n) | ||
""" | ||
m, n = len(users), len(users) | ||
|
||
result = np.zeros((m, n)) | ||
|
||
for i, vec1 in enumerate(users): | ||
for j, vec2 in enumerate(users): | ||
result[i, j] = distance().calculate(vec1, vec2) | ||
# print(f"Distance between user {i} and {j} is {result[i, j]}") | ||
|
||
return result |
Binary file modified
BIN
+80 Bytes
(110%)
backend/src/routes/users/__pycache__/getUserWithId.cpython-311.pyc
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from supabase_client import supabase_client | ||
|
||
|
||
users_select = "*, company:companies(*)" | ||
|
||
def getUserWithId(userId): | ||
return supabase_client.table("users").select(users_select).eq("id", userId).single().execute() | ||
|
||
from supabase_client import supabase_client | ||
|
||
def getAllUsers(): | ||
return supabase_client.table("users").select(users_select).execute() | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Tests for the distance module.""" | ||
|
||
import numpy as np | ||
|
||
from lunchheros.distance import MahattanDistance, calculate_distance_matrix | ||
|
||
|
||
def test_calculate_distance_matrix(): | ||
"""Tests for the calculate_distance_matrix function.""" | ||
|
||
# make 3 vectors of length 4 | ||
a = np.array([1, 2, 3, 4]) | ||
b = np.array([4, 5, 6, 7]) | ||
c = np.array([7, 8, 9, 10]) | ||
# make a list of the vectors | ||
users = [a, b, c] | ||
# calculate the euclidean distance for all pairs of vectors | ||
dist = np.zeros((3, 3)) | ||
for i, vec1 in enumerate(users): | ||
for j, vec2 in enumerate(users): | ||
dist[i, j] = np.sum(np.abs(vec1 - vec2)) | ||
# calculate the manhattan distance using the function | ||
dist2 = calculate_distance_matrix(users, distance=MahattanDistance) | ||
|
||
print(dist) | ||
print(dist2) | ||
assert np.allclose(dist, dist2) |
Oops, something went wrong.