Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MemeOClock Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s78456
MemeOClock Backend
Merge requests
!22
Bf3 feed anzeigen
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Bf3 feed anzeigen
BF3-feed-anzeigen
into
develop
Overview
1
Commits
18
Pipelines
0
Changes
6
Merged
Amelie Brucker
requested to merge
BF3-feed-anzeigen
into
develop
4 years ago
Overview
1
Commits
18
Pipelines
0
Changes
6
Expand
Tracking von gesehenen Memes und bewerteten Tags funktioniert, Memes für den Feed werden geladen
0
0
Merge request reports
Compare
develop
develop (base)
and
latest version
latest version
829ed7e7
18 commits,
4 years ago
6 files
+
151
−
76
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
Search (e.g. *.vue) (Ctrl+P)
Algorithmus/tagRating.js
+
41
−
22
Options
const
userService
=
require
(
'
../User/Services/userService
'
);
//
TODO:
tagLikeDislikeArray in req contains tagName,
tlr, neutralValue,
totalMemes, likes and dislikes as value
//tagLikeDislikeArray in req contains tagName, totalMemes, likes and dislikes as value
//sets an array called tlrArray with {tagId, tagName, neutralValue, tlr}
function
setTLRForAllTags
(
req
,
res
,
next
)
{
let
tags
=
[];
function
setTLRForAllTags
(
req
,
res
,
next
)
{
if
(
!
req
.
body
.
tagLikeDislikeArray
){
return
res
.
status
(
400
).
json
({
error
:
'
No tagLikeDislikeArray
'
});
}
let
tagLikeDislikeArray
=
req
.
body
.
tagLikeDislikeArray
;
let
likeRatio
;
let
newTlr
;
for
(
let
tag
of
req
.
body
.
tagLikeDislikeArray
){
likeRatio
=
tag
.
neutralValue
+
(
tag
.
likes
/
tag
.
totalMemes
)
*
0.5
-
(
tag
.
dislikes
/
tag
.
totalMemes
)
*
0.5
;
if
(
likeRatio
>
1
){
likeRatio
=
1
;
}
else
if
(
likeRatio
<
0
){
likeRatio
=
0
;
userService
.
getRatedTagsOfUserById
(
req
.
tokenUserId
,
(
err
,
tagarray
)
=>
{
if
(
err
||
!
tagarray
)
{
return
res
.
status
(
500
).
json
({
error
:
'
Missing db response while getting tags of User
'
});
}
newTlr
=
0.8
*
tag
.
tlr
+
0.2
*
likeRatio
;
tags
.
push
({
tagName
:
tag
.
tagName
,
neutralValue
:
tag
.
neutralValue
,
tlr
:
newTlr
});
}
req
.
body
.
ratedTags
=
tags
;
next
();
for
(
let
tag
of
tagLikeDislikeArray
)
{
let
tagInTagArray
=
tagarray
.
find
(
element
=>
element
.
tagName
==
tag
.
tagName
);
if
(
tagInTagArray
)
{
let
index
=
tagarray
.
indexOf
(
tagInTagArray
);
likeRatio
=
tagInTagArray
.
neutralValue
+
(
tag
.
likes
/
tag
.
totalMemes
)
*
0.5
-
(
tag
.
dislikes
/
tag
.
totalMemes
)
*
0.5
;
if
(
likeRatio
>
1
)
{
likeRatio
=
1
;
}
else
if
(
likeRatio
<
0
)
{
likeRatio
=
0
;
}
newTlr
=
0.8
*
tagInTagArray
.
tlr
+
0.2
*
likeRatio
;
tagInTagArray
.
tlr
=
newTlr
;
tagarray
[
index
]
=
tagInTagArray
;
}
else
{
//in case frontend provides tags, which are missing in user object, they are added
//should not happend regulary
likeRatio
=
0.5
+
(
tag
.
likes
/
tag
.
totalMemes
)
*
0.5
-
(
tag
.
dislikes
/
tag
.
totalMemes
)
*
0.5
;
newTlr
=
0.4
+
0.2
*
likeRatio
;
tagarray
.
push
({
tagName
:
tag
.
tagName
,
neutralValue
:
0.5
,
tlr
:
newTlr
})
}
}
req
.
body
.
ratedTags
=
tagarray
;
next
();
})
}
//AS IN USERMODEL PROVIDED: ratedTags in req contains tagName and tlr
//sets an array called tlrs with tagId and the "modified for algorithm"-tlr: {tagId, tlr}
//array contains all liked tags (not all tags!)
function
setAlgorithmTLRForAllTags
(
req
,
res
,
next
)
{
if
(
!
req
.
tokenUserId
){
if
(
!
req
.
tokenUserId
)
{
return
next
();
}
userService
.
getAlgorithmDataById
(
eq
.
tokenUserId
,
(
err
,
values
)
=>
{
if
(
err
){
userService
.
getAlgorithmDataById
(
r
eq
.
tokenUserId
,
(
err
,
values
)
=>
{
if
(
err
)
{
return
next
();
}
let
likedTags
=
[];
let
weightedValue
=
0
;
for
(
let
tag
of
values
.
ratedTags
){
if
(
tag
.
tlr
>
0.5
){
for
(
let
tag
of
values
.
ratedTags
)
{
if
(
tag
.
tlr
>
0.5
)
{
weightedValue
=
tag
.
tlr
-
0.5
;
likedTags
.
push
({
tagName
:
tag
.
tagName
,
tlr
:
weightedValue
});
likedTags
.
push
({
tagName
:
tag
.
tagName
,
tlr
:
weightedValue
});
}
}
req
.
values
=
({
tlrs
:
likedTags
,
followedUsers
:
values
.
following
,
seenMemes
:
values
.
seenMemes
});
req
.
values
=
({
tlrs
:
likedTags
,
followedUsers
:
values
.
following
,
seenMemes
:
values
.
seenMemes
});
next
();
})
})
}
module
.
exports
=
{
Loading