Ejemplo n.º 1
0
    def daily_unique_users(self):
        """

        """
        fig = plt.figure(figsize=[20, 6])
        ax1 = fig.add_subplot(1, 1, 1)

        sgcolors = ['Silver', 'Crimson']
        sglabels = ['$Non-Certified$', '$Certified$']

        for sg in [0, 1]:
            users = self.person[self.person.certified ==
                                sg].username.dropna().unique()
            daily = pd.crosstab(
                self.potime[self.potime.username.isin(users)].username,
                self.potime.date)
            daily = daily[daily > 0].count().sort_index()
            daily.index = [np.datetime64(d) for d in daily.index]
            daily.plot(ax=ax1,
                       style="-o",
                       ms=6,
                       lw=2,
                       color=sgcolors[sg],
                       rot=0,
                       label=sglabels[sg])

        xmin = (self.cinfo['start_date'] -
                np.timedelta64(2, 'W')).item().date()
        xmax = (self.cinfo['end_date'] + np.timedelta64(4, 'W')).item().date()

        ax1.set_xlim(xmin, xmax)
        ax1 = xff.timeseries_plot_formatter(ax1, interval=1)
        ax1.legend(loc=1, prop={'size': 24}, frameon=False)

        ylim1 = ax1.get_ylim()[1]
        ax1.vlines([
            self.cinfo.start_date.item().date(),
            self.cinfo.end_date.item().date()
        ],
                   0,
                   ylim1,
                   colors='Gray',
                   lw=1.5,
                   linestyles='--')
        ax1.set_ylim(0, ylim1)

        figsavename = self.figpath + 'daily_unique_users_' + self.nickname.replace(
            '.', '_')
        xff.texify(fig,
                   ax1,
                   ylabel='Unique Users',
                   tic_size=20,
                   label_size=24,
                   datefontsize=20,
                   title=self.nickname,
                   figsavename=figsavename + '.png')

        return None
Ejemplo n.º 2
0
    def enrollment_plots(self,**kwargs):
        """
        Plots using the start_date from enrollment_df.

        Parameters
        ----------
        None
        
        Output
        ------
        Figures and respective formats.

        Returns
        -------
        None
        """
        
        ### For JSON Data Output
        jsondata = []
        
        def date2epoch(x):
            return int( (datetime.combine(x, datetime.min.time()) - datetime(1970,1,1)).total_seconds()*1000 )

        for C in self.enrollment_df.columns:
            fig = plt.figure(figsize=(12,6))
            ax1 = fig.add_subplot(1,1,1)
            self.enrollment_df[C].plot(ax=ax1,color=xff.colors['institute'],rot=0,lw=3,label=self.nickname)
            
            ax1 = xff.timeseries_plot_formatter(ax1)
            ax1.set_yticklabels([r'${0}$'.format("%d" % (y)) for y in ax1.get_yticks()])
            #ax1.legend(loc=4,prop={'size':22},frameon=False,scatterpoints=1)
            
            ### Generalized Plotting functions
            figsavename = self.figpath+C.replace(' ','_')+'_'+self.nickname.replace('.','_')
            print figsavename
            xff.texify(fig,ax1,
                          ylabel=C,
                          #title=self._xdata.course_id+' - All Registrants',
                          datefontsize=20,
                          gridb='y',
                          figsavename=figsavename+'.png')

            ### Append JSON Data
            record = collections.OrderedDict()
            record['key'] = C
            if C == 'Enroll Count':
                record['bar'] = 'true'
            record['values'] = [[date2epoch(d),int(v)] for d,v in self.enrollment_df[C].iteritems()]
            jsondata.append(record)
                        
        print "JSON dump currently commented out."
        # str_jsondata = 'var data = '+json.dumps(jsondata)
        # with open(self.figpath+'enrollment.json', 'w') as outfile:
        #     outfile.write(str_jsondata)

        return None#self.enrollment_df
