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).

!7

// TODO: wait with the test on boot until #1027019 has done its thing

cmodule RebootConsciousness > DynPrintLog {
  DoubleRange typicalTimeToReboot = new(1000, 0);
  
  start-thread {
    theTest();
    /*watchQuotedLog_future(rebootLogFile(), 1000, voidfunc(S s) {
      new Matches m;
      if "* Rebooting computer"
        predictReboot();
    });*/
    
    dm_vmBus_onMessage_q doingCleanReboot(r predictReboot);
  }
  
  void theTest {
    LS lastLines = unquoteAll(lastNLines(2, rebootLogFile()));
    pnl(lastLines);
    analyzeLines(lastLines);
  }
  
  void analyzeLines(LS lastLines) {
    if (empty(lastLines)) ret;
    if (l(lastLines) == 1) ret with confused("Only one event: " + lastLines);
    
    S line1 = first(lastLines), line2 = second(lastLines);
    new Matches m;
    new Matches m2;
    if (match("* Rebooting computer", line1, m)
      && match("* Boot timestamp changed from * to *", line2, m2)) {
      long ts1 = parseLong(m.get(0)), ts2 = parseLong(m2.get(2));
      if (ts2 > ts1) {
        notConfused("All OK! A reboot happened after my reboot command");
        double timeToReboot = toSeconds(ts2-ts1);
        setField(typicalTimeToReboot := DoubleRange(
          min(typicalTimeToReboot.start, timeToReboot),
          max(typicalTimeToReboot.end, timeToReboot));
      } else
        confused("Timestamps are weird: " + lastLines);
    } else
      confused("Was expecting reboot cmd & then reboot effect: " + lastLines);
  }
  
  void confused(S msg) {
    printAndProgramLog("Confused: " + msg);
  }
  
  void notConfused(S msg) {
    printAndProgramLog("I am very satisfied. " + msg);
  }
  
  void predict(S msg) {
    printAndProgramLog("I predict: " + msg);
    dm_sayInEnglish(msg);
  }
  
  void predictReboot enter {
    predict("A reboot will happen in between "
      + formatDouble(typicalTimeToReboot.start, 1) + " and "
      + formatDouble(typicalTimeToReboot.end, 1) + " seconds");
  }
}

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: 266 / 804
Version history: 20 change(s)
Referenced in: