Example #1
0
def iter_sites_w_company(directory_or_file):
    contents = iter_files_content(directory_or_file)
    for swc in imap(SITES_W_COMPANY_PARSER, contents):
        ranks = map(operator.attrgetter('rank'), swc.ranking)
        index = pandas.DatetimeIndex(map(operator.attrgetter('tstamp'),
                                       swc.ranking))
        ts = pandas.Series(ranks, index=index)
        tstamp = pandas.Timestamp(swc.tstamp)
        yield (swc.site, ts, swc.company, swc.code, tstamp)
Example #2
0
def make_fr_per_date_plot(companies, plot_file=None):
    contents = iter_files_content(companies)
    d = collections.defaultdict(list)
    min_date = datetime.date(2011, 3, 1)
    months = set()
    for c in imap(FLATTENED_PARSER, contents):
        if c.tstamp >= min_date:
            d[c.code].append(matplotlib.dates.date2num(c.tstamp))
            months.add(datetime.date(c.tstamp.year, c.tstamp.month, 1))
    
    months = sorted(months)

    right_border = months[-1] + datetime.timedelta(31)
    right_border = datetime.date(right_border.year, right_border.month, 1)
    months.append(right_border)

    fig = plt.figure(figsize=(4*1.4, 3*1.4))
    ax = fig.add_subplot(111)
    ax.hist(d.values(), label=map(str.title, d.keys()),
            bins=matplotlib.dates.date2num(months))
    ax.set_xlim(matplotlib.dates.date2num(months[0]),
                matplotlib.dates.date2num(months[-1]))
    ax.legend()
    ax.xaxis.set_major_locator(
        matplotlib.dates.MonthLocator(bymonthday=15, interval=2)
        )
    ax.xaxis.set_major_formatter(
        matplotlib.ticker.FuncFormatter(
            lambda d, _: matplotlib.dates.num2date(d).strftime('%B %Y')
            )
        )
    fig.autofmt_xdate()
    ax.set_ylabel('Number of Funding Rounds')
    ax.grid(True, axis='y')
    if plot_file:
        fig.savefig(plot_file)
    return fig