Due the reason that API is paid, would be nice to have info how many requests in this month was sent on the current installation.
Would be nice to count requests for each type of requests https://cloud.google.com/vision/docs/pricing

Also maybe would be nice to have lock to not exceed some limit

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eugene.ilyin created an issue. See original summary.

eugene.ilyin’s picture

Issue summary: View changes
eugene.ilyin’s picture

Issue summary: View changes
marcoscano’s picture

Do you know if there is a way of retrieving this information from the API?
I was willing to move this issue forward, but I have looked into the documentation and did not found a way to do so, and apparently some other people neither: http://stackoverflow.com/questions/36096176/how-can-i-get-usage-data-for...

Or is the idea just to store this information locally based on the calls done by the module? (assuming then that the application will be the only one being used for a given account/quota)

ajalan065’s picture

Hi marcoscano,
Thank you for showing your interest in the issue.
Actually, there is no such way of retrieving the information directly from the API.

Or is the idea just to store this information locally based on the calls done by the module?

This is partially true, however with a subproblem.

Just storing the number of calls locally won't solve the issue. As because this information is directly attached to the google_vision module, hence if the user disables the module, this information would be lost, thus resetting the count to the initial value.

If this subproblem is tackled accordingly, we can build on this issue.

Please let me know if any further queries need to be answered.

eugene.ilyin’s picture

Yes, I know that data will be lost if module will be disabled. But it's better than nothing. Let's start from it.

eugene.ilyin’s picture

Status: Active » Needs work
ajalan065’s picture

Assigned: Unassigned » ajalan065

Assigning it to myself, as I am working on it.

ajalan065’s picture

Assigned: ajalan065 » eugene.ilyin
Status: Needs work » Needs review
FileSize
37.14 KB

Here is the patch which counts the sent requests.

The mechanism on which the patch works:
1. The status report of the API calls requested is shown under the Reports section of the site.
2. The number of calls made is reset at the end of each month, or we can say, with the start of the next month.
3. Maximum limits for each feature can be set at the Google Vision settings page.
4. If the limits exceed, a drupal message will be shown each time the user tries to use the exhausted features.
5. The reports show the current(today's) date, and the due date(which is the first day of the successive month), in addition to, the number of calls requested and the maximum calls allowed.
6. The simple tests for the issue have also been developed, considering any one of the features as the test feature to demonstrate the functionality of the issue.

Assigning it to Eugene for the review.
Please review :)

eugene.ilyin’s picture

Status: Needs review » Needs work
+    $build['landmark_detection'] = [
+      '#type' => 'number',
+      '#title' => $this->t('Landmark Detection'),
+      '#value' => !empty($config->get('landmark_detection')) ? $config->get('landmark_detection') : 0,
+    ];
+    $build['logo_detection'] = [
+      '#type' => 'number',
+      '#title' => $this->t('Logo Detection'),
+      '#value' => !empty($config->get('logo_detection')) ? $config->get('logo_detection') : 0,
+    ];

I think you can make code shorter if you will use something like this:

$build_options = [
...
'landmark_detection' => 'Landmark Detection',
'logo_detection' => 'Logo Detection',
...
];
and iterate over the elements in the loop.

ajalan065’s picture

Status: Needs work » Needs review
FileSize
36.07 KB
3.49 KB

Here is the new patch with suggestions implemented.

The similar loop cannot be applied to the next half of the controller, as the labels have different names, so it would be of no use to do so.

The optimized and minimized code is patched here.

Please review :)