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

57
LINES

< > BotCompany Repo | #1003048 // Load Slack log & tags (include)

JavaX fragment (include)

sclass Tag {
  S name;
}

sclass SlackMsg {
  S user, botName; // one of these is going to be set
  S userName; // looked up if user != null
  S type, text, ts;
  O reactions;
  S channelID;
  
  int index;
  new TreeSet<S> tags;
}

static PersistentMap<S, L<Tag>> tagMap;
static PersistentLog<SlackMsg> msgs;
static new L<SlackMsg> taggedMsgs;
static new TreeMap<Integer, SlackMsg> msgsByIndex;
static new MultiMap<S, SlackMsg> msgsByTag;

static void init() {
  tagMap = new PersistentMap("#1002192", "tagsByTS.log");
  print("Tags: " + l(tagMap));
  
  S channelName = "talkingbots";
  msgs = new PersistentLog("#1002185", parseChannelName(channelName) + ".msgs");
  print("Msgs: " + l(msgs));
  if (empty(tagMap) || empty(msgs)) fail("no data");
  
  //printStructure(last(msgs));
  
  // put tags and index in messages
  int n = 1;
  for (SlackMsg msg : msgs) {
    L<Tag> tags = tagMap.get(msg.ts);
    /*if (nempty(tags))
      print(structure(tags) + " " + structure(msg));*/
    msg.text = trim(msg.text);
    msg.index = n++;
    msgsByIndex.put(msg.index, msg);
    for (Tag t : unnull(tags)) {
      if (msg.tags.add(t.name))
        msgsByTag.put(t.name, msg);
    }
    if (nempty(msg.tags))
      taggedMsgs.add(msg);
  }
  
  print(l(taggedMsgs) + " tagged msgs.");
}

static void filterTag(S tag) {
  for (SlackMsg msg : msgs) {
    msg.tags = msg.tags.contains(tag) ? littreeset(tag) : main.<S> littreeset();
  }
}

Author comment

Began life as a copy of #1003042

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: #1003048
Snippet name: Load Slack log & tags (include)
Eternal ID of this version: #1003048/1
Text MD5: 3a35a73d3b1e120428342f8238065b23
Author: stefan
Category: eleu / nl
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-04-26 17:08:42
Source code size: 1488 bytes / 57 lines
Pitched / IR pitched: No / No
Views / Downloads: 488 / 699
Referenced in: [show references]