Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ARSnova Backend
Manage
Activity
Members
Labels
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Privacy
Imprint
Contact
Snippets
Groups
Projects
Show more breadcrumbs
Paul-Christian Volkmer
ARSnova Backend
Commits
64bfc50e
Commit
64bfc50e
authored
10 years ago
by
Christoph Thelen
Browse files
Options
Downloads
Patches
Plain Diff
Implemented learning progress in just one CouchDB view
parent
5191c77a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/de/thm/arsnova/dao/CouchDBDao.java
+26
-27
26 additions, 27 deletions
src/main/java/de/thm/arsnova/dao/CouchDBDao.java
with
26 additions
and
27 deletions
src/main/java/de/thm/arsnova/dao/CouchDBDao.java
+
26
−
27
View file @
64bfc50e
...
...
@@ -1323,42 +1323,41 @@ public class CouchDBDao implements IDatabaseDao {
}
@Override
public
int
getLearningProgress
(
final
Session
session
)
{
final
NovaView
courseView
=
new
NovaView
(
"learning_progress_course_value/course_value"
);
final
NovaView
maximumView
=
new
NovaView
(
"learning_progress_maximum_value/maximum_value"
);
courseView
.
setKey
(
session
.
get_id
());
maximumView
.
setKey
(
session
.
get_id
());
public
int
getLearningProgress
(
Session
session
)
{
NovaView
progressView
=
new
NovaView
(
"learning_progress/all"
);
progressView
.
setStartKeyArray
(
session
.
get_id
());
progressView
.
setEndKeyArray
(
session
.
get_id
(),
"{}"
);
return
getProgressPercentage
(
courseView
,
maximumView
);
List
<
Document
>
progressResults
=
this
.
getDatabase
().
view
(
progressView
).
getResults
();
// when filtering just by session, the query contains all three values.
return
getProgressPercentage
(
progressResults
,
progressResults
);
}
@Override
public
int
getMyLearningProgress
(
final
Session
session
,
final
User
user
)
{
final
NovaView
userView
=
new
NovaView
(
"learning_progress_user_value/user_value"
);
final
NovaView
maximumView
=
new
NovaView
(
"learning_progress_maximum_value/maximum_value"
);
userView
.
setKey
(
session
.
get_id
(),
user
.
getUsername
());
maximumView
.
setKey
(
session
.
get_id
());
public
int
getMyLearningProgress
(
Session
session
,
User
user
)
{
NovaView
progressView
=
new
NovaView
(
"learning_progress/all"
);
NovaView
maximumView
=
new
NovaView
(
"learning_progress/all"
);
progressView
.
setKey
(
session
.
get_id
(),
user
.
getUsername
());
maximumView
.
setStartKeyArray
(
session
.
get_id
());
maximumView
.
setEndKeyArray
(
session
.
get_id
(),
"{}"
);
return
getProgressPercentage
(
userView
,
maximumView
);
List
<
Document
>
progressResults
=
this
.
getDatabase
().
view
(
progressView
).
getResults
();
List
<
Document
>
maximumResults
=
this
.
getDatabase
().
view
(
maximumView
).
getResults
();
return
getProgressPercentage
(
progressResults
,
maximumResults
);
}
private
int
getProgressPercentage
(
final
NovaView
progressView
,
final
NovaView
maximumView
)
{
final
List
<
Document
>
progressValue
=
getDatabase
().
view
(
progressView
).
getResults
();
final
List
<
Document
>
maximumValue
=
getDatabase
().
view
(
maximumView
).
getResults
();
if
(
maximumValue
.
isEmpty
())
{
private
int
getProgressPercentage
(
List
<
Document
>
progressResults
,
List
<
Document
>
maximumResults
)
{
if
(
progressResults
.
isEmpty
()
||
maximumResults
.
isEmpty
())
{
return
0
;
}
final
int
maximum
=
maximumValue
.
get
(
0
).
getInt
(
"value"
);
int
progress
=
0
;
if
(!
progressValue
.
isEmpty
())
{
if
(
progressValue
.
get
(
0
).
optJSONArray
(
"value"
).
isArray
())
{
JSONArray
courseProgress
=
progressValue
.
get
(
0
).
getJSONArray
(
"value"
);
progress
=
courseProgress
.
getInt
(
0
)
/
courseProgress
.
getInt
(
1
);
}
else
{
progress
=
progressValue
.
get
(
0
).
getInt
(
"value"
);
}
final
int
max
=
maximumResults
.
get
(
0
).
getJSONArray
(
"value"
).
getInt
(
0
);
JSONArray
values
=
progressResults
.
get
(
0
).
getJSONArray
(
"value"
);
final
int
userResult
=
values
.
getInt
(
1
);
final
int
numAnswers
=
values
.
getInt
(
2
);
if
(
numAnswers
==
0
)
{
return
0
;
}
final
int
percentage
=
(
int
)(
progress
*
100.0f
/
maximum
)
;
return
percentage
<
0
?
0
:
percentage
;
final
int
averageResult
=
userResult
/
numAnswers
;
return
(
int
)((
averageResult
*
100.0f
)
/
max
)
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment