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
8ce529d3
Commit
8ce529d3
authored
10 years ago
by
Christoph Thelen
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'private/master'
Conflicts: src/main/java/de/thm/arsnova/dao/CouchDBDao.java
parents
7ae2a9e3
64bfc50e
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
src/main/java/de/thm/arsnova/dao/CouchDBDao.java
+31
-27
31 additions, 27 deletions
src/main/java/de/thm/arsnova/dao/CouchDBDao.java
src/main/java/de/thm/arsnova/dao/IDatabaseDao.java
+2
-1
2 additions, 1 deletion
src/main/java/de/thm/arsnova/dao/IDatabaseDao.java
with
34 additions
and
28 deletions
.gitignore
+
1
−
0
View file @
8ce529d3
...
...
@@ -4,3 +4,4 @@
target/*
chromedriver.log
.checkstyle
/target
This diff is collapsed.
Click to expand it.
src/main/java/de/thm/arsnova/dao/CouchDBDao.java
+
31
−
27
View file @
8ce529d3
...
...
@@ -23,6 +23,8 @@ import java.io.IOException;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.text.SimpleDateFormat
;
import
java.util.AbstractMap
;
import
java.util.AbstractMap.SimpleEntry
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Date
;
...
...
@@ -1323,42 +1325,44 @@ 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
SimpleEntry
<
Integer
,
Integer
>
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
();
int
myprogress
=
getProgressPercentage
(
progressResults
,
maximumResults
);
int
courseprogress
=
getProgressPercentage
(
maximumResults
,
maximumResults
);
return
new
AbstractMap
.
SimpleEntry
<
Integer
,
Integer
>(
myprogress
,
courseprogress
);
}
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
())
{
final
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.
src/main/java/de/thm/arsnova/dao/IDatabaseDao.java
+
2
−
1
View file @
8ce529d3
...
...
@@ -19,6 +19,7 @@
package
de.thm.arsnova.dao
;
import
java.util.AbstractMap.SimpleEntry
;
import
java.util.List
;
import
de.thm.arsnova.connector.model.Course
;
...
...
@@ -164,5 +165,5 @@ public interface IDatabaseDao {
int
getLearningProgress
(
Session
session
);
int
getMyLearningProgress
(
Session
session
,
User
user
);
SimpleEntry
<
Integer
,
Integer
>
getMyLearningProgress
(
Session
session
,
User
user
);
}
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