WIP: Resolve "Статистика по активностям" #232
@ -176,7 +176,7 @@ public class UserController extends OdinController<UserListDto, UserDto> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/activities")
|
@GetMapping("/activities")
|
||||||
public Response<Map<Date, Integer>> getActivitiesList(@RequestParam("userId") Integer userId,
|
public Response<Map<String, Integer>> 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));
|
||||||
|
@ -49,6 +49,7 @@ import ru.ulstu.utils.timetable.model.Lesson;
|
|||||||
|
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -413,15 +414,16 @@ public class UserService implements UserDetailsService {
|
|||||||
activityRepository.save(activities);
|
activityRepository.save(activities);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Date, Integer> getUsersActivity(Integer userId, Date dateFrom, Date dateTo) {
|
public Map<String, Integer> getUsersActivity(Integer userId, Date dateFrom, Date dateTo) {
|
||||||
List<Activity> activities = activityRepository.getByUserAndDateInterval(userId, dateFrom, dateTo);
|
List<Activity> activities = activityRepository.getByUserAndDateInterval(userId, dateFrom, dateTo);
|
||||||
Map<Date, Integer> dateActivities = new HashMap<>();
|
Map<String, Integer> dateActivities = new HashMap<>();
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
for (Activity activity : activities) {
|
for (Activity activity : activities) {
|
||||||
if (!dateActivities.containsKey(activity.getDate())) {
|
String dt = formatter.format(activity.getDate());
|
||||||
dateActivities.put(activity.getDate(), 1);
|
if (!dateActivities.containsKey(dt)) {
|
||||||
|
dateActivities.put(dt, 1);
|
||||||
} else {
|
} else {
|
||||||
dateActivities.put(activity.getDate(), dateActivities.get(activity.getDate()) + 1);
|
dateActivities.put(dt, dateActivities.get(dt) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dateActivities;
|
return dateActivities;
|
||||||
|
@ -124,4 +124,38 @@ function resetPassword() {
|
|||||||
function isEmailValid(email) {
|
function isEmailValid(email) {
|
||||||
re = /\S+@\S+\.\S+/;
|
re = /\S+@\S+\.\S+/;
|
||||||
return re.test(email)
|
return re.test(email)
|
||||||
|
}
|
||||||
|
|
||||||
|
function drawActivitiesChart() {
|
||||||
|
userId = $('#author :selected').val()
|
||||||
|
dateFrom = $('#dateFrom').val()
|
||||||
|
dateTo = $('#dateTo').val()
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url:`/api/1.0/users/activities?userId=${userId}&dateFrom=${dateFrom}&dateTo=${dateTo}`,
|
||||||
|
contentType: "application/json; charset=utf-8",
|
||||||
|
method: "GET",
|
||||||
|
success: function(response) {
|
||||||
|
if (response.data.length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
array = [['Активности', 'Количество']]
|
||||||
|
|
||||||
|
Object.keys(response.data).forEach(function(key) {
|
||||||
|
console.table('Key : ' + key + ', Value : ' + response.data[key])
|
||||||
|
array.push([key, response.data[key]])
|
||||||
|
})
|
||||||
|
var data = google.visualization.arrayToDataTable(array);
|
||||||
|
var options = {
|
||||||
|
title: 'Активности',
|
||||||
|
is3D: true,
|
||||||
|
pieResidueSliceLabel: 'Остальное'
|
||||||
|
};
|
||||||
|
var chart = new google.visualization.ColumnChart(document.getElementById('air'));
|
||||||
|
chart.draw(data, options);
|
||||||
|
},
|
||||||
|
error: function(errorData) {
|
||||||
|
showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
@ -34,8 +34,8 @@
|
|||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
<br/>
|
<br/>
|
||||||
<input type="date" id="dateFrom"/>
|
<input onchange="drawActivitiesChart();" type="date" id="dateFrom"/>
|
||||||
<input type="date" id="dateTo"/>
|
<input onchange="drawActivitiesChart();" type="date" id="dateTo"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user