From 9bec1d080da32ae450dcf8bb13beafba9693d170 Mon Sep 17 00:00:00 2001 From: "Artem.Arefev" Date: Wed, 5 Jun 2019 11:55:51 +0400 Subject: [PATCH] #93 completed count --- .../ulstu/user/controller/UserController.java | 7 ++-- .../ru/ulstu/user/model/ActivityElement.java | 37 +++++++++++++++++++ .../ru/ulstu/user/service/UserService.java | 13 +++++-- src/main/resources/public/js/users.js | 5 ++- .../resources/templates/users/activities.html | 2 +- 5 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 src/main/java/ru/ulstu/user/model/ActivityElement.java diff --git a/src/main/java/ru/ulstu/user/controller/UserController.java b/src/main/java/ru/ulstu/user/controller/UserController.java index d18df00..9770ed1 100644 --- a/src/main/java/ru/ulstu/user/controller/UserController.java +++ b/src/main/java/ru/ulstu/user/controller/UserController.java @@ -21,6 +21,7 @@ import ru.ulstu.odin.controller.OdinController; import ru.ulstu.odin.model.OdinMetadata; import ru.ulstu.odin.model.OdinVoid; import ru.ulstu.odin.service.OdinService; +import ru.ulstu.user.model.ActivityElement; import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserListDto; @@ -176,9 +177,9 @@ public class UserController extends OdinController { } @GetMapping("/activities") - public Response> getActivitiesList(@RequestParam("userId") Integer userId, - @RequestParam("dateFrom") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateFrom, - @RequestParam("dateTo") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateTo) { + public Response> getActivitiesList(@RequestParam("userId") Integer userId, + @RequestParam("dateFrom") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateFrom, + @RequestParam("dateTo") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateTo) { return new Response<>(userService.getUsersActivity(userId, dateFrom, dateTo)); } } diff --git a/src/main/java/ru/ulstu/user/model/ActivityElement.java b/src/main/java/ru/ulstu/user/model/ActivityElement.java new file mode 100644 index 0000000..f1e42b6 --- /dev/null +++ b/src/main/java/ru/ulstu/user/model/ActivityElement.java @@ -0,0 +1,37 @@ +package ru.ulstu.user.model; + +public class ActivityElement { + private int startedCount; + private int completedCount; + + public ActivityElement() {} + + public ActivityElement(int startedCount, int completedCount) { + this.startedCount = startedCount; + this.completedCount = completedCount; + } + + public int getStartedCount() { + return startedCount; + } + + public void setStartedCount(int startedCount) { + this.startedCount = startedCount; + } + + public int getCompletedCount() { + return completedCount; + } + + public void setCompletedCount(int completedCount) { + this.completedCount = completedCount; + } + + public void incrementStartedCount() { + this.startedCount ++; + } + + public void incrementCompletedCount() { + this.completedCount ++; + } +} diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 1990194..0004268 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -31,6 +31,7 @@ import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException; import ru.ulstu.user.error.UserResetKeyError; import ru.ulstu.user.error.UserSendingMailException; import ru.ulstu.user.model.Activity; +import ru.ulstu.user.model.ActivityElement; import ru.ulstu.user.model.User; import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserInfoNow; @@ -414,16 +415,20 @@ public class UserService implements UserDetailsService { activityRepository.save(activities); } - public Map getUsersActivity(Integer userId, Date dateFrom, Date dateTo) { + public Map getUsersActivity(Integer userId, Date dateFrom, Date dateTo) { List activities = activityRepository.getByUserAndDateInterval(userId, dateFrom, dateTo); - Map dateActivities = new HashMap<>(); + Map dateActivities = new HashMap<>(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); for (Activity activity : activities) { String dt = formatter.format(activity.getDate()); if (!dateActivities.containsKey(dt)) { - dateActivities.put(dt, 1); + dateActivities.put(dt, new ActivityElement(1, 1)); + } else { - dateActivities.put(dt, dateActivities.get(dt) + 1); + ActivityElement element = dateActivities.get(dt); + element.incrementCompletedCount(); + element.incrementStartedCount(); + dateActivities.put(dt, element); } } return dateActivities; diff --git a/src/main/resources/public/js/users.js b/src/main/resources/public/js/users.js index 2d1244f..82fb9fe 100644 --- a/src/main/resources/public/js/users.js +++ b/src/main/resources/public/js/users.js @@ -139,11 +139,12 @@ function drawActivitiesChart() { if (response.data.length == 0) { return; } - array = [['Активности', 'Количество']] + kk = response.data; + array = [['Активности', 'Количество начатых', 'Количество законченных']] Object.keys(response.data).forEach(function(key) { console.table('Key : ' + key + ', Value : ' + response.data[key]) - array.push([key, response.data[key]]) + array.push([key, response.data[key]['startedCount'], response.data[key]['completedCount']]) }) var data = google.visualization.arrayToDataTable(array); var options = { diff --git a/src/main/resources/templates/users/activities.html b/src/main/resources/templates/users/activities.html index 9527b95..f5c8e1d 100644 --- a/src/main/resources/templates/users/activities.html +++ b/src/main/resources/templates/users/activities.html @@ -9,7 +9,7 @@