-
Notifications
You must be signed in to change notification settings - Fork 261
New night shift goodie score calculation #1590
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
base: main
Are you sure you want to change the base?
Conversation
| JOIN shift_entries se ON se.user_id = u.id | ||
| JOIN shifts s ON se.shift_id = s.id | ||
| WHERE u.id = user_id | ||
| AND s.end < CURRENT_TIMESTAMP; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start and end timestamps are calculated by the engelsystem and then compared to a timestamp calculated by the database. This might cause issues if the database clock and engelsystem clock are not in sync.
Only a thought that came to mind, not sure how much of a problem this is in practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right this should be changed.
It was Carbon::now() - This parameter should be added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
| LEAVE read_loop; | ||
| END IF; | ||
| IF freeloaded THEN | ||
| SET SHIFT_SUM = TIMESTAMPDIFF(SECOND, shift_start, shift_end) * -2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previously the negated night_shift_multiplier was used freeloading. Not sure which is better, just wanted to point it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK the multiplier was hard coded so no difference at all ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@obit is right. I'll change this.
| END WHILE; | ||
| SET SHIFT_SUM = TIMESTAMPDIFF(SECOND, shift_start, shift_end) | ||
| + (NIGHT_SHIFT_SECONDS * night_shift_multiplier); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't the night_shift part be added once too many because it is also part of the TIMESTAMPDIFF?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm, I see you reduce the multiplier when calling the function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that I think of it, I think the multipler should be reduced in the function, so it is self contained and you don't need to remeber to reduce it when calling the function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed about it - IMHO the multiplier is now used correctly - Before that change the whole shift was multiplied.
Now only the night shift part is the amount of time in question.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what @obit means is to input the real multiplier into the function and then reduce it by one in the function. When reintroducing the night shift multiplier as freeloading I will probably change that and agree with @obit even though I was the person that was against this in the first place. 😇
resources/lang/de_DE/default.po
Outdated
| msgid "Night shifts between %d and %d am are multiplied by %d for the goodie score." | ||
| msgstr "Nachtschichten zwischen %d und %d Uhr werden für den Goodie Score mit %3$d multipliziert." | ||
| msgid "night_shift.goodie_score.hint" | ||
| msgstr "Nachtschichtstunden zwischen %d und %d Uhr werden für den Goodie Score mit %3$d multipliziert. Stunden außerhalb der Nachtzeit zählen normal." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be nitpicking, but this chage was introduced because shift with as little as 15min during the nightshift would be multiplied. I think specifing hours in the hint might cause confusion in those cases.
| msgstr "Nachtschichtstunden zwischen %d und %d Uhr werden für den Goodie Score mit %3$d multipliziert. Stunden außerhalb der Nachtzeit zählen normal." | |
| msgstr "Die Zeit in der Nacht zwischen %d und %d Uhr wird für den Goodie Score mit %3$d multipliziert. Die Zeit außerhalb der Nacht zählt normal." |
resources/lang/en_US/default.po
Outdated
| msgstr "Edit goodie" | ||
|
|
||
| msgid "night_shift.goodie_score.hint" | ||
| msgstr "Night shift hours between %d and %d am are multiplied by %d for the goodie score. Hours outside of the night time are counted regularly." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| msgstr "Night shift hours between %d and %d am are multiplied by %d for the goodie score. Hours outside of the night time are counted regularly." | |
| msgstr "Night shift time between %d and %d am is multiplied by %d for the goodie score. Time outside of the night is counted regularly." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "Time worked between ... and ..." instead of "Night shift hours/time"?
Also, I would leave out the "time outside of the night is counted regularly" - that's the default after all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that wording.
|
I played with this a bit and tried a few exotic shift times and didn't manage to break the calculation. However, it would be nice to see the hours that a shift is counted with somewhere (maybe in the tooltip and/or in the table in the user profile) to make the system a bit more intuitive and the calculation easier to understand. |
e2df954 to
af4f7af
Compare
MyIgel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A preliminary review:
The tests are not running and the linter says nope:
------ -----------------------------------------------------------------------------------
Line tests/Unit/Helpers/GoodieTest.php
------ -----------------------------------------------------------------------------------
26 Call to an undefined static method Engelsystem\Helpers\Goodie::shiftScoreQuery().
🪪 staticMethod.notFound
------ -----------------------------------------------------------------------------------
In sum i don't really like SQL functions as the can only be changed by migrations and thus as a whole but if you really want to do it this way i can't stop you.
| */ | ||
| public function up(): void | ||
| { | ||
| $this->db->statement( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a check to not be run during tests, see other migrations for reference:
[...]
.......WF...................EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 61 / 1122 ( 5%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 122 / 1122 ( 10%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE......E 183 / 1122 ( 16%)
EEEEEEEEEEE.EEEEEEEE....................EEEEEEEEEEE...EEEEEEE 244 / 1122 ( 21%)
EEEEEEEEEEEEEEEEEE......EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 305 / 1122 ( 27%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 366 / 1122 ( 32%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE.................. 427 / 1122 ( 38%)
...........EEEEEEEEEEEEEEEEEEEEEE............................ 488 / 1122 ( 43%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE....EEEEEEEEEEEEE... 549 / 1122 ( 48%)
................................................EE........... 610 / 1122 ( 54%)
.......................EEEE.E...........EEEE................. 671 / 1122 ( 59%)
............................................................. 732 / 1122 ( 65%)
....................................................EEEE..... 793 / 1122 ( 70%)
............................................................. 854 / 1122 ( 76%)
EEEEEEEEEEEEEEEEEE.E......................................... 915 / 1122 ( 81%)
...................................E........EEEEEEEEEEEEEEEEE 976 / 1122 ( 86%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 1037 / 1122 ( 92%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE..........E.......E....... 1098 / 1122 ( 97%)
........................ 1122 / 1122 (100%).
Time: 03:22.754, Memory: 134.50 MB
There were 571 errors:
1) Engelsystem\Test\Unit\Controllers\Admin\ConfigControllerTest::testIndex
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 near "DEFINER": syntax error (Connection: default, SQL: CREATE DEFINER=`engelsystem`@`%` FUNCTION `goodie_score` (
[...]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now there are less so its better debuggable ;)
| DECLARE NIGHT_END TIMESTAMP; | ||
| DECLARE NIGHT_SHIFT_SECONDS int; | ||
| DECLARE SHIFT_SUM int; | ||
| DECLARE GOODY_SUM int; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The consistent wording would be goodie
| DECLARE GOODY_SUM int; | |
| DECLARE GOODIE_SUM int; |
(same for following)
| msgid "Night shifts between %d and %d am are multiplied by %d for the goodie score." | ||
| msgstr "Nachtschichten zwischen %d und %d Uhr werden für den Goodie Score mit %3$d multipliziert." | ||
| msgid "night_shift.goodie_score.hint" | ||
| msgstr "Gearbeitete Zeit zwischen %d und %d Uhr werden für den Goodie Score mit %3$d multipliziert." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| msgstr "Gearbeitete Zeit zwischen %d und %d Uhr werden für den Goodie Score mit %3$d multipliziert." | |
| msgstr "Gearbeitete Zeit zwischen %d und %d Uhr wird für den Goodie Score mit %3$d multipliziert." |
| msgstr "Edit goodie" | ||
|
|
||
| msgid "night_shift.goodie_score.hint" | ||
| msgstr "Time worked between %d and %d am are multiplied by %d for the goodie score." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| msgstr "Time worked between %d and %d am are multiplied by %d for the goodie score." | |
| msgstr "Time worked between %d and %d am is multiplied by %d for the goodie score." |
| * | ||
| * Shifts and shift entries must be available via join | ||
| */ | ||
| public static function shiftScoreQuery(): Expression |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That function is still used in multiple places (admin_active, it is referenced in isNightShift),, please replace those too or re-add it n a compatible way
| $connection = $db->getConnection(); | ||
|
|
||
| if (!$connection->getQueryGrammar() instanceof MySqlGrammar) { | ||
| return $connection->raw('0'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be a still required distinction imho
| `night_shift_start` INT, | ||
| `night_shift_end` INT, | ||
| `night_shift_multiplier` INT, | ||
| `now` TIMESTAMP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `now` TIMESTAMP | |
| `until` TIMESTAMP |
or something similar, now is imho not the right wording or could be directly replaced with NOW()
Night shifts hours get multiplied partially. Only hours inside the night time get night shift multiplier.