Skip to content
This repository was archived by the owner on Mar 1, 2021. It is now read-only.

Commit 6f7895a

Browse files
committed
add mvp for profile selection
1 parent fbdb807 commit 6f7895a

File tree

11 files changed

+1451
-100
lines changed

11 files changed

+1451
-100
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ docker-compose.yml
1111
*/Dockerfile
1212
Dockerfile
1313
*.Dockerfile
14+
.dockerignore
1415

1516
# PYTHON stuff
1617
__pycache__/
1718
*.pyc
1819
*faces/env/*
1920
*faces/images/*
2021
frontend
22+
Makefile

api/grpcserver/grpc_server.go

+47-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"database/sql"
7+
"encoding/base64"
78
"fmt"
89
"log"
910
"net"
@@ -12,7 +13,6 @@ import (
1213
"strings"
1314
"time"
1415
// required for postgres
15-
"encoding/base64"
1616
_ "github.com/lib/pq"
1717
"github.com/segmentio/kafka-go"
1818

@@ -293,7 +293,6 @@ func (s *GrpcServer) getURLForPost(object string) (string, error) {
293293
log.Println(err)
294294
return "", err
295295
}
296-
fmt.Println("Successfully generated presigned URL", presignedURL)
297296
return presignedURL.String(), nil
298297

299298
}
@@ -379,3 +378,49 @@ func (s *GrpcServer) SearchSimilarFaces(ctx context.Context, request *proto.Face
379378

380379
return &proto.FaceSearchResponse{Faces: responseFaces}, nil
381380
}
381+
382+
// SearchUsersWithWeightedPosts searches for users by their occurence in posts, taking the weights into account
383+
func (s *GrpcServer) SearchUsersWithWeightedPosts(ctx context.Context, weightedPosts *proto.WeightedPosts) (*proto.WeightedUsers, error) {
384+
userIDToFaces := map[string]*proto.UserWithFaces{}
385+
for _, post := range weightedPosts.Posts {
386+
rows, err := s.db.Query(`SELECT u.id, COALESCE(user_name, '') as user_name,
387+
COALESCE(u.real_name, '') as real_name,
388+
COALESCE(u.bio, '') as bio,
389+
COALESCE(u.avatar_url, '') as avatar_url
390+
FROM users u
391+
INNER JOIN posts p on p.user_id = u.id
392+
WHERE p.id = $1`, post.PostId)
393+
394+
if err != nil {
395+
return nil, err
396+
}
397+
398+
defer rows.Close()
399+
400+
for rows.Next() {
401+
user := &proto.User{}
402+
403+
err := rows.Scan(&user.Id, &user.UserName, &user.RealName, &user.Bio, &user.AvatarUrl)
404+
if err != nil {
405+
return nil, err
406+
}
407+
408+
if userIDToFaces[user.Id] == nil {
409+
userIDToFaces[user.Id] = &proto.UserWithFaces{User: user}
410+
}
411+
412+
wrappedUser := userIDToFaces[user.Id]
413+
414+
wrappedUser.Faces = append(wrappedUser.Faces, post.Faces...)
415+
wrappedUser.Weight += post.Weight
416+
}
417+
}
418+
419+
weightedUsers := &proto.WeightedUsers{}
420+
421+
for _, user := range userIDToFaces {
422+
weightedUsers.UsersWithFaces = append(weightedUsers.UsersWithFaces, user)
423+
}
424+
425+
return weightedUsers, nil
426+
}

0 commit comments

Comments
 (0)