Ejemplo n.º 1
0
  public static String getProtovisForDates(
      String[] chartSpec,
      List<Date> outDates,
      List<Date> inDates,
      List<Date> intervals,
      int normalizeCount,
      int width,
      int height,
      boolean showTotals,
      boolean inNOut,
      String browseParams) {
    int[] inGram = CalendarUtil.computeHistogram(inDates, intervals);
    //	double[] normalizedInGram = Util.normalizeHistogramToBase(inGram, normalizeCount);
    int[] outGram = CalendarUtil.computeHistogram(outDates, intervals);
    //	double[] normalizedOutGram = Util.normalizeHistogramToBase(outGram, normalizeCount);

    return getProtoVizBox(
        chartSpec,
        outDates.size(),
        inDates.size(),
        outGram,
        inGram,
        normalizeCount,
        width,
        height,
        showTotals,
        inNOut,
        intervals.get(0),
        intervals.get(intervals.size() - 1),
        false /*focusOnly*/,
        browseParams);
  }
Ejemplo n.º 2
0
  public static int findMaxInOrOutInAnInterval(
      List<Date> inDates, List<Date> outDates, List<Date> intervals) {
    int[] histogram = CalendarUtil.computeHistogram(inDates, intervals);
    int max = Integer.MIN_VALUE;
    for (int x : histogram) if (x > max) max = x;

    histogram = CalendarUtil.computeHistogram(outDates, intervals);
    for (int x : histogram) if (x > max) max = x;
    return max;
  }
Ejemplo n.º 3
0
 private static int findNormalizingMax(List<Date> dates, List<Date> intervals) {
   if (dates == null) return Integer.MIN_VALUE;
   int[] histogram = CalendarUtil.computeHistogram(dates, intervals);
   int max = Integer.MIN_VALUE;
   for (int x : histogram) if (x > max) max = x;
   return max;
 }
Ejemplo n.º 4
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;
  }