Ejemplo n.º 3
0
    def daily_activity(self):
        """
        Creates daily timeseries of discussion activity (only posts/comments/votes from forum data).
       
        
        Parameters (generated during class initialization)
        ----------
        None

        Output
        ------
        Saves figures to specified directories.

        Returns
        -------
        None
        """

        fig = plt.figure(figsize=[20,6])
        ax1 = fig.add_subplot(1,1,1)

        ### List of Certified Participants
        certs = self.pc_plus[self.pc_plus.certified==1].user_id.unique()
        certs = [str(u) for u in certs]

        ### Non-Certified
        post_act = self.forum[ (self.forum.created_at.notnull()) & (self.forum.author_id.isin(certs)==False) ].created_at.apply(lambda x: x.date()).value_counts().sort_index()
        post_act.plot(ax=ax1,style="-o",ms=6,lw=2,color=xff.colors['neutral'],label='$Non-Certified$')
        #(post_act.cumsum()/10).plot(ax=ax1,style="-",ms=3,color='Orange')
        
        ### Certified
        post_act = self.forum[ (self.forum.created_at.notnull()) & (self.forum.author_id.isin(certs)) ].created_at.apply(lambda x: x.date()).value_counts().sort_index()
        post_act.plot(ax=ax1,style="-o",ms=6,lw=2,color=xff.colors['institute'],label='$Certified$')

        xmin = (self.cinfo['start_date'] - np.timedelta64(2,'W')).item().date()
        xmax = (self.cinfo['end_date'] + np.timedelta64(4,'W')).item().date()

        ax1.set_xlim(xmin,xmax)

        ylim1 = ax1.get_ylim()[1]
        ax1.vlines([self.cinfo.start_date.item().date(),self.cinfo.end_date.item().date()], 0, ylim1, colors='Gray', lw=1.5, linestyles='--')
        ax1.set_ylim(0,ylim1)

        ax1 = xff.timeseries_plot_formatter(ax1,interval=1)
        ax1.legend(loc=1,prop={'size':24},frameon=False)

        figsavename = self.figpath+'discussion_activity_'+self.nickname.replace('.','_')
        xff.texify(fig,ax1,ylabel='Forum Text Submissions',
                   tic_size=20,label_size=24,
                   datefontsize=20,
                   title=self.nickname,
                   figsavename=figsavename+'.png')

        return None
Ejemplo n.º 4
0
    def daily_unique_users(self):
        """

        """
        fig = plt.figure(figsize=[20,6])
        ax1 = fig.add_subplot(1,1,1)

        sgcolors = ['Silver','Crimson']
        sglabels = ['$Non-Certified$','$Certified$']

        for sg in [0,1]:
            users = self.person[self.person.certified==sg].username.dropna().unique()
            daily = pd.crosstab(self.potime[self.potime.username.isin(users)].username,self.potime.date)
            daily = daily[daily>0].count().sort_index()
            daily.index = [np.datetime64(d) for d in daily.index]
            daily.plot(ax=ax1,style="-o",ms=6,lw=2,color=sgcolors[sg],rot=0,label=sglabels[sg])
        
        xmin = (self.cinfo['start_date'] - np.timedelta64(2,'W')).item().date()
        xmax = (self.cinfo['end_date'] + np.timedelta64(4,'W')).item().date()

        ax1.set_xlim(xmin,xmax)
        ax1 = xff.timeseries_plot_formatter(ax1, interval=1)
        ax1.legend(loc=1,prop={'size':24},frameon=False)

        ylim1 = ax1.get_ylim()[1]
        ax1.vlines([self.cinfo.start_date.item().date(),self.cinfo.end_date.item().date()], 0, ylim1, colors='Gray', lw=1.5, linestyles='--')
        ax1.set_ylim(0,ylim1)

        figsavename = self.figpath+'daily_unique_users_'+self.nickname.replace('.','_')
        xff.texify(fig,ax1,ylabel='Unique Users',
                   tic_size=20,label_size=24,
                   datefontsize=20,
                   title=self.nickname,
                   figsavename=figsavename+'.png')


        return None
