Skip to content

Commit

Permalink
PARE FUNZIONARE TUTTO YAY - ditemi se trovate problemi con lo scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
PierpaoloSpadafora committed Dec 6, 2024
1 parent 95ceed7 commit b531f63
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import unical.demacs.rdm.persistence.dto.MachineDTO;
import unical.demacs.rdm.persistence.dto.MachineTypeDTO;
import unical.demacs.rdm.persistence.dto.ScheduleDTO;
import unical.demacs.rdm.persistence.dto.ScheduleWithMachineDTO;
import unical.demacs.rdm.persistence.entities.Job;
import unical.demacs.rdm.persistence.entities.Machine;
import unical.demacs.rdm.persistence.entities.MachineType;
Expand Down Expand Up @@ -112,32 +113,32 @@ public ResponseEntity<List<MachineDTO>> exportMachine() {
@Operation(summary = "Export Job data to JSON", description = "Export all Job data to JSON.",
tags = {"json-controller"})
@GetMapping(value = "/export-job-scheduled-by-priority", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<ScheduleDTO>> exportJobScheduledPriority() {
List<ScheduleDTO> schedules = jsonService.readScheduleFile("./data/job-scheduled-by-priority.json");
public ResponseEntity<List<ScheduleWithMachineDTO>> exportJobScheduledPriority() {
List<ScheduleWithMachineDTO> schedules = jsonService.readScheduleFile("./data/job-scheduled-by-priority.json");
return ResponseEntity.ok(schedules);
}

@Operation(summary = "Export Job data to JSON", description = "Export all Job data to JSON.",
tags = {"json-controller"})
@GetMapping(value = "/export-job-scheduled-by-due-date", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<ScheduleDTO>> exportJobScheduledDueDate() {
List<ScheduleDTO> schedules = jsonService.readScheduleFile("./data/job-scheduled-by-due-date.json");
public ResponseEntity<List<ScheduleWithMachineDTO>> exportJobScheduledDueDate() {
List<ScheduleWithMachineDTO> schedules = jsonService.readScheduleFile("./data/job-scheduled-by-due-date.json");
return ResponseEntity.ok(schedules);
}

@Operation(summary = "Export Job data to JSON", description = "Export all Job data to JSON.",
tags = {"json-controller"})
@GetMapping(value = "/export-job-scheduled-by-duration", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<ScheduleDTO>> exportJobScheduledDuration() {
List<ScheduleDTO> schedules = jsonService.readScheduleFile("./data/job-scheduled-by-duration.json");
public ResponseEntity<List<ScheduleWithMachineDTO>> exportJobScheduledDuration() {
List<ScheduleWithMachineDTO> schedules = jsonService.readScheduleFile("./data/job-scheduled-by-duration.json");
return ResponseEntity.ok(schedules);
}

@Operation(summary = "Export Job data to JSON", description = "Export all Job data to JSON.",
tags = {"json-controller"})
@GetMapping(value = "/export-job-scheduled-ro", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<ScheduleDTO>> exportJobScheduledRO() {
List<ScheduleDTO> schedules = jsonService.readScheduleFile("./data/job-scheduled-ro.json");
public ResponseEntity<List<ScheduleWithMachineDTO>> exportJobScheduledRO() {
List<ScheduleWithMachineDTO> schedules = jsonService.readScheduleFile("./data/job-scheduled-ro.json");
return ResponseEntity.ok(schedules);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ public class JsonServiceImpl implements IJsonService {

private final ObjectMapper objectMapper;

public List<ScheduleDTO> readScheduleFile(String fileName) {
public List<ScheduleWithMachineDTO> readScheduleFile(String fileName) {
File file = new File(fileName);
try {
return objectMapper.readValue(file,
objectMapper.getTypeFactory().constructCollectionType(List.class, ScheduleDTO.class));
objectMapper.getTypeFactory().constructCollectionType(List.class, ScheduleWithMachineDTO.class));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package unical.demacs.rdm.persistence.service.interfaces;

import unical.demacs.rdm.persistence.dto.ScheduleDTO;
import unical.demacs.rdm.persistence.dto.ScheduleWithMachineDTO;

import java.util.List;

public interface IJsonService {
public List<ScheduleDTO> readScheduleFile(String fileName);
public List<ScheduleWithMachineDTO> readScheduleFile(String fileName);
}
7 changes: 5 additions & 2 deletions Backend/src/main/java/unical/demacs/rdm/utils/TimeWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import lombok.AllArgsConstructor;
import lombok.Data;

/**
* Represents a time interval with start and end times in epoch seconds
*/
@Data
@AllArgsConstructor
public class TimeWindow {
private long startTime;
private long endTime;
private long startTime; // Start time in epoch seconds
private long endTime; // End time in epoch seconds
}
26 changes: 26 additions & 0 deletions Frontend/src/app/components/home/home.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@
font-size: 1rem;
}

.machine-type-header {
color: #2c3e50;
font-size: 1.5rem;
margin: 1.5rem 0 1rem;
padding-bottom: 0.5rem;
border-bottom: 2px solid #3498db;
}

.machine-header {
color: #34495e;
font-size: 1.2rem;
margin: 1rem 0;
padding-left: 1rem;
border-left: 3px solid #3498db;
}

@media (max-width: 768px) {
.page-container {
padding: 1rem;
Expand Down Expand Up @@ -210,4 +226,14 @@
.schedule-table tr:nth-child(even) {
background-color: transparent;
}

.machine-type-header {
font-size: 1.3rem;
margin: 1rem 0 0.5rem;
}

.machine-header {
font-size: 1.1rem;
margin: 0.5rem 0;
}
}
77 changes: 56 additions & 21 deletions Frontend/src/app/components/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,62 @@ <h1>Scheduled Jobs</h1>
<div *ngIf="hasScheduledJobs">
<div *ngFor="let date of visibleDates">
<h2>{{ formatDate(date) }}</h2>
<div *ngFor="let machineTypeId of Array.from(schedulesByDateAndMachine.get(date)?.keys() || [])">
<h3>{{ machinesMap.get(machineTypeId) || 'Unknown Machine Type' }}</h3>
<table class="schedule-table">
<thead>
<tr>
<th>Job Title</th>
<th>Start Time</th>
<th>Duration</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let schedule of schedulesByDateAndMachine.get(date)?.get(machineTypeId)">
<td data-label="Job Title">{{ jobsMap.get(schedule.jobId || 0)?.title || 'Unknown Job' }}</td>
<td data-label="Start Time">{{ schedule.startTime | date: 'shortTime' }}</td>
<td data-label="Duration">{{ schedule.duration ? (schedule.duration / 3600) + ' ore' : 'N/A' }}</td>
<td data-label="Status">{{ schedule.status }}</td>
</tr>
</tbody>
</table>
</div>

<!-- Different layout based on schedule type -->
<ng-container *ngIf="selectedScheduleType === 'ALL'; else groupedView">
<div *ngFor="let machineTypeId of Array.from(schedulesByDateAndMachine.get(date)?.keys() || [])">
<h3>{{ machinesMap.get(machineTypeId) || 'Unknown Machine Type' }}</h3>
<table class="schedule-table">
<thead>
<tr>
<th>Job Title</th>
<th>Start Time</th>
<th>Duration</th>
<th>Due Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let schedule of schedulesByDateAndMachine.get(date)?.get(machineTypeId)">
<td data-label="Job Title">{{ jobsMap.get(schedule.jobId || 0)?.title || 'Unknown Job' }}</td>
<td data-label="Start Time">{{ schedule.startTime | date: 'shortTime' }}</td>
<td data-label="Duration">{{ schedule.duration ? (schedule.duration / 3600) + ' ore' : 'N/A' }}</td>
<td data-label="Due Date">{{ schedule.dueDate | date: 'short' }}</td>
<td data-label="Status">{{ schedule.status }}</td>
</tr>
</tbody>
</table>
</div>
</ng-container>

<ng-template #groupedView>
<div *ngFor="let machineType of getUniqueMachineTypes(date)">
<h3 class="machine-type-header">{{ machineType }}</h3>
<div *ngFor="let machineSchedules of getSchedulesForMachineType(date, machineType)">
<h4 class="machine-header">{{ getMachineName(machineSchedules[0].machineId) }}</h4>
<table class="schedule-table">
<thead>
<tr>
<th>Job Title</th>
<th>Start Time</th>
<th>Duration</th>
<th>Due Date</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let schedule of machineSchedules">
<td data-label="Job Title">{{ jobsMap.get(schedule.jobId || 0)?.title || 'Unknown Job' }}</td>
<td data-label="Start Time">{{ schedule.startTime | date: 'shortTime' }}</td>
<td data-label="Duration">{{ schedule.duration ? (schedule.duration / 3600) + ' ore' : 'N/A' }}</td>
<td data-label="Due Date">{{ schedule.dueDate | date: 'short' }}</td>
<td data-label="Status">{{ schedule.status }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</ng-template>
</div>

<div class="pagination-controls" *ngIf="paginatedDates.length > selectedDaysPerPage">
Expand Down
88 changes: 72 additions & 16 deletions Frontend/src/app/components/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Component, OnInit } from '@angular/core';
import { ScheduleControllerService } from '../../generated-api';
import { JobDTO } from '../../generated-api';
import { ScheduleDTO } from '../../generated-api';
import { JsonControllerService } from '../../generated-api';
import { ScheduleControllerService, JobDTO,
JsonControllerService } from '../../generated-api';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { ScheduleWithMachineDTO } from '../../generated-api/model/scheduleWithMachineDTO';

@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
scheduleData: ScheduleDTO[] = [];
scheduleData: ScheduleWithMachineDTO[] = [];
jobsMap: Map<number, JobDTO> = new Map<number, JobDTO>();
machinesMap: Map<number, string> = new Map<number, string>();
machineNamesMap: Map<number, string> = new Map<number, string>(); // New map for machine names

scheduleTypes = [
{ label: 'All Jobs', value: 'ALL' },
Expand All @@ -32,7 +33,7 @@ export class HomeComponent implements OnInit {
hasScheduledJobs = false;
loading = true;

schedulesByDateAndMachine: Map<string, Map<number, ScheduleDTO[]>> = new Map<string, Map<number, ScheduleDTO[]>>();
schedulesByDateAndMachine: Map<string, Map<number, ScheduleWithMachineDTO[]>> = new Map<string, Map<number, ScheduleWithMachineDTO[]>>();

constructor(
private scheduleService: ScheduleControllerService,
Expand All @@ -51,7 +52,7 @@ export class HomeComponent implements OnInit {
fetchData() {
this.loading = true;

let scheduleObservable;
let scheduleObservable: Observable<ScheduleWithMachineDTO[]>;
switch (this.selectedScheduleType) {
case 'PRIORITY':
scheduleObservable = this.jsonService.exportJobScheduledPriority();
Expand All @@ -70,11 +71,11 @@ export class HomeComponent implements OnInit {
}

scheduleObservable.subscribe({
next: (scheduleData: ScheduleDTO[]) => {
next: (scheduleData: ScheduleWithMachineDTO[]) => {
this.scheduleData = scheduleData;

this.jsonService.exportJob().subscribe({
next: (jobs) => {
next: (jobs: JobDTO[]) => {
this.jobsMap.clear();
jobs.forEach(job => {
if (job.id !== undefined) {
Expand All @@ -91,22 +92,38 @@ export class HomeComponent implements OnInit {
}
});

this.processData();
this.loading = false;
// Fetch machine names
this.jsonService.exportMachine().subscribe({
next: (machines) => {
this.machineNamesMap.clear();
machines.forEach(machine => {
if (machine.id !== undefined && machine.name !== undefined) {
this.machineNamesMap.set(machine.id, machine.name);
}
});

this.processData();
this.loading = false;
},
error: (error: unknown) => {
console.error('Error fetching machines data', error);
this.loading = false;
}
});
},
error: (error: any) => {
error: (error: unknown) => {
console.error('Error fetching machine types data', error);
this.loading = false;
}
});
},
error: (error: any) => {
error: (error: unknown) => {
console.error('Error fetching jobs data', error);
this.loading = false;
}
});
},
error: (error: any) => {
error: (error: unknown) => {
console.error('Error fetching schedule data', error);
this.loading = false;
}
Expand All @@ -120,14 +137,14 @@ export class HomeComponent implements OnInit {
}
this.hasScheduledJobs = true;

const schedulesByDateAndMachine: Map<string, Map<number, ScheduleDTO[]>> = new Map();
const schedulesByDateAndMachine: Map<string, Map<number, ScheduleWithMachineDTO[]>> = new Map();

this.scheduleData.forEach(schedule => {
const date = schedule.startTime ? new Date(schedule.startTime).toDateString() : 'Unknown Date';
const machineTypeId = schedule.machineTypeId || 0;

if (!schedulesByDateAndMachine.has(date)) {
schedulesByDateAndMachine.set(date, new Map<number, ScheduleDTO[]>());
schedulesByDateAndMachine.set(date, new Map<number, ScheduleWithMachineDTO[]>());
}

const machineMap = schedulesByDateAndMachine.get(date)!;
Expand Down Expand Up @@ -159,6 +176,40 @@ export class HomeComponent implements OnInit {
});
}

getUniqueMachineTypes(date: string): string[] {
const machineTypeIds = Array.from(this.schedulesByDateAndMachine.get(date)?.keys() || []);
const uniqueTypes = new Set<string>();

machineTypeIds.forEach(id => {
const machineName = this.machinesMap.get(id) || 'Unknown Machine Type';
uniqueTypes.add(machineName);
});

return Array.from(uniqueTypes);
}

getSchedulesForMachineType(date: string, machineTypeName: string): ScheduleWithMachineDTO[][] {
const machineTypeId = Array.from(this.machinesMap.entries())
.find(([_, name]) => name === machineTypeName)?.[0];

if (!machineTypeId) return [];

const schedules = this.schedulesByDateAndMachine.get(date)?.get(machineTypeId) || [];

// Group schedules by machineId
const groupedSchedules = new Map<number, ScheduleWithMachineDTO[]>();

schedules.forEach(schedule => {
const machineId = schedule.machineId || 0;
if (!groupedSchedules.has(machineId)) {
groupedSchedules.set(machineId, []);
}
groupedSchedules.get(machineId)?.push(schedule);
});

return Array.from(groupedSchedules.values());
}

get visibleDates(): string[] {
const start = this.currentPage * this.selectedDaysPerPage;
return this.paginatedDates.slice(start, start + this.selectedDaysPerPage);
Expand Down Expand Up @@ -199,5 +250,10 @@ export class HomeComponent implements OnInit {
return new Intl.DateTimeFormat('it-IT', options).format(date);
}

getMachineName(machineId: number | undefined): string {
if (!machineId) return 'Unknown Machine';
return `${this.machineNamesMap.get(machineId) || 'Unknown'} - ${machineId}`;
}

protected readonly Array = Array;
}
Loading

0 comments on commit b531f63

Please sign in to comment.