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

65
LINES

< > BotCompany Repo | #1027021 // Mini Consciousness Analyzing Reboots

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 1319K of libraries. Click here for Pure Java version (4203L/21K).

1  
!7
2  
3  
// TODO: wait with the test on boot until #1027019 has done its thing
4  
5  
cmodule RebootConsciousness > DynPrintLog {
6  
  DoubleRange typicalTimeToReboot = new(1000, 0);
7  
  
8  
  start-thread {
9  
    theTest();
10  
    /*watchQuotedLog_future(rebootLogFile(), 1000, voidfunc(S s) {
11  
      new Matches m;
12  
      if "* Rebooting computer"
13  
        predictReboot();
14  
    });*/
15  
    
16  
    dm_vmBus_onMessage_q doingCleanReboot(r predictReboot);
17  
  }
18  
  
19  
  void theTest {
20  
    LS lastLines = unquoteAll(lastNLines(2, rebootLogFile()));
21  
    pnl(lastLines);
22  
    analyzeLines(lastLines);
23  
  }
24  
  
25  
  void analyzeLines(LS lastLines) {
26  
    if (empty(lastLines)) ret;
27  
    if (l(lastLines) == 1) ret with confused("Only one event: " + lastLines);
28  
    
29  
    S line1 = first(lastLines), line2 = second(lastLines);
30  
    new Matches m;
31  
    new Matches m2;
32  
    if (match("* Rebooting computer", line1, m)
33  
      && match("* Boot timestamp changed from * to *", line2, m2)) {
34  
      long ts1 = parseLong(m.get(0)), ts2 = parseLong(m2.get(2));
35  
      if (ts2 > ts1) {
36  
        notConfused("All OK! A reboot happened after my reboot command");
37  
        double timeToReboot = toSeconds(ts2-ts1);
38  
        setField(typicalTimeToReboot := DoubleRange(
39  
          min(typicalTimeToReboot.start, timeToReboot),
40  
          max(typicalTimeToReboot.end, timeToReboot));
41  
      } else
42  
        confused("Timestamps are weird: " + lastLines);
43  
    } else
44  
      confused("Was expecting reboot cmd & then reboot effect: " + lastLines);
45  
  }
46  
  
47  
  void confused(S msg) {
48  
    printAndProgramLog("Confused: " + msg);
49  
  }
50  
  
51  
  void notConfused(S msg) {
52  
    printAndProgramLog("I am very satisfied. " + msg);
53  
  }
54  
  
55  
  void predict(S msg) {
56  
    printAndProgramLog("I predict: " + msg);
57  
    dm_sayInEnglish(msg);
58  
  }
59  
  
60  
  void predictReboot enter {
61  
    predict("A reboot will happen in between "
62  
      + formatDouble(typicalTimeToReboot.start, 1) + " and "
63  
      + formatDouble(typicalTimeToReboot.end, 1) + " seconds");
64  
  }
65  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1027021
Snippet name: Mini Consciousness Analyzing Reboots
Eternal ID of this version: #1027021/21
Text MD5: 38140197fc503dac9d2ff6719d601d79
Transpilation MD5: 953f3bf483a02d529684f074e58dca0d
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-10 15:20:50
Source code size: 2013 bytes / 65 lines
Pitched / IR pitched: No / No
Views / Downloads: 196 / 717
Version history: 20 change(s)
Referenced in: [show references]