Example #1
0
  /**
   * addressBook is needed only for telling whether we received or sent the message. if its null we
   * assume sent (i.e. protovis is shown above x-axis)
   */
  public static String getProtovisForDocs(
      String[] chartSpec,
      Collection<DatedDocument> docs,
      AddressBook ab,
      List<Date> intervals,
      int normalizer,
      int width,
      int height,
      boolean showTotals,
      boolean inNOut,
      String browseParams,
      String caption) {
    Pair<List<Date>, List<Date>> p = ab.splitInOutDates(docs, inNOut);
    // compute in/out dates for each group
    List<Date> inDates = p.getFirst();
    List<Date> outDates = p.getSecond();

    String info = JSPHelper.docControls("/muse/browse", "attachments", null);

    return getProtovisForDates(
            chartSpec,
            outDates,
            inDates,
            intervals,
            normalizer,
            width,
            height,
            showTotals,
            inNOut,
            browseParams)
        + ((caption == null) ? "" : protovisCaption(caption, info));
  }
Example #2
0
  /**
   * generates protovis string for group activity (in/out) chart + all names in the group.
   * normalized across all groups. optionally group members names are included.
   *
   * @return
   */
  public static List<String> getProtovisForGroups(
      AddressBook addressBook,
      List<SimilarGroup<String>> groups,
      Collection<EmailDocument> allDocs,
      int nIntervals,
      int width,
      int height,
      boolean generateNames) {
    // compute in/out dates for each group
    List<Date>[] inDates = new ArrayList[groups.size()];
    List<Date>[] outDates = new ArrayList[groups.size()];
    for (int i = 0; i < groups.size(); i++) {
      inDates[i] = new ArrayList<Date>();
      outDates[i] = new ArrayList<Date>();
    }

    for (EmailDocument ed : allDocs) {
      List<String> rawEmailAddrs = ed.getParticipatingAddrsExcept(addressBook.getOwnAddrs());
      List<String> canonicalEmailAddrs = addressBook.convertToCanonicalAddrs(rawEmailAddrs);
      Collections.sort(canonicalEmailAddrs);
      Group<String> emailGroup = new Group<String>(canonicalEmailAddrs);
      int x = Group.bestFit(groups, emailGroup);
      if (x != -1) {
        int sentOrReceived = ed.sentOrReceived(addressBook);
        if ((sentOrReceived & EmailDocument.RECEIVED_MASK) != 0) inDates[x].add(ed.date);
        if ((sentOrReceived & EmailDocument.SENT_MASK) != 0) outDates[x].add(ed.date);
      }
    }

    // find normalizing max
    int max = Integer.MIN_VALUE;
    Pair<Date, Date> p = EmailUtils.getFirstLast(allDocs);
    Date globalStart = p.getFirst();
    Date globalEnd = p.getSecond();
    List<Date> intervals = CalendarUtil.divideIntoIntervals(globalStart, globalEnd, nIntervals);

    for (int i = 0; i < groups.size(); i++) {
      int x = normalizingMax(inDates[i], outDates[i], intervals, /* inNOut */ true);
      if (x >= max) max = x;
    }

    // generate protovis
    List<String> result = new ArrayList<String>();
    for (int i = 0; i < groups.size(); i++) {
      int[] inGram = CalendarUtil.computeHistogram(inDates[i], intervals);
      //	double[] normalizedInGram = Util.normalizeHistogramToBase(inGram, max);
      int[] outGram = CalendarUtil.computeHistogram(outDates[i], intervals);
      //	double[] normalizedOutGram = Util.normalizeHistogramToBase(outGram, max);
      String url = JSPHelper.getURLForGroupMessages(i);
      StringBuilder sb = new StringBuilder();
      sb.append(
          getProtoVizBox(
              null,
              outDates[i].size(),
              inDates[i].size(),
              outGram,
              inGram,
              max,
              width,
              height,
              true,
              true,
              intervals.get(0),
              intervals.get(intervals.size() - 1),
              true /*focusOnly*/,
              "'" + url + "'"));

      // add names to the mark if needed
      if (generateNames) {
        sb.append("<br/><span style=\"font-size:small\">");
        for (String str : groups.get(i).elements)
          sb.append(Util.strippedEmailAddress(str) + "<br/>");

        sb.append(
            "<a href=\""
                + url
                + "\" target=\"_new\"><img title=\"Messages\" src=\"/muse/images/email.jpg\" width=\"25\"/>"
                + "</a>");

        sb.append("</span>");
      }
      result.add(sb.toString());
    }

    return result;
  }