It is currently April 26th, 2024, 10:10 pm

Instantaneous CPS algorithm

Get help with creating, editing & fixing problems with skins
User avatar
Yincognito
Rainmeter Sage
Posts: 7175
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Instantaneous CPS algorithm

Post by Yincognito »

EnhancedJax wrote: August 8th, 2021, 11:29 am Yeah. that's it.

For example, if we have a data set like this:
Sec1: 5 clicks (0 to 1)s
Sec2: 7 clicks (1 to 2)s
If the time extracting the CPS is at 1.5s, it would be the num of clicks from 0.5s to 1.5s, lets expand the data set
Column: Each 100ms, row: each sec
Sec1: 0 1 0 0 1 1 1 1 1 0
Sec2: 1 1 1 0 0 1 1 0 0 0
the CPS then would be [ 1 1 1 1 0 1 1 1 0 0 ] -> 7

If we set the "instant range" as 1, we would always get an integer, for a smoother result we could use 2 as the "instant range"... so I guess what is left is the execution?
Yep, I understand what you mean. That will be slightly difficult as, apart from the update rate, Rainmeter can't measure time less than 1 second. But then, if you're ok with basing the code on the inaccurate update rate, all will be good and doable. I have some things to take care of now for a couple of hours, so I'll take a look at the required code afterwards, if death.crafter doesn't come with a feasible solution in the meantime.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
EnhancedJax
Posts: 19
Joined: October 17th, 2020, 11:57 am

Re: Instantaneous CPS algorithm

Post by EnhancedJax »

Thanks, and take your time! :)
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Instantaneous CPS algorithm

Post by death.crafter »

EnhancedJax wrote: August 8th, 2021, 12:27 pm Thanks, and take your time! :)
SKIN:

Code: Select all

[Rainmeter]
Update=50

[Variables]
Time=0
Clicks=0
CPS=0

[Time]
Measure=Calc
Formula=Time+0.05
DynamicVariables=1

[Lua]
Measure=Script
ScriptFile=Tester.lua

[Image]
Meter=Image
SolidColor=FEFEFE
H=69
W=50
DynamicVariables=1
LeftMouseUpAction=[!SetVariable Clicks "(#Clicks#+1)"][!CommandMeasure Lua "t[[&Time]]=[#Clicks]"]

[String]
Meter=String
X=10
Y=25
Text=#CPS#
DynamicVariables=1
LUA:

Code: Select all

t={}

function Update()
    e=SKIN:GetMeasure('Time'):GetValue()
    s=e-1
    local m={}
    for k,v in pairs(t) do
        if k>=s and k<=e then
            table.insert(m, v)
        end
    end
    SKIN:Bang('!SetVariable', 'CPS', table.maxn(m))
end
1st Edit:
P.S.> Max clicks you can count is 62, at an update 16. Good luck! :thumbup:

2nd Edit:
If Rainmeter can keep up that is.
from the Realm of Death
User avatar
EnhancedJax
Posts: 19
Joined: October 17th, 2020, 11:57 am

Re: Instantaneous CPS algorithm

Post by EnhancedJax »

death.crafter wrote: August 8th, 2021, 12:38 pm SKIN:

Code: Select all

[Rainmeter]
Update=50

[Variables]
Time=0
Clicks=0
CPS=0

[Time]
Measure=Calc
Formula=Time+0.05
DynamicVariables=1

[Lua]
Measure=Script
ScriptFile=Tester.lua

[Image]
Meter=Image
SolidColor=FEFEFE
H=69
W=50
DynamicVariables=1
LeftMouseUpAction=[!SetVariable Clicks "(#Clicks#+1)"][!CommandMeasure Lua "t[[&Time]]=[#Clicks]"]

[String]
Meter=String
X=10
Y=25
Text=#CPS#
DynamicVariables=1
LUA:

Code: Select all

t={}

function Update()
    e=SKIN:GetMeasure('Time'):GetValue()
    s=e-1
    local m={}
    for k,v in pairs(t) do
        if k>=s and k<=e then
            table.insert(m, v)
        end
    end
    SKIN:Bang('!SetVariable', 'CPS', table.maxn(m))
end
P.S.> Max clicks you can count is 62, at an update 16. Good luck! :thumbup:

:o This is exactly what I needed! Thankyou so much!
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Instantaneous CPS algorithm

Post by death.crafter »

EnhancedJax wrote: August 8th, 2021, 12:42 pm :o This is exactly what I needed! Thankyou so much!
8-)

By the way nice work with the ArcTech clocks. :great:
from the Realm of Death
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: Instantaneous CPS algorithm

Post by death.crafter »

EnhancedJax wrote: August 8th, 2021, 12:42 pm :o This is exactly what I needed! Thankyou so much!
In case it causes memory leaks due to more usage(in case):

Code: Select all

t={}

function Update()
    e=SKIN:GetMeasure('Time'):GetValue()
    s=e-1
    local m={}
    for k,v in pairs(t) do
        if k<s then
            table.remove(t, k)
        end
        if k>=s and k<=e then
            table.insert(m, v)
        end
    end
    SKIN:Bang('!SetVariable', 'CPS', table.maxn(m))
end
from the Realm of Death
User avatar
chrismorris
Posts: 1
Joined: May 18th, 2022, 7:30 am

Re: Instantaneous CPS algorithm

Post by chrismorris »

death.crafter wrote: August 8th, 2021, 12:38 pm SKIN:

Code: Select all

[Rainmeter]
Update=50

[Variables]
Time=0
Clicks=0
CPS=0

[Time]
Measure=Calc
Formula=Time+0.05
DynamicVariables=1

[Lua]
Measure=Script
ScriptFile=Tester.lua

[Image]
Meter=Image
SolidColor=FEFEFE
H=69
W=50
DynamicVariables=1
LeftMouseUpAction=[!SetVariable Clicks "(#Clicks#+1)"][!CommandMeasure Lua "t[[&Time]]=[#Clicks]"]

[String]
Meter=String
X=10
Y=25
Text=#CPS#
DynamicVariables=1
LUA:

Code: Select all

t={}

function Update()
    e=SKIN:GetMeasure('Time'):GetValue()
    s=e-1
    local m={}
    for k,v in pairs(t) do
        if k>=s and k<=e then
            table.insert(m, v)
        end
    end
    SKIN:Bang('!SetVariable', 'CPS', table.maxn(m))
end
1st Edit:
P.S.> Max clicks you can count is 62, at an update 16. Good luck! :thumbup:

2nd Edit:
If Rainmeter can keep up that is.
man I made account just to thank you. I had been struggling for a couple of days while making my CPS test that could calculate instant clicks per second. deleted everything and implemented your code and it worked in single time! kudos to you.
Last edited by Active Colors on May 19th, 2022, 8:57 am, edited 1 time in total.
Reason: Removed external link