Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

53
LINES

< > BotCompany Repo | #1002065 // Function Watcher Bot

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (743L/6K/18K).

1  
!752
2  
3  
static volatile long startedWatching, endedWatching;
4  
static volatile double currentValue, lastValue;
5  
static volatile double minValue = Double.MAX_VALUE, maxValue = Double.MIN_VALUE;
6  
7  
static volatile double avgSum, deltaAvgSum;
8  
static volatile long avgCount, deltaAvgCount;
9  
static volatile long maxRuntime;
10  
static volatile long n;
11  
static volatile boolean actuallyEnded;
12  
13  
p {
14  
  thread {
15  
    print("Started watching.");
16  
    startedWatching = now();
17  
    while (licensed()) {
18  
      ++n;
19  
      endedWatching = now();
20  
      currentValue = callIt();
21  
      long runtime = now()-endedWatching;
22  
      if (n > 1) {
23  
        deltaAvgSum += currentValue-lastValue;
24  
        deltaAvgCount++;
25  
      }
26  
      lastValue = currentValue;
27  
      if (runtime > maxRuntime) maxRuntime = runtime;
28  
      if (currentValue < minValue) minValue = currentValue;
29  
      if (currentValue > maxValue) maxValue = currentValue;
30  
      avgCount++;
31  
      avgSum += currentValue;
32  
      sleepSeconds(1); // TODO: sleep until specific time
33  
    }
34  
    print("Done watching.");
35  
    actuallyEnded = true;
36  
  }
37  
}
38  
39  
static double callIt() {
40  
  ret unixTime();
41  
}
42  
43  
static S html() {
44  
  new L l;
45  
  for (S field : listFields(getMainClass())) {
46  
    S value = "(Error getting value)";
47  
    pcall {
48  
      value = structure(get(getMainClass(), field));
49  
    }
50  
    l.add(litmap("Field", field, "Value", value));
51  
  }
52  
  ret "<h4>Variables</h4>" + htmlTable(l);
53  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002065
Snippet name: Function Watcher Bot
Eternal ID of this version: #1002065/1
Text MD5: df3c6f1326c26bfc79d10e481b09270c
Transpilation MD5: 2369a7bca57c01be2d8bd234bc484902
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-16 00:20:33
Source code size: 1452 bytes / 53 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 693 / 1983
Referenced in: [show references]