WIP: Resolve "Статистика по активностям" #232
@ -21,6 +21,7 @@ import ru.ulstu.odin.controller.OdinController;
|
|||||||
import ru.ulstu.odin.model.OdinMetadata;
|
import ru.ulstu.odin.model.OdinMetadata;
|
||||||
import ru.ulstu.odin.model.OdinVoid;
|
import ru.ulstu.odin.model.OdinVoid;
|
||||||
import ru.ulstu.odin.service.OdinService;
|
import ru.ulstu.odin.service.OdinService;
|
||||||
|
import ru.ulstu.user.model.ActivityElement;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
import ru.ulstu.user.model.UserListDto;
|
import ru.ulstu.user.model.UserListDto;
|
||||||
@ -176,9 +177,9 @@ public class UserController extends OdinController<UserListDto, UserDto> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/activities")
|
@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("dateFrom") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateFrom,
|
||||||
@RequestParam("dateTo") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateTo) {
|
@RequestParam("dateTo") @DateTimeFormat(pattern = "yyyy-MM-dd") Date dateTo) {
|
||||||
return new Response<>(userService.getUsersActivity(userId, dateFrom, dateTo));
|
return new Response<>(userService.getUsersActivity(userId, dateFrom, dateTo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
37
src/main/java/ru/ulstu/user/model/ActivityElement.java
Normal file
37
src/main/java/ru/ulstu/user/model/ActivityElement.java
Normal 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 ++;
|
||||||
|
}
|
||||||
|
}
|
@ -31,6 +31,7 @@ import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException;
|
|||||||
import ru.ulstu.user.error.UserResetKeyError;
|
import ru.ulstu.user.error.UserResetKeyError;
|
||||||
import ru.ulstu.user.error.UserSendingMailException;
|
import ru.ulstu.user.error.UserSendingMailException;
|
||||||
import ru.ulstu.user.model.Activity;
|
import ru.ulstu.user.model.Activity;
|
||||||
|
import ru.ulstu.user.model.ActivityElement;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
import ru.ulstu.user.model.UserInfoNow;
|
import ru.ulstu.user.model.UserInfoNow;
|
||||||
@ -414,16 +415,20 @@ public class UserService implements UserDetailsService {
|
|||||||
activityRepository.save(activities);
|
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);
|
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");
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
for (Activity activity : activities) {
|
for (Activity activity : activities) {
|
||||||
String dt = formatter.format(activity.getDate());
|
String dt = formatter.format(activity.getDate());
|
||||||
if (!dateActivities.containsKey(dt)) {
|
if (!dateActivities.containsKey(dt)) {
|
||||||
dateActivities.put(dt, 1);
|
dateActivities.put(dt, new ActivityElement(1, 1));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
dateActivities.put(dt, dateActivities.get(dt) + 1);
|
ActivityElement element = dateActivities.get(dt);
|
||||||
|
element.incrementCompletedCount();
|
||||||
|
element.incrementStartedCount();
|
||||||
|
dateActivities.put(dt, element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dateActivities;
|
return dateActivities;
|
||||||
|
@ -139,11 +139,12 @@ function drawActivitiesChart() {
|
|||||||
if (response.data.length == 0) {
|
if (response.data.length == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
array = [['Активности', 'Количество']]
|
kk = response.data;
|
||||||
|
array = [['Активности', 'Количество начатых', 'Количество законченных']]
|
||||||
|
|
||||||
Object.keys(response.data).forEach(function(key) {
|
Object.keys(response.data).forEach(function(key) {
|
||||||
console.table('Key : ' + key + ', Value : ' + response.data[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 data = google.visualization.arrayToDataTable(array);
|
||||||
var options = {
|
var options = {
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<script src="/js/core.js"></script>
|
<script src="/js/core.js"></script>
|
||||||
<script>
|
<script>
|
||||||
google.load('visualization', '1.0', {'packages':['corechart']});
|
google.load('visualization', '1.0', {'packages':['corechart']});
|
||||||
google.setOnLoadCallback(drawChart);
|
google.setOnLoadCallback(drawActivitiesChart());
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
Loading…
Reference in New Issue
Block a user