HiroMacro - how to setup random times (sleep) - random

I'm using this app with this language.
In the link above, i'm refering to point 4.2.8 & 4.2.13. I want to merge these 2 bits of code together.
How do I randomise sleep?
For example:
I want to click button 1 and then button 2.
The time between button1 & button2 needs to be randomly chosen from between 1 and 10 seconds.
This is all I could find:
rand sleep 1000 10000
or
Sleep math.random(1000,10000)
Would this work?
So far I have
:start
touchdown 0 12 123
touchMove 0 12 123 //this part is clicking Button 1
var #sleepTime 0
rand #sleepTime 1000 10000
sleep #sleepTime
// The code you provided to randomly wait between 1 and 10
seconds
touchdown 0 12 145
touchMove 0 12 145
//this part is clicking Button 2
:end

You need to write:
var #sleepTime 0
rand #sleepTime 1000 10000
sleep #sleepTime
Using your code, and the examples in the documentation
(which declares variables before ':start is used)
var #sleepTime 0
:start
rand #sleepTime 1000 10000
touchPress 0 100 200
sleep #sleepTime
touchPress 1 200 200
:end
I think you might need to use touchPress to simulate a button being pressed.

Related

Optimising PixelSearch

I need to optimise this AHK script, currently the script runs in around 2 seconds. I would ultimately like it to run >1 second, the best case would be 0.6 seconds. The basic functionality is the script is clicking on red boxes, of which there can be between 2 - 8. I'd love some help on ways to increase the speed of this script if possible.
Thanks, code below.
1::
; Activate the target window
WinActivate, Paint
; Define the search area
SearchLeft := 1047
SearchTop := 572
SearchRight := 1222
SearchBottom := 650
SetDefaultMouseSpeed, 0
; Start the timer
StartTime := A_TickCount
; Loop through all pixels in the search area and click on them
Loop {
; Search for the next pixel
PixelSearch, Px, Py, SearchLeft, SearchTop, SearchRight, SearchBottom, 0x0000FF, RGBFast, Fastest
if (ErrorLevel = 0) {
; Click on the pixel
Click, %Px%, %Py%, 1
}
else {
; If no pixel is found, exit the loop
break
}
}
; Calculate the elapsed time
ElapsedTime := A_TickCount - StartTime
; Output the elapsed time as a message box
MsgBox, % "Script completed in " . ElapsedTime . " milliseconds."
3::ExitApp

D3 Filter Issue

I am trying to filter my data list using D3. What I am trying to do is filter my data based on date I specify and threshold value for precipitation.
Here is my code as
$(function() {
$("#datepicker").datepicker();
$("#datepicker").on("change",function(){
//var currentDate = $( "#datepicker" ).datepicker( "getDate" )/1000;
//console.log(currentDate)
});
});
function GenerateReport() {
d3.csv("/DataTest.csv", function(data) {
var startdate = $( "#datepicker" ).datepicker( "getDate" )/1000;
var enddate = startdate + 24*60*60
var data_Date = d3.values(data.filter(function(d) { return d["Date"] >=
startdate && d["Date"] <= enddate} ))
var x = document.getElementById("threshold").value
console.log(data_Date)
var data_Date_Threshold = data_Date.filter(function(d) {return
d.Precipitation > x});
My data set looks like
ID Date Prcip Flow Stage
1010 1522281000 0 0 0
1010 1522281600 0 0 0
1010 1522285200 10 0 0
1010 1522303200 12 200 1.2
1010 1522364400 6 300 2
1010 1522371600 4 400 2.5
1010 1522364400 6 500 2.8
1010 1522371600 4 600 3.5
2120 1522281000 0 0 0
2120 1522281600 0 0 0
2120 1522285200 10 100 1
2120 1522303200 12 1000 2
2120 1522364400 6 2000 3
2120 1522371600 4 2500 3.2
2290 1522281000 0 0 0
2290 1522281600 4 0 0
2290 1522285200 5 200 1
2290 1522303200 10 800 1.5
2290 1522364400 6 1500 3
2290 1522371600 0 1000 2
6440 1522281000 0 0 0
6440 1522281600 4 0 0
6440 1522285200 5 200 0.5
6440 1522303200 10 800 1
6440 1522364400 6 1500 2
6440 1522371600 0 100 1.4
When I use filter function, I have some problems.
What I have found is that when I use x = 2 to filter precipitation value, it does not catch precipitation = 10 or 12. However, when I use x=1, it works fine. I am guessing that it catches only the first number (e.g., if x=2, it regards precipitation = 10 or 12 is less than 2 since it looks only 1 in 10 and 12) Is there anyone who had the same issue what I have? Can anyone help me to solve this problem?
Thanks.
You are comparing strings. This comparison is therefore done lexicographically.
In order to accomplish what you want, you need to first convert these strings to numbers:
var x = Number(document.getElementById("threshold").value)
var data_Date_Threshold = data_Date.filter(function(d) {return Number(d.Precipitation) > x});
Alternatively, floats:
var x = parseFloat(document.getElementById("threshold").value)
var data_Date_Threshold = data_Date.filter(function(d) {return parseFloat(d.Precipitation) > x});

Round minutes 20 in 20 in visual fox pro

please i'm having problems resolving a function about a program in Visual Fox Pro.
I need to make a rounding down every 20 minutes in decimal.
For example: if i recive 19 minutes (0.316) y need return 0 minutes.
if i get between 0-19 minutes, return 0 minutes
if i get between 20-39 minutes, return 20 minutes
if i get between 40-59 minutes, return 40 minutes
if i get between 60-79 minutes, return 60 minutes
i was thinking use ROUND() but i don't know how because "Round" Approaches to the nearest decimal.
thanks in advance.
roundedMinutes = Floor( m.myMinute / 20 ) * 20
For example:
Create Cursor SampleMin (minutes i, rounded i)
Local ix
For ix = 1 To 600
Insert Into SampleMin ;
(minutes, rounded) ;
values ;
(m.ix, Floor(m.ix/20) * 20)
Endfor
Locate
Browse
Here's a small prg I made that will hopefully help you or at least start you in the right direction.
lnStart = 0
lnEnd = 20
lnReceivedMinutes = 500
llNotDone = .T.
IF lnReceivedMinutes > 0
DO WHILE llNotDone
IF BETWEEN(lnReceivedMinutes, lnStart, lnEnd)
llNotDone = .F.
MESSAGEBOX(ALLTRIM(STR(lnStart)) + " Minutes")
ELSE
lnStart = lnStart + 20
lnEnd = lnEnd + 20
ENDIF
ENDDO
ENDIF
I check to see if the value received is between my lnStart and lnEnd. If it is not then I check for the next 20 minutes.
Cetin Basoz gave correct answer
roundedMinutes = Floor( m.myMinute / 20 ) * 20
I have checked myself

Algorithm Check for Switch Program

I have 4 switches that are randomly generated at run time. Ex:
Switch1: 1 0 0 0
Switch2: 0 1 0 0
Switch3: 0 0 1 0
Switch4: 0 0 0 1
When the switch is generated, the column for the switch number needs to be 1, but all other columns are randomly assigned (1 or 0).
A main switch performs an XOR operation on a switch that the user selects. The main switch starts at 0 0 0 0.
When the user selects a switch ( s1,s2,s3,s4 ) it is "XOR"ed to the current main switch.
Real Case:
S1: 1 1 0 0
S2: 0 1 1 0
S3: 0 0 1 0
S4: 1 0 0 1
START: 0 0 0 0
AND S1:1 1 0 0
AND S3:1 1 1 0
The objective is to get the main switch to 1 1 1 1.
When the four switches are created at run-time, I need to ensure that the puzzle is solvable. Any suggestions on how I can compare the four switches to determine if there is a combination to achieve a winning result of 1 1 1 1.
UPDATE------------
Note:
0 and 0 = 0
1 and 1 = 0
0 and 1 = 1
The main switch starts at 0 0 0 0.
When the user selects a switch ( s1,s2,s3,s4 ) it is ANDED to the current main switch.
If you start with 0000 and the only operation available is AND, you cannot get anything except 0000 as a result: 0 & 1 = 0, not 0 & 1 = 1.
Based on the example in your Real Case, it appears that you are performing an OR operation. If this is the case then any puzzle is solvable since
the column for the switch number needs to be 1
If you OR each switch with the original 0000 main switch you will always get 1111. You may get it before OR'ing with all four switches, based on the other randomly assigned bits, but you are guaranteed to get 1111 if you OR each switch with the original main switch.
This can be solved pretty easy, assuming you represent the switches as Integer:
public boolean isSolvable(Switch[] switches){
int[] tmp = new int[SWITCH.COUNT];
//generate an integer with all 1s of all switches
for(Switch sw : switches)
for(int i = 0 ; i < tmp.length ; i++)
tmp[i] |= sw.get(i);
//check if all bits that are part of the switches are 1
for(int i : tmp)
if(i == 0)
return false;//this bit is 0 -> can't be set to 1 by combining switches
//all bits can be set to 1 by combining switches
return true;
}
Hope this java-code helps. I can explain further if necassary. Though the constraint that switch i has column i set to 1 ensures that a solution exists, if the number of switches is atleast equal to the number of columns in each switch.

First Come First Serve Wait Time Algorithm

As i understand FCFS does not need any sorting but there are no examples covered in the internet what happens if waiting time goes negative?
So i understand that algorithm for waiting time is: WT = CT (Completion Time) - AT (Arrival Time) - BT (Burst Time).
But what happens if i have:
AT: 0 / BT: 2
AT: 0 / BT: 4
AT: 15 / BT: 5
AT: 21 / BT: 10
My calculations would be:
WT = 2 - 0 - 2 = 0
WT = 6 - 0 - 4 = 2
WT = 11 - 15 -5 = -9
WT = 21 - 21 - 10 = -10
Avg: (0+2-10-9)/4 = -17/4 = -4,25 (seems unreal)
Is the correct answer negative or should i modify the algorithm somehow?

Resources