Ejemplo n.º 5
0
    def last_day_plots_dual(self,**kwargs):
        """
        Combining enroll count and cumulative enrollment.

        Parameters
        ----------
        None
        
        Output
        ------
        Figures and respective formats.

        Returns
        -------
        None
        """
        
        fig = plt.figure(figsize=(12,6))
        ax1 = fig.add_subplot(1,1,1)

        fsize = 24

        self.lastact_df['Last Activity Count'].plot(ax=ax1,lw=3,color='Silver',label='left axis')
        ax1 = xff.timeseries_plot_formatter(ax1)
        ax1.set_yticklabels([r'${0}$'.format("%d" % (y)) for y in ax1.get_yticks()])
        ax1.set_ylabel('$Last Activity Count$'.replace(' ','\ '),
                       fontdict={'fontsize': fsize,'style': 'oblique'})

        ax1.grid(which='both', b=False, axis='x')


        ax2 = ax1.twinx()
        self.lastact_df['Last Activity Survival'].plot(ax=ax2,lw=3,color='Crimson',label='right axis')
        ax2 = xff.timeseries_plot_formatter(ax2)
        ax2.set_yticklabels([r'${0}$'.format("%d" % (y)) for y in ax2.get_yticks()])
        ax2.set_ylabel('$Last Activity Survival$'.replace(' ','\ '),
                       fontdict={'fontsize': fsize,'style': 'oblique'})

        ax2.grid(which='both', b=False, axis='x')

        ylim2 = ax2.get_ylim()[1]
        ax2.vlines([self.cinfo['start_date'],self.cinfo['end_date']], 0, ylim2, colors='Gray', lw=1.5, linestyles='--')
        ax2.set_ylim(0,ylim2)

        #Tic Labels
        datefontsize = 20
        tic_size = fsize
        for ax in [ax1,ax2]:
            for tics in ax.get_xticklabels() + ax.get_yticklabels():
                if datefontsize != None and tics in ax.get_xticklabels():
                    tics.set_fontsize(datefontsize)
                else:
                    tics.set_fontsize(tic_size)
            
                tics.set_fontname('serif')
                tics.set_style('oblique')

        figsavename = self.figpath+'last_day_dual_'+self.nickname.replace('.','_')+'.png'
        print figsavename 
        if figsavename != None:
            dpiset = 300
            #fig.savefig('OUTPUT_Figures/%s/%s_%s.png' %(mens2_cid,figsavename,nickname), bbox_inches='tight', dpi=dpiset)
            fig.savefig('%s' % (figsavename), bbox_inches='tight', dpi=dpiset)

        return None#self.enrollment_df
Ejemplo n.º 6
0
    def daily_activity(self):
        """
        Creates daily timeseries of discussion activity (only posts/comments/votes from forum data).
       
        
        Parameters (generated during class initialization)
        ----------
        None

        Output
        ------
        Saves figures to specified directories.

        Returns
        -------
        None
        """

        fig = plt.figure(figsize=[20, 6])
        ax1 = fig.add_subplot(1, 1, 1)

        ### List of Certified Participants
        certs = self.pc_plus[self.pc_plus.certified == 1].user_id.unique()
        certs = [str(u) for u in certs]

        ### Non-Certified
        post_act = self.forum[(self.forum.created_at.notnull()) & (
            self.forum.author_id.isin(certs) == False)].created_at.apply(
                lambda x: x.date()).value_counts().sort_index()
        post_act.plot(ax=ax1,
                      style="-o",
                      ms=6,
                      lw=2,
                      color=xff.colors['neutral'],
                      label='$Non-Certified$')
        #(post_act.cumsum()/10).plot(ax=ax1,style="-",ms=3,color='Orange')

        ### Certified
        post_act = self.forum[(self.forum.created_at.notnull()) & (
            self.forum.author_id.isin(certs))].created_at.apply(
                lambda x: x.date()).value_counts().sort_index()
        post_act.plot(ax=ax1,
                      style="-o",
                      ms=6,
                      lw=2,
                      color=xff.colors['institute'],
                      label='$Certified$')

        xmin = (self.cinfo['start_date'] -
                np.timedelta64(2, 'W')).item().date()
        xmax = (self.cinfo['end_date'] + np.timedelta64(4, 'W')).item().date()

        ax1.set_xlim(xmin, xmax)

        ylim1 = ax1.get_ylim()[1]
        ax1.vlines([
            self.cinfo.start_date.item().date(),
            self.cinfo.end_date.item().date()
        ],
                   0,
                   ylim1,
                   colors='Gray',
                   lw=1.5,
                   linestyles='--')
        ax1.set_ylim(0, ylim1)

        ax1 = xff.timeseries_plot_formatter(ax1, interval=1)
        ax1.legend(loc=1, prop={'size': 24}, frameon=False)

        figsavename = self.figpath + 'discussion_activity_' + self.nickname.replace(
            '.', '_')
        xff.texify(fig,
                   ax1,
                   ylabel='Forum Text Submissions',
                   tic_size=20,
                   label_size=24,
                   datefontsize=20,
                   title=self.nickname,
                   figsavename=figsavename + '.png')

        return None
