#93 completed count

This commit is contained in:
Artem.Arefev 2019-06-05 11:55:51 +04:00
parent 44e3fc2c6e
commit 9bec1d080d
5 changed files with 54 additions and 10 deletions

View File

@ -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,7 +177,7 @@ public class UserController extends OdinController<UserListDto, UserDto> {
}
@GetMapping("/activities")
public Response<Map<String, Integer>> getActivitiesList(@RequestParam("userId") Integer userId,
public Response<Map<String, ActivityElement>> 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));

View File

@ -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 ++;
}
}

View File

@ -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<String, Integer> getUsersActivity(Integer userId, Date dateFrom, Date dateTo) {
public Map<String, ActivityElement> getUsersActivity(Integer userId, Date dateFrom, Date dateTo) {
List<Activity> activities = activityRepository.getByUserAndDateInterval(userId, dateFrom, dateTo);
Map<String, Integer> dateActivities = new HashMap<>();
Map<String, ActivityElement> 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;

View File

@ -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 = {

View File

@ -9,7 +9,7 @@
<script src="/js/core.js"></script>
<script>
google.load('visualization', '1.0', {'packages':['corechart']});
google.setOnLoadCallback(drawChart);
google.setOnLoadCallback(drawActivitiesChart());
</script>
</head>