fix stats calculation - include repeating avs.
This commit is contained in:
@ -22,11 +22,11 @@ function ContactsPage({ allPublishers }) {
|
|||||||
const [pubWithAssignmentsCount, setPubWithAssignmentsCount] = useState(0);
|
const [pubWithAssignmentsCount, setPubWithAssignmentsCount] = useState(0);
|
||||||
const [filteredPublishers, setFilteredPublishers] = useState(allPublishers);
|
const [filteredPublishers, setFilteredPublishers] = useState(allPublishers);
|
||||||
|
|
||||||
const [sortField, setSortField] = useState('firstName');
|
const [sortField, setSortField] = useState('name');
|
||||||
const [sortOrder, setSortOrder] = useState('asc');
|
const [sortOrder, setSortOrder] = useState('asc');
|
||||||
|
|
||||||
const months = common.getMonthNames();
|
const months = common.getMonthNames();
|
||||||
const subsetMonths = Array.from({ length: 7 }, (_, i) => {
|
const subsetMonths = Array.from({ length: 9 }, (_, i) => {
|
||||||
const monthIndex = (currentMonth - 3 + i + 12) % 12; // Adjust for year wrap-around
|
const monthIndex = (currentMonth - 3 + i + 12) % 12; // Adjust for year wrap-around
|
||||||
return {
|
return {
|
||||||
name: months[monthIndex],
|
name: months[monthIndex],
|
||||||
@ -104,7 +104,7 @@ function ContactsPage({ allPublishers }) {
|
|||||||
<h1 className="text-xl font-semibold mb-4">Статистика </h1>
|
<h1 className="text-xl font-semibold mb-4">Статистика </h1>
|
||||||
<h5 className="text-lg font-semibold mb-4">{pubWithAssignmentsCount} участника с предпочитания за месеца (от {filteredPublishers.length} )</h5>
|
<h5 className="text-lg font-semibold mb-4">{pubWithAssignmentsCount} участника с предпочитания за месеца (от {filteredPublishers.length} )</h5>
|
||||||
<div className="mb-4 flex justify-between items-center">
|
<div className="mb-4 flex justify-between items-center">
|
||||||
<input
|
<input name="filterText"
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Търси по име, имейл или телефон..."
|
placeholder="Търси по име, имейл или телефон..."
|
||||||
value={searchQuery}
|
value={searchQuery}
|
||||||
@ -112,7 +112,7 @@ function ContactsPage({ allPublishers }) {
|
|||||||
className="border border-gray-300 rounded-md px-2 py-2 text-base md:text-sm flex-grow mr-2"
|
className="border border-gray-300 rounded-md px-2 py-2 text-base md:text-sm flex-grow mr-2"
|
||||||
/>
|
/>
|
||||||
{/* Month dropdown */}
|
{/* Month dropdown */}
|
||||||
<select
|
<select name="filterMonth"
|
||||||
className="border border-gray-300 rounded-md px-2 py-2 text-base md:text-sm"
|
className="border border-gray-300 rounded-md px-2 py-2 text-base md:text-sm"
|
||||||
value={selectedMonth}
|
value={selectedMonth}
|
||||||
onChange={(e) => setSelectedMonth(e.target.value)}
|
onChange={(e) => setSelectedMonth(e.target.value)}
|
||||||
@ -123,7 +123,7 @@ function ContactsPage({ allPublishers }) {
|
|||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
{/* Publisher type dropdown */}
|
{/* Publisher type dropdown */}
|
||||||
<select
|
<select name="filterType"
|
||||||
className="border border-gray-300 rounded-md px-2 py-2 text-base md:text-sm"
|
className="border border-gray-300 rounded-md px-2 py-2 text-base md:text-sm"
|
||||||
value={publisherType}
|
value={publisherType}
|
||||||
onChange={(e) => setPublisherType(e.target.value)}
|
onChange={(e) => setPublisherType(e.target.value)}
|
||||||
@ -138,8 +138,8 @@ function ContactsPage({ allPublishers }) {
|
|||||||
<table className="w-full text-left border-collapse">
|
<table className="w-full text-left border-collapse">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th className="border-b font-medium p-4 pl-8 pt-0 pb-3 cursor-pointer" onClick={() => handleSort('firstName')}>
|
<th className="border-b font-medium p-4 pl-8 pt-0 pb-3 cursor-pointer" onClick={() => handleSort('name')}>
|
||||||
Име{renderSortArrow('firstName')}
|
Име{renderSortArrow('name')}
|
||||||
</th>
|
</th>
|
||||||
<th className="border-b font-medium p-4 pt-0 pb-3 cursor-pointer" onClick={() => handleSort('currentMonthAvailabilityDaysCount')}>
|
<th className="border-b font-medium p-4 pt-0 pb-3 cursor-pointer" onClick={() => handleSort('currentMonthAvailabilityDaysCount')}>
|
||||||
Възможности{renderSortArrow('currentMonthAvailabilityDaysCount')}
|
Възможности{renderSortArrow('currentMonthAvailabilityDaysCount')}
|
||||||
@ -217,6 +217,10 @@ export default ContactsPage;
|
|||||||
|
|
||||||
export const getServerSideProps = async (context) => {
|
export const getServerSideProps = async (context) => {
|
||||||
const allPublishers = await data.getAllPublishersWithStatistics(new Date());
|
const allPublishers = await data.getAllPublishersWithStatistics(new Date());
|
||||||
|
//merge first and last name
|
||||||
|
allPublishers.forEach(publisher => {
|
||||||
|
publisher.name = `${publisher.firstName} ${publisher.lastName}`;
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
allPublishers
|
allPublishers
|
||||||
|
@ -420,7 +420,8 @@ async function filterPublishersNew(selectFields, filterDate, isExactTime = false
|
|||||||
if (isWithStats) {
|
if (isWithStats) {
|
||||||
pub.currentMonthAvailability = pub.availabilities?.filter(avail => {
|
pub.currentMonthAvailability = pub.availabilities?.filter(avail => {
|
||||||
// return avail.dayOfMonth != null && avail.startTime >= currentMonthStart && avail.startTime <= monthInfo.lastSunday;
|
// return avail.dayOfMonth != null && avail.startTime >= currentMonthStart && avail.startTime <= monthInfo.lastSunday;
|
||||||
return avail.startTime >= monthInfo.firstMonday && (noEndDateFilter || avail.startTime <= monthInfo.lastSunday);
|
return (avail.startTime >= monthInfo.firstMonday && (noEndDateFilter || avail.startTime <= monthInfo.lastSunday))
|
||||||
|
|| (avail.dayOfMonth == null); // include repeating availabilities
|
||||||
})
|
})
|
||||||
pub.currentMonthAvailabilityDaysCount = pub.currentMonthAvailability.length;
|
pub.currentMonthAvailabilityDaysCount = pub.currentMonthAvailability.length;
|
||||||
// pub.currentMonthAvailabilityDaysCount += pub.availabilities.filter(avail => {
|
// pub.currentMonthAvailabilityDaysCount += pub.availabilities.filter(avail => {
|
||||||
@ -557,6 +558,14 @@ async function getAllPublishersWithStatistics(filterDate, noEndDateFilter = fals
|
|||||||
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
orderBy: [
|
||||||
|
{
|
||||||
|
firstName: 'asc', // or 'desc' if you want descending order
|
||||||
|
},
|
||||||
|
{
|
||||||
|
lastName: 'asc', // or 'desc' if you want descending order
|
||||||
|
}
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -577,6 +586,11 @@ async function getAllPublishersWithStatistics(filterDate, noEndDateFilter = fals
|
|||||||
// common.convertDatesToISOStrings(publisher.availabilities); //ToDo fix the function to work with this sctucture and use it
|
// common.convertDatesToISOStrings(publisher.availabilities); //ToDo fix the function to work with this sctucture and use it
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//debug
|
||||||
|
const pubsWithAvailabilities = allPublishers.filter(publisher => publisher.availabilities.length > 0);
|
||||||
|
const pubsWithAvailabilities2 = publishers.filter(publisher => publisher.currentMonthAvailabilityHoursCount > 0);
|
||||||
|
console.log(`publishers: ${allPublishers.length}, publishers with availabilities: ${pubsWithAvailabilities.length}, publishers with availabilities2: ${pubsWithAvailabilities2.length}`);
|
||||||
|
|
||||||
|
|
||||||
//merge allPublishers with publishers
|
//merge allPublishers with publishers
|
||||||
allPublishers = allPublishers.map(pub => {
|
allPublishers = allPublishers.map(pub => {
|
||||||
|
Reference in New Issue
Block a user