Ejemplo n.º 1
0
def juxta_basicstats(u):
    ns = u.note_owner
    nvals = u.note_owner.values()
    stats = (
        ("N", ns.count()),  ## number of notes
        ("keep/del", "%s/%s" % (ns.filter(deleted=0).count(), ns.filter(deleted=1).count())),
        ("s:", exporter.makedate_usec(min([float(x["created"]) for x in nvals]))),
        ("l:", exporter.makedate_usec(max([float(x["edited"]) for x in nvals] + [float(x["created"]) for x in nvals]))),
        ("|words|", mean([ca.note_words(nvs)[1] for nvs in nvals])),
        ("|chars|", mean([len(nvs["contents"].strip()) for nvs in nvals])),
        ("|urls%|", sum([1 for nvs in nvals if ca.note_urls(nvs)[1] > 0]) / (1.0 * ns.count()) * 100),
        ("|#vers|", mean([float(nvs["version"]) for nvs in nvals])),
    )
    return '<span class="userstats">%s</span>' % "; ".join(
        ['%s: <span class="val">%s</span>' % (k, v) for k, v in stats]
    )
Ejemplo n.º 2
0
def plot_note_words_hist_modfilename(notes,
                                     filename="num_words",
                                     width=1024,
                                     height=800,
                                     soft_max=300):
    user = notes[0].owner
    nwords = [
        ca.note_words(n2vals(x))['note_words']
        for x in notes.values("contents")
    ]

    nchars_ = [len(x["contents"].strip()) for x in notes.values("contents")]
    nchars = [x for x in nchars_ if x < soft_max]

    r.png(file='/dev/null', width=width, height=height)
    breaks = [x for x in xrange(soft_max)]
    nchars = r.hist(c(nchars), breaks=c(breaks))[1]
    r('dev.off()')

    r.png(file=make_filename(filename), width=width, height=height)
    nwords_ = [x for x in nwords]
    nwords = [x for x in nwords if x < soft_max]

    hh = r.hist(c(nwords),
                breaks=c(breaks),
                labels=c(breaks),
                freq=True,
                xlab='',
                ylab='',
                main='length of notes (in words) %s (%d)' %
                (user.email, len(notes)))
    # print len(breaks)," ", len(nchars)
    print nchars
    r.lines(c(breaks[:-1]), nchars, col='green')
    r.text(
        r.c(3.0 / 4.0 * soft_max),
        r.c(3.0 / 4.8 * max(hh[1]) + 0.1 * max(hh[1])),
        "notes min-median-mode-max: %f %f %f %f" %
        (min(nwords_), median(nwords_), ca.mode(nwords_), max(nwords_)))
    r.text(
        r.c(3.0 / 4.0 * soft_max), r.c(3.0 / 4.8 * max(hh[1])),
        "char min-median-mode-max: %f %f %f %f" %
        (min(nchars_), median(nchars_), ca.mode(nchars_), max(nchars_)))

    r('dev.off()')
    return hh
Ejemplo n.º 3
0
def juxta_basicstats(u):
    ns = u.note_owner
    nvals = u.note_owner.values()
    stats = (
        ("N", ns.count()),  ## number of notes
        ("keep/del", "%s/%s" %
         (ns.filter(deleted=0).count(), ns.filter(deleted=1).count())),
        ("s:", exporter.makedate_usec(min([float(x['created'])
                                           for x in nvals]))),
        ("l:",
         exporter.makedate_usec(
             max([float(x['edited'])
                  for x in nvals] + [float(x['created']) for x in nvals]))),
        ("|words|", mean([ca.note_words(nvs)[1] for nvs in nvals])),
        ("|chars|", mean([len(nvs['contents'].strip()) for nvs in nvals])),
        ("|urls%|", sum([1 for nvs in nvals if ca.note_urls(nvs)[1] > 0]) /
         (1.0 * ns.count()) * 100),
        ("|#vers|", mean([float(nvs['version']) for nvs in nvals])))
    return '<span class="userstats">%s</span>' % "; ".join(
        ['%s: <span class="val">%s</span>' % (k, v) for k, v in stats])
