在工作中,我们有一个讨厌的公共小便池.没有冲洗手柄.相反,它有一个运动传感器,当你站在它前面时有时会触发,有时则不会.当它触发时,一个水箱充满,当充满时用于冲洗小便池.
在我之前的许多旅程中,我已经考虑了用于确定何时打开的框用于什么算法以及什么是最佳算法,在节约用水方面同时仍保持相对舒适的小便体验.
一旦人们有机会分享他们的想法,我会分享我的答案.
Ger*_*ald 17
OnUserEnter()
{
if (UsersDetected == 0)
{
FirstDetectionTime = Now();
}
UsersDetected++;
CurrentlyInUse = true;
}
OnUserExit()
{
CurrentlyInUse = false;
if (UsersDetected >= MaxUsersBetweenFlushes ||
Now() - FirstDetectionTime > StinkInterval)
{
Flush();
}
}
OnTimer()
{
if (!CurrentlyInUse &&
UsersDetected > 0 &&
Now() - FirstDetectionTime > StinkInterval)
{
Flush();
}
}
Flush()
{
FlushTheUrinal();
UsersDetected = 0;
}
Run Code Online (Sandbox Code Playgroud)