PHP code example of alphonse243 / biocycle-predictor

1. Go to this page and download the library: Download alphonse243/biocycle-predictor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alphonse243 / biocycle-predictor example snippets



Alphonse243\BioCycle\Calculator\CycleCalculator;
use Alphonse243\BioCycle\Collection\CycleHistory;
use Alphonse243\BioCycle\Entity\CycleEntity;
use Carbon\Carbon;

// Créer un historique
$history = new CycleHistory();

$history->addCycle(new CycleEntity(
    Carbon::createFromFormat('Y-m-d', '2024-10-01'),
    Carbon::createFromFormat('Y-m-d', '2024-10-29')
));

$history->addCycle(new CycleEntity(
    Carbon::createFromFormat('Y-m-d', '2024-10-29'),
    Carbon::createFromFormat('Y-m-d', '2024-11-26')
));

// Créer le calculateur
$calculator = new CycleCalculator(
    $history,
    Carbon::createFromFormat('Y-m-d', '2024-11-26')
);

// Obtenir les prédictions
$formatted = $calculator->getFormattedPrediction('fr');

echo "Prochaines règles : " . $formatted['prochaines_règles'];
echo "Fenêtre de fertilité : " . $formatted['fenetre_fertilité'];

$cycle = new CycleEntity(
    Carbon::createFromFormat('Y-m-d', '2024-10-01'),
    Carbon::createFromFormat('Y-m-d', '2024-10-29')
);

echo $cycle->getDureeRecue(); // 28 jours

$history = new CycleHistory();
$history->addCycle($cycle1);
$history->addCycle($cycle2);

$moyenne = $history->getAverageDuration(); // float
echo $history->count(); // int

$calculator = new CycleCalculator($history, $lastPeriodDate);

// Prédictions brutes
$prediction = $calculator->predictNextCycle();

// Prédictions formatées
$formatted = $calculator->getFormattedPrediction('fr');

$forcedDate = Carbon::now()->addDays(5);
$calculator->forceOvulationDate($forcedDate);
$prediction = $calculator->predictNextCycle();

use Alphonse243\BioCycle\Exception\CycleIrregulierException;

try {
    $prediction = $calculator->predictNextCycle();
} catch (CycleIrregulierException $e) {
    echo "⚠️ Cycle irrégulier détecté : " . $e->getMessage();
}