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

90
LINES

< > BotCompany Repo | #1013031 // Matrix Module [Smart Bot Dyn]

JavaX module [tags: use-pretranspiled]

Download Jar. Libraryless. Click here for Pure Java version (12998L/89K/289K).

1  
!7
2  
3  
// "Matrix functions" are not supposed to use the index
4  
// ...but now they can.
5  
6  
!include once #1013530 // Dyn
7  
8  
html {
9  
  bool authed = creatorAuthed();
10  
  
11  
  S _topic = params.get("topic");
12  
  if (empty(_topic))
13  
    _topic = ai_randomString();
14  
  fS topic = _topic;
15  
  if (nempty(params.get("topic"))) { // not from "random topic" url
16  
    // post user's answers (verified or unverified)
17  
    
18  
    // free-text line
19  
    S newCat = params.get("new-cat"), newValue = params.get("new-value");
20  
    if (nempty(newCat)) {
21  
      S verb = ai_matrix_answerToVerb(newValue);
22  
      if (nempty(verb))
23  
        post(topic, verb, newCat);
24  
      else
25  
        post(quote(newCat), " is a matrix category for", topic);
26  
    }
27  
    
28  
    // all other lines
29  
    for (S key : keysStartingWith2(params, "cat-")) {
30  
      S value = params.get(key);
31  
      continue if empty(value);
32  
      S verb = ai_matrix_answerToVerb(value);
33  
      continue if empty(verb);
34  
      S cat = urldecode(dropPrefix("cat-", key));
35  
      temp tempSetThreadLocal(ai_postTriple_verified, authed);
36  
      post(topic, verb, cat);
37  
    }
38  
  }
39  
  
40  
  L<S> functions = ai_matrix_standardFunctions();
41  
  Map<S, O> rawResults = evaluateFunctionsAsMap(functions, topic);
42  
  SS results = mapValues(f ai_html_struct, rawResults);
43  
  for (S f : keys(rawResults))
44  
    postWithSource(topic, "under " + f + " is", sfu(rawResults.get(f)), "matrix");
45  
46  
  final L<S> answers = concatLists(ll(""), ai_matrix_standardAnswers());
47  
  
48  
  Set<S> options = ai_matrix_categoriesForTopic(topic);
49  
  options.addAll(ai_matrix_standardCategories());
50  
  
51  
  L<Map> data = map(options, func(S cat) -> Map {
52  
    S userAnswer = null;
53  
54  
    ret litorderedmap(
55  
      "Statement", b(htmlencode2(topic)) + " is " + html_matrixLink(cat),
56  
      "Computer Answer", htmlEncode(ai_matrixGet(topic, cat)),
57  
      "Your Answer",
58  
        hselect_list(answers, userAnswer, name := "cat-" + urlencode(cat))
59  
        //hcheckbox(urlencode(s), tossCoin())
60  
    );
61  
  });
62  
  
63  
  S formURL =
64  
    //smartBotRealURL() + "/dyn/" + psI(programID()) + "?topic=" + urlencode(topic);
65  
    smartBot_matrixLink(topic);
66  
  
67  
  // Free category entry line
68  
  data.add(litorderedmap(
69  
    "Statement", b(htmlencode2(topic)) + " is " + htextinput("new-cat", onkeypress :=
70  
      [[ if ($("#new_value").val() == '') $("#new_value").val("yes").prop('selected', true); ]]),
71  
    "Your Answer", hselect_list(answers, name := "new-value", id := "new_value")));
72  
  
73  
  // Main HTML
74  
  
75  
  ret hstyle_matrixBackground()
76  
    + htitle_htmlencode("Matrix: " + topic) + loadJQuery() 
77  
    + div(small(authed ? "Authed" : "Not authed"), style := "position:absolute; right: 10px; top: 10px;")
78  
    + hcenter(
79  
      hform("Topic: " + hinputfield('topic, value := topic), style := "display: inline", action := smartBot_emptyMatrixLink()) + " "
80  
    + hform(hsubmit("Random"), style := "display: inline", action := "/matrix/")
81  
    + p(b(
82  
      hfontsize(15, "Matrix Page for:") + "<br>" +
83  
      targetBlank(smartBot_encyclopediaLink(topic), hfontsize(40, topic), style := "text-decoration: none")) + "<br>"
84  
      /*+ ahref(smartBot_encyclopediaLink(topic), "[more]")*/, style := "margin-top: 3em")
85  
    + hpostform(hhidden(+topic)
86  
    + hsubmit("Save answers") + "<br><br>"
87  
    + htable_noEncode(data), action := formURL)
88  
    + htable_noEncode(mapToListOfMaps(results, "Function", "Result"))
89  
  );
90  
}

Author comment

Began life as a copy of #1013022

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1013031
Snippet name: Matrix Module [Smart Bot Dyn]
Eternal ID of this version: #1013031/86
Text MD5: e561ccd748286bdf383138606739c66b
Transpilation MD5: 8639c0dc326e0598a951471c267f03c7
Author: stefan
Category: javax / a.i. / html
Type: JavaX module
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-01-08 06:33:40
Source code size: 3416 bytes / 90 lines
Pitched / IR pitched: No / No
Views / Downloads: 752 / 2202
Version history: 85 change(s)
Referenced in: [show references]