Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core : clean duplicate value in history if cmd is in no repeat #1935

Closed
zoic21 opened this issue Jan 12, 2022 · 1 comment
Closed

Core : clean duplicate value in history if cmd is in no repeat #1935

zoic21 opened this issue Jan 12, 2022 · 1 comment
Assignees

Comments

@zoic21
Copy link
Contributor

zoic21 commented Jan 12, 2022

No description provided.

@zoic21 zoic21 self-assigned this Jan 12, 2022
@BadWolf42
Copy link
Contributor

Hi,
This may help: https://community.jeedom.com/t/fonction-archive-de-la-class-history/75979

I personally use this code in a scenario:

$totI = 0;
$totKey = 0;
$totCmd = 0;
$histoCmds = cmd::allHistoryCmd();
foreach ($histoCmds as $histoCmd) {
  if ($histoCmd->getConfiguration('historizeMode') == 'none' && 
      ($histoCmd->getConfiguration('repeatEventManagement') == 'never'
       || $histoCmd->getConfiguration('repeatEventManagement') == 'auto'))  {
    $totCmd++;
    $scenario->setLog($histoCmd->getId() . ' ---> ' . $histoCmd->getHumanName());
    $historys = history::all($histoCmd->getId());
    $i = 0;
    $key = 0;
    foreach ($historys as $key => $history) {
      if ($key == 0)
        continue;
      if ($history->getValue() === $historys[$key-1]->getValue()
          && substr($history->getDatetime(), 0, 10) === substr($historys[$key-1]->getDatetime(), 0, 10)) {
        //$history->remove(); // *** Uncomment me to DELETE FOR REAL ***
        $i++;
      }
    }
    $scenario->setLog("Nb d'enregistrements effacés $i, sur $key précédement");
    $totI = $totI + $i;
    $totKey = $totKey + $key;
  }
}
$scenario->setLog("-------------------------------------------------------------------");
$scenario->setLog("Nb d'enregistrements effacés $totI, sur $totKey précédement");
$scenario->setLog("Nb de commandes historisées : $totCmd");

Bad

@zoic21 zoic21 closed this as completed Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants