2019 enhancement backend endpoint for hash heatmap#2068
Draft
jessevz wants to merge 2 commits into
Draft
Conversation
Contributor
Author
|
hashtopolis/python-hashtopolis#4 Should be merged to pass the tests |
There was a problem hiding this comment.
Pull request overview
Adds a new APIv2 helper endpoint intended to move “cracks per day” aggregation (used for hash heatmaps) from the frontend to the backend (closes #2019).
Changes:
- Added
GET /api/v2/helper/getCracksPerDaywhich returns a date→count mapping of cracks for the current year. - Registered the new helper endpoint in the APIv2 router.
- Added CI tests validating the new helper’s response shape and basic behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/inc/apiv2/helper/GetCracksPerDayHelperAPI.php |
Implements the new backend aggregation endpoint for cracked hashes per day. |
src/api/v2/index.php |
Registers the new helper endpoint so it becomes reachable via APIv2. |
ci/apiv2/test_cracks_per_day.py |
Adds CI coverage for the new helper endpoint. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+44
to
+55
| public function handleGet(Request $request, Response $response): Response { | ||
| $this->preCommon($request); | ||
|
|
||
| $yearStart = mktime(0, 0, 0, 1, 1, (int) date('Y')); | ||
| $now = time(); | ||
|
|
||
| $filters = [ | ||
| new QueryFilter(Hash::IS_CRACKED, 1, "="), | ||
| new QueryFilter(Hash::TIME_CRACKED, $yearStart, ">="), | ||
| new QueryFilter(Hash::TIME_CRACKED, $now, "<="), | ||
| ]; | ||
|
|
| } | ||
|
|
||
| public function getRequiredPermissions(string $method): array { | ||
| return [Hashlist::PERM_READ, Hash::PERM_READ]; |
Comment on lines
+56
to
+72
| $counts = []; | ||
|
|
||
| foreach (Factory::getHashFactory()->filter([Factory::FILTER => $filters]) as $hash) { | ||
| $day = date('Y-m-d', $hash->getTimeCracked()); | ||
| $counts[$day] = ($counts[$day] ?? 0) + 1; | ||
| } | ||
|
|
||
| $binaryFilters = [ | ||
| new QueryFilter(HashBinary::IS_CRACKED, 1, "="), | ||
| new QueryFilter(HashBinary::TIME_CRACKED, $yearStart, ">="), | ||
| new QueryFilter(HashBinary::TIME_CRACKED, $now, "<="), | ||
| ]; | ||
|
|
||
| foreach (Factory::getHashBinaryFactory()->filter([Factory::FILTER => $binaryFilters]) as $hash) { | ||
| $day = date('Y-m-d', $hash->getTimeCracked()); | ||
| $counts[$day] = ($counts[$day] ?? 0) + 1; | ||
| } |
Comment on lines
+41
to
+42
| * Returns a map of date -> crack count for every day from January 1st of the | ||
| * current year up to and including today. |
| @@ -0,0 +1,52 @@ | |||
| import re | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #2019