Skip to content

Commit 6c00e22

Browse files
Adiciona suporte para datas de preprint em FulltextDates (#1052)
* feat(dates): add preprint_date support to FulltextDates - Add cached_property preprint_date to extract preprint date from history - Include preprint dates in get_peer_reviewed_stats method - Calculate days_from_preprint_to_received and days_from_preprint_to_published - Add estimation flags for preprint-related intervals - Support serialization of preprint_date when serialize_dates=True * test(dates): add comprehensive tests for preprint_date functionality - Add TestPreprintDate class with tests for: - Preprint date extraction when present - Behavior when preprint date is absent - Partial preprint dates (year and month only) - Multiple preprint dates (first one is selected) - Add TestGetPeerReviewedStatsWithPreprint class with tests for: - Complete peer review cycle including preprint - Preprint with estimated dates - Only preprint and published dates scenario - Custom default values for partial preprint dates - Date serialization with preprint - Negative intervals for out-of-order dates - Fix leap year calculations (2024 has 366 days) - Correct day count from Dec 15, 2023 to Mar 1, 2024 (77 days)
1 parent 4c21fa4 commit 6c00e22

2 files changed

Lines changed: 405 additions & 0 deletions

File tree

packtools/sps/models/dates.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,19 @@ def date_types_ordered_by_date(self):
415415
# obtem uma lista com os nomes dos eventos ordenados
416416
return [event[0] for event in self.ordered_events]
417417

418+
@cached_property
419+
def preprint_date(self):
420+
"""Get preprint date as a Date instance.
421+
422+
Returns:
423+
Date: Date instance for the preprint date, or None if not available
424+
"""
425+
try:
426+
node = self.front.xpath(".//history//date[@date-type='preprint']")[0]
427+
return Date(node)
428+
except (IndexError, AttributeError):
429+
return None
430+
418431
@cached_property
419432
def received_date(self):
420433
"""Get received date as a Date instance.
@@ -444,6 +457,11 @@ def accepted_date(self):
444457
def get_peer_reviewed_stats(
445458
self, default_month=6, default_day=15, serialize_dates=False
446459
):
460+
preprint = {}
461+
if self.preprint_date:
462+
preprint = self.preprint_date.get_date(
463+
default_month=default_month, default_day=default_day
464+
)
447465
received = {}
448466
if self.received_date:
449467
received = self.received_date.get_date(
@@ -460,11 +478,17 @@ def get_peer_reviewed_stats(
460478
default_month=default_month, default_day=default_day
461479
)
462480

481+
preprint_date = preprint.get("date")
463482
received_date = received.get("date")
464483
accepted_date = accepted.get("date")
465484
published_date = published.get("date")
466485

467486
stats = {}
487+
stats["preprint_date"] = (
488+
preprint_date.isoformat()
489+
if serialize_dates and preprint_date
490+
else preprint_date
491+
)
468492
stats["received_date"] = (
469493
received_date.isoformat()
470494
if serialize_dates and received_date
@@ -480,6 +504,10 @@ def get_peer_reviewed_stats(
480504
if serialize_dates and published_date
481505
else published_date
482506
)
507+
stats["days_from_preprint_to_received"] = get_days(preprint_date, received_date)
508+
stats["estimated_days_from_preprint_to_received"] = preprint.get(
509+
"estimated"
510+
) or received.get("estimated")
483511
stats["days_from_received_to_accepted"] = get_days(received_date, accepted_date)
484512
stats["estimated_days_from_received_to_accepted"] = received.get(
485513
"estimated"
@@ -490,6 +518,13 @@ def get_peer_reviewed_stats(
490518
stats["estimated_days_from_accepted_to_published"] = accepted.get(
491519
"estimated"
492520
) or published.get("estimated")
521+
522+
stats["days_from_preprint_to_published"] = get_days(
523+
preprint_date, published_date
524+
)
525+
stats["estimated_days_from_preprint_to_published"] = preprint.get(
526+
"estimated"
527+
) or published.get("estimated")
493528
stats["days_from_received_to_published"] = get_days(
494529
received_date, published_date
495530
)

0 commit comments

Comments
 (0)