Ejemplo n.º 7
0
    def last_day_plots_dual(self, **kwargs):
        """
        Combining enroll count and cumulative enrollment.

        Parameters
        ----------
        None
        
        Output
        ------
        Figures and respective formats.

        Returns
        -------
        None
        """

        fig = plt.figure(figsize=(12, 6))
        ax1 = fig.add_subplot(1, 1, 1)

        fsize = 24

        self.lastact_df['Last Activity Count'].plot(ax=ax1,
                                                    lw=3,
                                                    color='Silver',
                                                    label='left axis')
        ax1 = xff.timeseries_plot_formatter(ax1)
        ax1.set_yticklabels(
            [r'${0}$'.format("%d" % (y)) for y in ax1.get_yticks()])
        ax1.set_ylabel('$Last Activity Count$'.replace(' ', '\ '),
                       fontdict={
                           'fontsize': fsize,
                           'style': 'oblique'
                       })

        ax1.grid(which='both', b=False, axis='x')

        ax2 = ax1.twinx()
        self.lastact_df['Last Activity Survival'].plot(ax=ax2,
                                                       lw=3,
                                                       color='Crimson',
                                                       label='right axis')
        ax2 = xff.timeseries_plot_formatter(ax2)
        ax2.set_yticklabels(
            [r'${0}$'.format("%d" % (y)) for y in ax2.get_yticks()])
        ax2.set_ylabel('$Last Activity Survival$'.replace(' ', '\ '),
                       fontdict={
                           'fontsize': fsize,
                           'style': 'oblique'
                       })

        ax2.grid(which='both', b=False, axis='x')

        ylim2 = ax2.get_ylim()[1]
        ax2.vlines([self.cinfo['start_date'], self.cinfo['end_date']],
                   0,
                   ylim2,
                   colors='Gray',
                   lw=1.5,
                   linestyles='--')
        ax2.set_ylim(0, ylim2)

        #Tic Labels
        datefontsize = 20
        tic_size = fsize
        for ax in [ax1, ax2]:
            for tics in ax.get_xticklabels() + ax.get_yticklabels():
                if datefontsize != None and tics in ax.get_xticklabels():
                    tics.set_fontsize(datefontsize)
                else:
                    tics.set_fontsize(tic_size)

                tics.set_fontname('serif')
                tics.set_style('oblique')

        figsavename = self.figpath + 'last_day_dual_' + self.nickname.replace(
            '.', '_') + '.png'
        print figsavename
        if figsavename != None:
            dpiset = 300
            #fig.savefig('OUTPUT_Figures/%s/%s_%s.png' %(mens2_cid,figsavename,nickname), bbox_inches='tight', dpi=dpiset)
            fig.savefig('%s' % (figsavename), bbox_inches='tight', dpi=dpiset)

        return None  #self.enrollment_df
Ejemplo n.º 8
0
    def last_day_plots(self, **kwargs):
        """
        Plots using the last_event date from enrollment_df.

        Parameters
        ----------
        None
        
        Output
        ------
        Figures and respective formats.

        Returns
        -------
        None
        """

        col = self.lastact_df.columns[0]
        tmp = self.lastact_df[col][self.lastact_df[col] > 100]
        mindate = tmp.index[0] - timedelta(days=21)
        maxdate = tmp.index[-1] + timedelta(days=21)
        #print mindate,maxdate

        ### For JSON Data Output
        jsondata = []

        def date2epoch(x):
            return int((datetime.combine(x, datetime.min.time()) -
                        datetime(1970, 1, 1)).total_seconds() * 1000)

        for C in self.lastact_df.columns:
            #print C,self.lastact_df[C].idxmin(),self.lastact_df[C].idxmax()
            fig = plt.figure(figsize=(12, 6))
            ax1 = fig.add_subplot(1, 1, 1)
            self.lastact_df[C].plot(ax=ax1,
                                    color=xff.colors['institute'],
                                    rot=0,
                                    lw=3,
                                    label=self.nickname)

            ax1.set_xlim(mindate, maxdate)
            ax1 = xff.timeseries_plot_formatter(ax1)
            ax1.set_yticklabels(
                [r'${0}$'.format("%d" % (y)) for y in ax1.get_yticks()])
            #ax1.legend(loc=4,prop={'size':22},frameon=False,scatterpoints=1)

            ### Generalized Plotting functions
            figsavename = self.figpath + C.replace(
                ' ', '_') + '_' + self.nickname.replace('.', '_')
            print figsavename
            xff.texify(
                fig,
                ax1,
                ylabel=C,
                #title=self._xdata.course_id+' - All Registrants',
                datefontsize=20,
                gridb='y',
                figsavename=figsavename + '.png')

            ### Append JSON Data
            record = collections.OrderedDict()
            record['key'] = C
            if C == 'Last Activity Count':
                record['bar'] = 'true'
            record['values'] = [[date2epoch(d), int(v)]
                                for d, v in self.lastact_df[C].iteritems()]
            jsondata.append(record)

        print "JSON dump currently commented out."
        # str_jsondata = 'var data = '+json.dumps(jsondata)
        # with open(self.figpath+'lastday.json', 'w') as outfile:
        #     outfile.write(str_jsondata)

        return None