Skip to content
Snippets Groups Projects
Commit d85b4b8f authored by ArianaJogi's avatar ArianaJogi
Browse files

Fixed the date frequency bug and a bug which states that the tickets should be...

Fixed the date frequency bug and a bug which states that the tickets should be shown only based on the start date #133 #140
parent 858c680c
No related branches found
No related tags found
No related merge requests found
Pipeline #48313 passed
......@@ -377,19 +377,12 @@ export default {
// Extracts start and end dates
const start = new Date(startDate);
const end = new Date(endDate);
// Adjusts the end date based on frequency
if (frequency === 'monthly') {
end.setMonth(end.getMonth() + 1);
end.setDate(0); // Sets to the last day of the month
} else if (frequency === 'yearly') {
end.setFullYear(end.getFullYear() + 1);
end.setDate(0); // Sets to the last day of the previous year
}
end.setHours(23, 59, 59, 999);
// Daily grouping
if (frequency === 'daily') {
let currentDate = new Date(start);
currentDate.setHours(0, 0, 0, 0);
while (currentDate <= end) {
const dateKey = this.formatDate(currentDate);
......@@ -442,25 +435,71 @@ export default {
}
currentDate.setDate(currentDate.getDate() + 1); // Moves to the next day
currentDate.setHours(0, 0, 0, 0);
}
}
// Monthly grouping
else if (frequency === 'monthly') {
let currentDate = new Date(start);
// Check if start and end are in the same month
if (start.getFullYear() === end.getFullYear() && start.getMonth() === end.getMonth()) {
const sameMonthKey = `${this.formatDate(start)} - ${this.formatDate(end)}`;
const tempGroupedDataSameMonth = {};
while (currentDate <= end) {
const monthStart = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1);
const monthEnd = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0, 23, 59, 59, 999);
const dateRangeKey = `${this.formatDate(monthStart)} - ${this.formatDate(monthEnd)}`; // e.g., "1.10.2023 - 31.10.2023"
const tempGroupedData = {};
tickets.forEach(ticket => {
const ticketDate = new Date(ticket.date);
if (ticketDate >= start && ticketDate <= end) {
const uniqueKeyParts = [ticket.upperSpecies];
if (this.selectedSpecies.length > 0) {
uniqueKeyParts.push(ticket.species);
}
if (this.selectedRegions.length > 0) {
uniqueKeyParts.push(ticket.region);
}
if (this.selectedInjuries.length > 0) {
uniqueKeyParts.push(ticket.injuries.join(','));
}
if (this.selectedResolutions.length > 0) {
uniqueKeyParts.push(ticket.resolution);
}
const uniqueKey = uniqueKeyParts.join('|');
if (!tempGroupedDataSameMonth[uniqueKey]) {
tempGroupedDataSameMonth[uniqueKey] = {
date: sameMonthKey,
upperSpecies: ticket.upperSpecies,
species: this.selectedSpecies.length > 0 ? ticket.species : null,
region: this.selectedRegions.length > 0 ? ticket.region : null,
injuries: this.selectedInjuries.length > 0 ? ticket.injuries : [],
resolution: this.selectedResolutions.length > 0 ? ticket.resolution : null,
count: 0
};
}
tempGroupedDataSameMonth[uniqueKey].count += 1;
}
});
for (const key in tempGroupedDataSameMonth) {
if (tempGroupedDataSameMonth[key].count > 0) {
if (!groupedData[sameMonthKey]) {
groupedData[sameMonthKey] = [];
}
groupedData[sameMonthKey].push(tempGroupedDataSameMonth[key]);
}
}
} else {
// Process the first month
const firstMonthStart = new Date(start.getFullYear(), start.getMonth(), start.getDate());
const firstMonthEnd = new Date(start.getFullYear(), start.getMonth() + 1, 0); // Last day of the month
const firstMonthKey = `${this.formatDate(firstMonthStart)} - ${this.formatDate(firstMonthEnd)}`;
const tempGroupedDataFirstMonth = {};
tickets.forEach(ticket => {
const ticketDate = new Date(ticket.date);
if (ticketDate >= monthStart && ticketDate <= monthEnd) {
// Constructs uniqueKey based on selected fields
const uniqueKeyParts = [];
uniqueKeyParts.push(ticket.upperSpecies);
if (ticketDate >= firstMonthStart && ticketDate <= firstMonthEnd) {
const uniqueKeyParts = [ticket.upperSpecies];
if (this.selectedSpecies.length > 0) {
uniqueKeyParts.push(ticket.species);
......@@ -469,17 +508,17 @@ export default {
uniqueKeyParts.push(ticket.region);
}
if (this.selectedInjuries.length > 0) {
uniqueKeyParts.push(ticket.injuries.join(',')); // Joins injuries as a string
uniqueKeyParts.push(ticket.injuries.join(','));
}
if (this.selectedResolutions.length > 0) {
uniqueKeyParts.push(ticket.resolution);
}
const uniqueKey = uniqueKeyParts.join('|'); // Creates unique key
const uniqueKey = uniqueKeyParts.join('|');
if (!tempGroupedData[uniqueKey]) {
tempGroupedData[uniqueKey] = {
date: this.formatDate(monthStart, 'month'),
if (!tempGroupedDataFirstMonth[uniqueKey]) {
tempGroupedDataFirstMonth[uniqueKey] = {
date: firstMonthKey,
upperSpecies: ticket.upperSpecies,
species: this.selectedSpecies.length > 0 ? ticket.species : null,
region: this.selectedRegions.length > 0 ? ticket.region : null,
......@@ -488,36 +527,138 @@ export default {
count: 0
};
}
tempGroupedData[uniqueKey].count += 1;
tempGroupedDataFirstMonth[uniqueKey].count += 1;
}
});
for (const key in tempGroupedData) {
if (tempGroupedData[key].count > 0) {
if (!groupedData[dateRangeKey]) {
groupedData[dateRangeKey] = [];
for (const key in tempGroupedDataFirstMonth) {
if (tempGroupedDataFirstMonth[key].count > 0) {
if (!groupedData[firstMonthKey]) {
groupedData[firstMonthKey] = [];
}
groupedData[dateRangeKey].push(tempGroupedData[key]);
groupedData[firstMonthKey].push(tempGroupedDataFirstMonth[key]);
}
}
// Move to the next month
let currentDate = new Date(firstMonthEnd);
currentDate.setMonth(currentDate.getMonth() + 1);
// Process full months in between
while (currentDate < end) {
const monthStart = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1);
const monthEnd = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0); // Last day of the month
const monthKey = `${this.formatDate(monthStart)} - ${this.formatDate(monthEnd)}`;
const tempGroupedDataFullMonth = {};
tickets.forEach(ticket => {
const ticketDate = new Date(ticket.date);
if (ticketDate >= monthStart && ticketDate <= monthEnd) {
const uniqueKeyParts = [ticket.upperSpecies];
if (this.selectedSpecies.length > 0) {
uniqueKeyParts.push(ticket.species);
}
if (this.selectedRegions.length > 0) {
uniqueKeyParts.push(ticket.region);
}
if (this.selectedInjuries.length > 0) {
uniqueKeyParts.push(ticket.injuries.join(','));
}
if (this.selectedResolutions.length > 0) {
uniqueKeyParts.push(ticket.resolution);
}
const uniqueKey = uniqueKeyParts.join('|');
if (!tempGroupedDataFullMonth[uniqueKey]) {
tempGroupedDataFullMonth[uniqueKey] = {
date: monthKey,
upperSpecies: ticket.upperSpecies,
species: this.selectedSpecies.length > 0 ? ticket.species : null,
region: this.selectedRegions.length > 0 ? ticket.region : null,
injuries: this.selectedInjuries.length > 0 ? ticket.injuries : [],
resolution: this.selectedResolutions.length > 0 ? ticket.resolution : null,
count: 0
};
}
tempGroupedDataFullMonth[uniqueKey].count += 1;
}
});
for (const key in tempGroupedDataFullMonth) {
if (tempGroupedDataFullMonth[key].count > 0) {
if (!groupedData[monthKey]) {
groupedData[monthKey] = [];
}
groupedData[monthKey].push(tempGroupedDataFullMonth[key]);
}
}
// Move to the next month
currentDate.setMonth(currentDate.getMonth() + 1);
}
// Process the last month
const lastMonthStart = new Date(end.getFullYear(), end.getMonth(), 1);
const lastMonthEnd = new Date(end.getFullYear(), end.getMonth(), end.getDate(), 23, 59, 59);
const lastMonthKey = `${this.formatDate(lastMonthStart)} - ${this.formatDate(lastMonthEnd)}`;
const tempGroupedDataLastMonth = {};
tickets.forEach(ticket => {
const ticketDate = new Date(ticket.date);
if (ticketDate >= lastMonthStart && ticketDate <= lastMonthEnd) {
const uniqueKeyParts = [ticket.upperSpecies];
if (this.selectedSpecies.length > 0) {
uniqueKeyParts.push(ticket.species);
}
if (this.selectedRegions.length > 0) {
uniqueKeyParts.push(ticket.region);
}
if (this.selectedInjuries.length > 0) {
uniqueKeyParts.push(ticket.injuries.join(','));
}
if (this.selectedResolutions.length > 0) {
uniqueKeyParts.push(ticket.resolution);
}
const uniqueKey = uniqueKeyParts.join('|');
if (!tempGroupedDataLastMonth[uniqueKey]) {
tempGroupedDataLastMonth[uniqueKey] = {
date: lastMonthKey,
upperSpecies: ticket.upperSpecies,
species: this.selectedSpecies.length > 0 ? ticket.species : null,
region: this.selectedRegions.length > 0 ? ticket.region : null,
injuries: this.selectedInjuries.length > 0 ? ticket.injuries : [],
resolution: this.selectedResolutions.length > 0 ? ticket.resolution : null,
count: 0
};
}
tempGroupedDataLastMonth[uniqueKey].count += 1;
}
});
for (const key in tempGroupedDataLastMonth) {
if (tempGroupedDataLastMonth[key].count > 0) if (!groupedData[lastMonthKey]) {
groupedData[lastMonthKey] = [];
}
groupedData[lastMonthKey].push(tempGroupedDataLastMonth[key]);
}
}
}
// Yearly grouping
else if (frequency === 'yearly') {
let currentDate = new Date(start);
while (currentDate <= end) {
const yearStart = new Date(currentDate.getFullYear(), 0, 1);
const yearEnd = new Date(currentDate.getFullYear(), 11, 31, 23, 59, 59, 999);
const dateRangeKey = `${this.formatDate(yearStart)} - ${this.formatDate(yearEnd)}`; // e.g., "1.1.2023 - 31.12.2023"
const tempGroupedData = {};
// Check if start and end are in the same year
if (start.getFullYear() === end.getFullYear()) {
const sameYearKey = `${this.formatDate(start, 'year')} - ${this.formatDate(end)}`;
const tempGroupedDataSameYear = {};
tickets.forEach(ticket => {
const ticketDate = new Date(ticket.date);
if (ticketDate >= yearStart && ticketDate <= yearEnd) {
if (ticketDate >= start && ticketDate <= end) {
// Constructs uniqueKey based on selected fields
const uniqueKeyParts = [];
uniqueKeyParts.push(ticket.upperSpecies);
......@@ -537,9 +678,9 @@ export default {
const uniqueKey = uniqueKeyParts.join('|'); // Creates unique key
if (!tempGroupedData[uniqueKey]) {
tempGroupedData[uniqueKey] = {
date: this.formatDate(yearStart, 'year'),
if (!tempGroupedDataSameYear[uniqueKey]) {
tempGroupedDataSameYear[uniqueKey] = {
date: sameYearKey,
upperSpecies: ticket.upperSpecies,
species: this.selectedSpecies.length > 0 ? ticket.species : null,
region: this.selectedRegions.length > 0 ? ticket.region : null,
......@@ -548,20 +689,81 @@ export default {
count: 0
};
}
tempGroupedData[uniqueKey].count += 1;
tempGroupedDataSameYear[uniqueKey].count += 1;
}
});
for (const key in tempGroupedData) {
if (tempGroupedData[key].count > 0) {
if (!groupedData[dateRangeKey]) {
groupedData[dateRangeKey] = [];
for (const key in tempGroupedDataSameYear) {
if (tempGroupedDataSameYear[key].count > 0) {
if (!groupedData[sameYearKey]) {
groupedData[sameYearKey] = [];
}
groupedData[dateRangeKey].push(tempGroupedData[key]);
groupedData[sameYearKey].push(tempGroupedDataSameYear[key]);
}
}
} else {
// Process each year in the range
let currentDate = new Date(start);
currentDate.setFullYear(currentDate.getFullYear());
while (currentDate <= end) {
const yearStart = new Date(currentDate.getFullYear(), 0, 1);
const yearEnd = new Date(currentDate.getFullYear(), 11, 31, 23, 59, 59, 999);
const dateRangeKey = `${this.formatDate(yearStart)} - ${this.formatDate(yearEnd)}`; // e.g., "1.1.2023 - 31.12.2023"
const tempGroupedData = {};
tickets.forEach(ticket => {
const ticketDate = new Date(ticket.date);
if (ticketDate >= yearStart && ticketDate <= yearEnd) {
// Constructs uniqueKey based on selected fields
const uniqueKeyParts = [];
uniqueKeyParts.push(ticket.upperSpecies);
if (this.selectedSpecies.length > 0) {
uniqueKeyParts.push(ticket.species);
}
if (this.selectedRegions.length > 0) {
uniqueKeyParts.push(ticket.region);
}
if (this.selectedInjuries.length > 0) {
uniqueKeyParts.push(ticket.injuries.join(',')); // Joins injuries as a string
}
if (this.selectedResolutions.length > 0) {
uniqueKeyParts.push(ticket.resolution);
}
const uniqueKey = uniqueKeyParts.join('|'); // Creates unique key
if (!tempGroupedData[uniqueKey]) {
tempGroupedData[uniqueKey] = {
date: this.formatDate(yearStart, 'year'),
upperSpecies: ticket.upperSpecies,
species: this.selectedSpecies.length > 0 ? ticket.species : null,
region: this.selectedRegions.length > 0 ? ticket.region : null,
injuries: this.selectedInjuries.length > 0 ? ticket.injuries : [],
resolution: this.selectedResolutions.length > 0 ? ticket.resolution : null,
count: 0
};
}
tempGroupedData[uniqueKey].count += 1;
}
});
for (const key in tempGroupedData) {
if (tempGroupedData[key].count > 0) {
if (!groupedData[dateRangeKey]) {
groupedData[dateRangeKey] = [];
}
groupedData[dateRangeKey].push(tempGroupedData[key]);
}
}
currentDate.setFullYear(currentDate.getFullYear() + 1);
currentDate.setFullYear(currentDate.getFullYear() + 1);
}
const lastYearKey = `${this.formatDate(new Date(end.getFullYear(), 0, 1))} - ${this.formatDate(end)}`;
if (!groupedData[lastYearKey]) {
groupedData[lastYearKey] = [];
}
}
}
return groupedData;
......
......@@ -34,7 +34,7 @@ public class StatisticsService {
return ticket.getStatus().getName().equals("Lõpetatud");
}
private boolean isTicketWithinDateRange(Ticket ticket, Timestamp startDate, Timestamp endDate) {
return ticket.getCloseDate().after(startDate) && ticket.getCloseDate().before(endDate);
return !ticket.getOpenDate().before(startDate) && !ticket.getOpenDate().after(endDate);
}
private boolean doesTicketMatchFilters(Ticket ticket, List<String> upperSpecies, List<String> species, List<String> region, List<String> resolution, List<String> injuries) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment