It is currently Sun Jun 30, 2024 3:16 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: timer plug-in acts sort of like a stop watch w/wo TRACKING CODE
PostPosted: Sat Nov 25, 2023 8:55 pm  (#1) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3999
Location: Canada
Since I was interested in how much time plug-ins save compared to manual process,
I wrote this timer-tt.py plug-in
If you map it to shortcut (I use Ctrl+T) by going to Edit/Preferences>Interface then scroll on right down to Shortcuts and search for my timer plugin and just mapped it to Ctrl+T (but Ctrl+T in GIMP toggles the show selection flag, I never use that so it's fine for me).
Then every, you hit Ctrl+T it gives you the time since you last Ctrl+T-ed.
Sort of like a stop watch internally to gimp.
I'll just output number in seconds out to the error console using pdb.gimp_message.
#!/usr/bin/env python
# timer.py
# Creator: TT
# This plug-in was intended to be used as a way to roughly measure a manual process.
# If you map it to a shortcut (ie. Ctrl+T) then just Ctrl+T before you do your manual editing/operations in GIMP
# Then when you're done, just Ctrl+T again and it'll gimp_message the time in seconds since the last time you hit Ctrl+T
# Open Source
# Rel: 1.0
from gimpfu import *
import time
global_var_id = 'timertt' #used to store our startt timer.
def set_global_variable(value):
    gimp.set_data(global_var_id, str(value))

def get_global_variable():
    return float(gimp.get_data(global_var_id))

def timer_tt():
    try:
        startt = get_global_variable()
    except RuntimeError:
        startt = time.time()
    endt = time.time()
    time_taken = endt-startt
    pdb.gimp_message("Time since last call in secs:" + str(time_taken))
    set_global_variable(time.time())
   
# Register the Python-Fu plugin
register(
    "python_fu_timer_tt",
    "Times since last this plug-in was call",
    "Times since last this plug-in was call",
    "TT",
    "TT",
    "2023.11.25",
    "Timer",
    "",      # Alternately use RGB, RGB*, GRAY*, INDEXED etc.
    [
    #INPUT BEGINS
    #(PF_IMAGE, "img", "Image", None),
    #(PF_DRAWABLE,   "layer", "Drawable", None),
    #INPUT ENDS
    ],
    [],
    timer_tt,
    menu="<Image>/Python-Fu")

main()

_________________
TinT


Last edited by trandoductin on Sun Nov 26, 2023 6:32 pm, edited 1 time in total.

Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: timer plug-in acts sort of like a stop watch
PostPosted: Sun Nov 26, 2023 6:07 pm  (#2) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 3999
Location: Canada
This version has TRACKING code.
TRACKING only increments a single counter each time the plug-in is called/used.
#!/usr/bin/env python
# timer.py
# Creator: TT
# =======================================================================================
# NOTICE: This version has tracking code which increments a single counter each use.
# You can get untracked version at http://gimpchat.com/viewtopic.php?f=9&t=20651#p285522
# =======================================================================================
# This plug-in was intended to be used as a way to roughly measure a manual process.
# If you map it to a shortcut (ie. Ctrl+T) then just Ctrl+T before you do your manual editing/operations in GIMP
# Then when you're done, just Ctrl+T again and it'll gimp_message the time in seconds since the last time you hit Ctrl+T
# Open Source
# Rel: 1.0
from gimpfu import *
import time
# TRACKING CODE STARTS ================================================================================
# ================================================================================================
import requests
def hit_it(): #this function is called whenever we want to increment counter of var timertt in data below
    TRACKING_VARNAME = 'timertt' #Change this value to track different var for each plug-in
    # Replace these values with your Firebase configuration
    firebase_config = {"apiKey": "AIzaSyApnXYZuSzdpQNXYg0ZWHLF2t3VHjqmf9k","databaseURL": "https://single-counter-default-rtdb.firebaseio.com/"}
    counter_path = TRACKING_VARNAME + ".json"
    response = requests.get(firebase_config['databaseURL']+counter_path,params={"key": firebase_config["apiKey"]})
    if response.status_code == 200:
        current_value = response.json()
        if current_value is None: #FIRST RUN EVER doesn't have a value we'll just make value 0 so it can be incremented
            current_value = 0
        new_value = current_value + 1
        update_response = requests.put(firebase_config['databaseURL']+counter_path,json=new_value,params={"key": firebase_config["apiKey"]})
        if update_response.status_code == 200:
            pass
        #pdb.gimp_message(new_value) #debug to see incremented value   

# TRACKING CODE ENDS ==================================================================================
# =================================================================================================

global_var_id = 'timertt' #used to store our startt timer.
def set_global_variable(value):
    gimp.set_data(global_var_id, str(value))

def get_global_variable():
    return float(gimp.get_data(global_var_id))

def timer_tt():
    try:
        startt = get_global_variable()
    except RuntimeError:
        startt = time.time()
    endt = time.time()
    time_taken = endt-startt
    pdb.gimp_message("Time since last call in secs:" + str(time_taken))
    hit_it() #tracking usage here
    set_global_variable(time.time())
   
# Register the Python-Fu plugin
register(
    "python_fu_timer_tt",
    "Times since last this plug-in was call",
    "Times since last this plug-in was call",
    "TT",
    "TT",
    "2023.11.25",
    "Timer",
    "",      # Alternately use RGB, RGB*, GRAY*, INDEXED etc.
    [
    #INPUT BEGINS
    #(PF_IMAGE, "img", "Image", None),
    #(PF_DRAWABLE,   "layer", "Drawable", None),
    #INPUT ENDS
    ],
    [],
    timer_tt,
    menu="<Image>/Python-Fu")

main()

here's the tracking code portion
# TRACKING CODE STARTS ================================================================================
# ================================================================================================
import requests
def hit_it(): #this function is called whenever we want to increment counter of var timertt in data below
    TRACKING_VARNAME = 'timertt' #Change this value to track different var for each plug-in
    # Replace these values with your Firebase configuration
    firebase_config = {"apiKey": "AIzaSyApnXYZuSzdpQNXYg0ZWHLF2t3VHjqmf9k","databaseURL": "https://single-counter-default-rtdb.firebaseio.com/"}
    counter_path = TRACKING_VARNAME + ".json"
    response = requests.get(firebase_config['databaseURL']+counter_path,params={"key": firebase_config["apiKey"]})
    if response.status_code == 200:
        current_value = response.json()
        if current_value is None: #FIRST RUN EVER doesn't have a value we'll just make value 0 so it can be incremented
            current_value = 0
        new_value = current_value + 1
        update_response = requests.put(firebase_config['databaseURL']+counter_path,json=new_value,params={"key": firebase_config["apiKey"]})
        if update_response.status_code == 200:
            pass
        #pdb.gimp_message(new_value) #debug to see incremented value   

# TRACKING CODE ENDS ==================================================================================
# =================================================================================================

it defines one function call hit_it() which is called once by the plug-in itself that hits the database and increases a single counter
with TRACKING_VARNAME = 'timertt'
for a different plug-in i would change the timertt to something else.
and then anyone can view these tracked single counters on GIMP Plug-in Stats Usage

If you plan to use this tracking for other plug-ins it'll work and define the counter the first time you run it as 1 if you define your own TRACKING_VARNAME.
but it won't show up on the above stats page until I add it to the page.
But you can view the TRACKING_VARNAME you're interested in by going to
https://tinmantaken.blogspot.com/2023/11/view-gimp-plug-in-usage-stats.html?var=timertttest
just replace timertttest with your TRACKING_VARNAME value to temporarily see the value before it's hardcode added to the stats page.

There is also commented out line at end of TRACKING CODE that you uncomment and see the value using pdb.gimp_message.

this tracking call is called when the plug-in isn't doing time calculation so the timer functionality is still as accurate as before.

_________________
TinT


Top
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) A sort of spotlight effect?

6

No new posts Attachment(s) Never stop...

1

No new posts Watch Folder and load image as layer

1

No new posts Traffic stop

3



* Login  



Powered by phpBB3 © phpBB Group