Activity of Taskgroups

This commit is contained in:
Sebastian Böckelmann 2024-03-18 15:23:40 +01:00
parent 183030611b
commit bbdeaabd1e
4 changed files with 174 additions and 38 deletions

View File

@ -22,6 +22,7 @@ public class StatisticController {
@Autowired private TaskScheduleService taskScheduleService;
@Autowired private StatisticService statisticService;
@Autowired private TaskgroupService taskgroupService;
@GetMapping("/history/workingStatus")
public ResponseEntity<?> getWorkingStatus() {
@ -44,7 +45,22 @@ public class StatisticController {
LocalDate starting = LocalDate.parse(startingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
LocalDate ending = LocalDate.parse(endingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
var taskgroupActivityInfos = statisticService.calcActivityByUser(SecurityContextHolder.getContext().getAuthentication().getName(), starting, ending);
var taskgroupActivityInfos = statisticService.calcActivityByUser(null, SecurityContextHolder.getContext().getAuthentication().getName(), starting, ending);
List<TaskgroupActivityInfo> outgoingResult = StatisticService.convertInternActivityInfo(taskgroupActivityInfos);
return ResponseEntity.ok(outgoingResult);
}
@GetMapping("/statistics/{taskgroupID}/{startingDate}/{endingDate}")
public ResponseEntity<?> getTaskgroupActivity(@PathVariable long taskgroupID, @PathVariable String startingDate, @PathVariable String endingDate){
LocalDate starting = LocalDate.parse(startingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
LocalDate ending = LocalDate.parse(endingDate, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
String username = SecurityContextHolder.getContext().getAuthentication().getName();
var permissionResult = taskgroupService.getTaskgroupByIDAndUsername(taskgroupID, username);
if(permissionResult.hasIssue()) {
return permissionResult.mapToResponseEntity();
}
var taskgroupActivityInfos = statisticService.calcActivityByUser(permissionResult.getResult(), username, starting, ending);
List<TaskgroupActivityInfo> outgoingResult = StatisticService.convertInternActivityInfo(taskgroupActivityInfos);
return ResponseEntity.ok(outgoingResult);
}

View File

@ -21,11 +21,24 @@ public class StatisticService {
@Autowired private ScheduleRepository scheduleRepository;
public HashMap<Taskgroup, HashMap<LocalDate, Integer>> calcActivityByUser(String username, LocalDate startinDate, LocalDate endingDate) {
public HashMap<Taskgroup, HashMap<LocalDate, Integer>> calcActivityByUser(Taskgroup taskgroup, String username, LocalDate startinDate, LocalDate endingDate) {
HashMap<Taskgroup, HashMap<LocalDate, Integer>> taskgroupActivityInfos = new HashMap<>();
List<AbstractSchedule> startedSchedules = scheduleRepository.getAllFinishedSchedulesByUser(username);
for(AbstractSchedule schedule : startedSchedules) {
Taskgroup topTaskgroup = findTopTaskgroup(schedule.getTask().getTaskgroup());
if(schedule.getStartTime().toLocalDate().isAfter(endingDate) || schedule.getStopTime().toLocalDate().isBefore(startinDate)) {
continue;
}
Taskgroup topTaskgroup;
if(taskgroup == null) {
topTaskgroup = findTopTaskgroup(schedule.getTask().getTaskgroup());
} else {
topTaskgroup = findTaskgroupOfLayer(taskgroup, schedule.getTask().getTaskgroup());
if(topTaskgroup == null) {
continue;
}
}
HashMap<LocalDate, Integer> taskgroupActivity;
if(taskgroupActivityInfos.containsKey(topTaskgroup)) {
taskgroupActivity = taskgroupActivityInfos.get(topTaskgroup);
@ -81,4 +94,20 @@ public class StatisticService {
}
return currentTaskgroup;
}
private Taskgroup findTaskgroupOfLayer(Taskgroup targetLayer, Taskgroup childTaskgroup) {
if(targetLayer.getTaskgroupID() == childTaskgroup.getTaskgroupID()) {
return childTaskgroup;
}
Taskgroup currentTaskgroup = childTaskgroup;
while (currentTaskgroup.getParent() != null && currentTaskgroup.getParent().getTaskgroupID() != targetLayer.getTaskgroupID()) {
currentTaskgroup = currentTaskgroup.getParent();
}
if(currentTaskgroup.getParent() == null) {
return null;
}
return currentTaskgroup;
}
}

View File

@ -263,4 +263,69 @@ export class HistoryService {
);
}
/**
* @param taskgroupID internal id of taskgroup
* @param startingDate starting date
* @param endingDate starting date
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public statisticsTaskgroupIDStartingDateEndingDateGet(taskgroupID: number, startingDate: string, endingDate: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<Array<TaskgroupActivityInfo>>;
public statisticsTaskgroupIDStartingDateEndingDateGet(taskgroupID: number, startingDate: string, endingDate: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<Array<TaskgroupActivityInfo>>>;
public statisticsTaskgroupIDStartingDateEndingDateGet(taskgroupID: number, startingDate: string, endingDate: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<Array<TaskgroupActivityInfo>>>;
public statisticsTaskgroupIDStartingDateEndingDateGet(taskgroupID: number, startingDate: string, endingDate: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
if (taskgroupID === null || taskgroupID === undefined) {
throw new Error('Required parameter taskgroupID was null or undefined when calling statisticsTaskgroupIDStartingDateEndingDateGet.');
}
if (startingDate === null || startingDate === undefined) {
throw new Error('Required parameter startingDate was null or undefined when calling statisticsTaskgroupIDStartingDateEndingDateGet.');
}
if (endingDate === null || endingDate === undefined) {
throw new Error('Required parameter endingDate was null or undefined when calling statisticsTaskgroupIDStartingDateEndingDateGet.');
}
let localVarHeaders = this.defaultHeaders;
let localVarCredential: string | undefined;
// authentication (API_TOKEN) required
localVarCredential = this.configuration.lookupCredential('API_TOKEN');
if (localVarCredential) {
localVarHeaders = localVarHeaders.set('Authorization', 'Bearer ' + localVarCredential);
}
let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
if (localVarHttpHeaderAcceptSelected === undefined) {
// to determine the Accept header
const httpHeaderAccepts: string[] = [
'application/json'
];
localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
}
if (localVarHttpHeaderAcceptSelected !== undefined) {
localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
}
let localVarHttpContext: HttpContext | undefined = options && options.context;
if (localVarHttpContext === undefined) {
localVarHttpContext = new HttpContext();
}
let responseType_: 'text' | 'json' = 'json';
if(localVarHttpHeaderAcceptSelected && localVarHttpHeaderAcceptSelected.startsWith('text')) {
responseType_ = 'text';
}
return this.httpClient.get<Array<TaskgroupActivityInfo>>(`${this.configuration.basePath}/statistics/${encodeURIComponent(String(taskgroupID))}/${encodeURIComponent(String(startingDate))}/${encodeURIComponent(String(endingDate))}`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: localVarHeaders,
observe: observe,
reportProgress: reportProgress
}
);
}
}

View File

@ -2,7 +2,7 @@ import {Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from '@an
import {FormControl} from "@angular/forms";
import {ChangeContext, LabelType, Options} from "ngx-slider-v2";
import {ApexAxisChartSeries, ChartComponent, ChartType} from "ng-apexcharts";
import {HistoryService, TaskgroupPathInfo, TaskgroupService} from "../../../../api";
import {HistoryService, TaskgroupActivityInfo, TaskgroupPathInfo, TaskgroupService} from "../../../../api";
import * as moment from "moment/moment";
import {ChartOptions} from "../taskgroup-activity.component";
@ -32,19 +32,43 @@ export class SimpleActivityDiagramComponent implements OnChanges {
@ViewChild("chart") chart?: ChartComponent;
series: ApexAxisChartSeries = []
chartOptions: Partial<ChartOptions> | undefined;
constructor(private taskgroupService: TaskgroupService,
private historyService: HistoryService) {
}
ngOnChanges() {
this.series = [];
this.fetchData()
}
fetchData() {
const startingDate = moment(this.dateRange[0]).format("yyyy-MM-DD");
const endingDate = moment(this.dateRange[this.dateRange.length-1]).format("yyyy-MM-DD");
if(this.selectedTaskgroupPath == undefined) {
this.historyService.statisticsStartingDateEndingDateGet(startingDate, endingDate).subscribe({
next: resp => {
resp.forEach(taskgroupActivityInfo => {
const series = this.createChartSeries(resp);
this.chartOptions = this.createChartOptions(series);
}
})
} else {
this.historyService.statisticsTaskgroupIDStartingDateEndingDateGet(
this.selectedTaskgroupPath.rootTasktroup.taskgroupID,
startingDate,
endingDate
).subscribe({
next: resp => {
const series = this.createChartSeries(resp);
this.chartOptions = this.createChartOptions(series)
}
})
}
}
createChartSeries(data: TaskgroupActivityInfo[]) {
const series: ApexAxisChartSeries = [];
data.forEach(taskgroupActivityInfo => {
const data: any[] = [];
this.dateRange.map(date => {
const selectedActivity = taskgroupActivityInfo.activityInfos.find(activity => moment(date).isSame(moment(activity.date), "day"))
@ -55,14 +79,18 @@ export class SimpleActivityDiagramComponent implements OnChanges {
}
})
this.series.push({
series.push({
name: taskgroupActivityInfo.taskgroup.taskgroupName,
data: data
})
})
this.chartOptions = {
series: this.series,
return series;
}
createChartOptions(series: any[] = []) {
return {
series: series,
chart: {
height: 350,
type: this.selectedChartype as ChartType,
@ -76,8 +104,6 @@ export class SimpleActivityDiagramComponent implements OnChanges {
}
}
}
})
}
createDateRange(): Date[] {
const dates: Date[] = [];