Ejemplo n.º 4
0
def plot_note_words_hist_modfilename(notes, filename="num_words", width=1024, height=800, soft_max=300):
    user = notes[0].owner
    nwords = [ca.note_words(n2vals(x))["note_words"] for x in notes.values("contents")]

    nchars_ = [len(x["contents"].strip()) for x in notes.values("contents")]
    nchars = [x for x in nchars_ if x < soft_max]

    r.png(file="/dev/null", width=width, height=height)
    breaks = [x for x in xrange(soft_max)]
    nchars = r.hist(c(nchars), breaks=c(breaks))[1]
    r("dev.off()")

    r.png(file=make_filename(filename), width=width, height=height)
    nwords_ = [x for x in nwords]
    nwords = [x for x in nwords if x < soft_max]

    hh = r.hist(
        c(nwords),
        breaks=c(breaks),
        labels=c(breaks),
        freq=True,
        xlab="",
        ylab="",
        main="length of notes (in words) %s (%d)" % (user.email, len(notes)),
    )
    # print len(breaks)," ", len(nchars)
    print nchars
    r.lines(c(breaks[:-1]), nchars, col="green")
    r.text(
        r.c(3.0 / 4.0 * soft_max),
        r.c(3.0 / 4.8 * max(hh[1]) + 0.1 * max(hh[1])),
        "notes min-median-mode-max: %f %f %f %f" % (min(nwords_), median(nwords_), ca.mode(nwords_), max(nwords_)),
    )
    r.text(
        r.c(3.0 / 4.0 * soft_max),
        r.c(3.0 / 4.8 * max(hh[1])),
        "char min-median-mode-max: %f %f %f %f" % (min(nchars_), median(nchars_), ca.mode(nchars_), max(nchars_)),
    )

    r("dev.off()")
    return hh
Ejemplo n.º 5
0
            (jid, (when - float(n.created)))
            for jid, when in max_deletes.iteritems()
        ])
    return njidtodel[n.owner.email].get(n.jid, None)


juxtapose_n_props = lambda i, n_created, n_text, n: "".join([
    ("<td>%s</td>" % repr(x)) for x in [
        i,
        int(n.jid),
        exporter.makedate_usec(float(n_created)),
        (time_till_deletion(n) / (24 * 60 * 60 * 1000)
         if time_till_deletion(n) is not None else "-?-")
        if n.deleted else "NOT DELETED",
        len(n_text) if n_text is not None else 0,
        ca.note_words(text2vals(n_text))[1] if n_text is not None else 0,
        ca.note_lines(text2vals(n_text))[1] if n_text is not None else 0,
        ca.note_changed_edits(n2vals(n))[1],
        htmlesc(n_text)
    ]
])

njidtosave = {}


def juxtapose_note(i, n):
    ## cache all the note-saves, build chronological revision array { user.id : { noteid: (when, contents), (when, contents) , ... } }
    global njidtosave
    if n.owner.email not in njidtosave:
        person = {}
        for when, noteid, contents, action in ActivityLog.objects.filter(
Ejemplo n.º 6
0
        njidtodel[n.owner.email] = dict([(jid, (when - float(n.created))) for jid, when in max_deletes.iteritems()])
    return njidtodel[n.owner.email].get(n.jid, None)


juxtapose_n_props = lambda i, n_created, n_text, n: "".join(
    [
        ("<td>%s</td>" % repr(x))
        for x in [
            i,
            int(n.jid),
            exporter.makedate_usec(float(n_created)),
            (time_till_deletion(n) / (24 * 60 * 60 * 1000) if time_till_deletion(n) is not None else "-?-")
            if n.deleted
            else "NOT DELETED",
            len(n_text) if n_text is not None else 0,
            ca.note_words(text2vals(n_text))[1] if n_text is not None else 0,
            ca.note_lines(text2vals(n_text))[1] if n_text is not None else 0,
            ca.note_changed_edits(n2vals(n))[1],
            htmlesc(n_text),
        ]
    ]
)

njidtosave = {}


def juxtapose_note(i, n):
    ## cache all the note-saves, build chronological revision array { user.id : { noteid: (when, contents), (when, contents) , ... } }
    global njidtosave
    if n.owner.email not in njidtosave:
        person = {}