
    g                     B    d dl mZ d dlZd dlmZmZ d dlmZ d Zd Z	dS )    wrapsN)requestg)get_db_connectionc                 <     t                      fd            }|S )Nc                     	 t           j        }t          j                                                                        }t                      }|                                }|                    d||f           |                                 |	                                 |	                                 n)# t          $ r}t          d|            Y d }~nd }~ww xY w | i |S )Nz
                INSERT INTO api_usage (endpoint, date)
                VALUES (%s, %s)
                ON DUPLICATE KEY UPDATE total = total + 1
            u   ❌ Failed to track usage: )r   pathdatetimeutcnowdater   cursorexecutecommitclose	Exceptionprint)argskwargsr
   nowconnr   efuncs          7/var/www/wisegym.app/api/functions/statistic_service.pywrapperztrack_usage.<locals>.wrapper   s    	5<D#**,,1133C$&&D[[]]FNN  	  
 KKMMMLLNNNJJLLLL 	5 	5 	533344444444	5tT$V$$$s   B2B6 6
C CCr   )r   r   s   ` r   track_usager      s3    
4[[% % % % [%$ N    c                     	 t                      } |                     d          }t          j                                                                        t          j        d          z
  }|                    d|f           |                                }|                                 |                                  d|idgS # t          $ r/}t          d|            d	t          |          id
gcY d }~S d }~ww xY w)NT)
dictionary   )daysz
            SELECT date, SUM(total) as total
            FROM api_usage
            WHERE date >= %s
            GROUP BY date
            ORDER BY date ASC
        usage   u   ❌ Failed to get API usage: errori  )r   r   r   r   r   	timedeltar   fetchallr   r   r   str)r   r   seven_days_agor"   r   s        r   get_api_usager)      s   * ""--"+224499;;h>PVW>X>X>XX  	  	  	  !!

5"C(( * * *1a112223q66#S)))))))*s   CC 
C>$C93C>9C>)
	functoolsr   r   flaskr   r   	db_configr   r   r)    r   r   <module>r.      sr                   ' ' ' ' ' '  ,* * * * *r   