Exemplo n.º 1
0
    def registered_users_per_month(self, trans, **kwd):
        message = escape(util.restore_text(kwd.get('message', '')))
        specs = sorter('date', kwd)
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow
        _order = specs.exc_order

        q = sa.select(
            (self.select_month(
                galaxy.model.User.table.c.create_time).label('date'),
             sa.func.count(galaxy.model.User.table.c.id).label('num_users')),
            from_obj=[galaxy.model.User.table],
            group_by=self.group_by_month(
                galaxy.model.User.table.c.create_time),
            order_by=[_order])
        users = []
        for row in q.execute():
            users.append((row.date.strftime("%Y-%m"), row.num_users,
                          row.date.strftime("%B"), row.date.strftime("%Y")))
        return trans.fill_template(
            '/webapps/reports/registered_users_per_month.mako',
            order=order,
            arrow=arrow,
            sort_id=sort_id,
            users=users,
            message=message)
Exemplo n.º 2
0
    def user_per_month(self, trans, **kwd):
        params = util.Params(kwd)
        message = ''
        specs = sorter('date', kwd)
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow
        _order = specs.exc_order
        email = util.restore_text(params.get('email', ''))
        user_id = trans.security.decode_id(params.get('id', ''))

        q = sa.select(
            (self.select_month(
                model.StoredWorkflow.table.c.create_time).label('date'),
             sa.func.count(
                 model.StoredWorkflow.table.c.id).label('total_workflows')),
            whereclause=model.StoredWorkflow.table.c.user_id == user_id,
            from_obj=[model.StoredWorkflow.table],
            group_by=self.group_by_month(
                model.StoredWorkflow.table.c.create_time),
            order_by=[_order])

        all_workflows_user_month = sa.select(
            (self.select_day(
                model.StoredWorkflow.table.c.create_time).label('date'),
             model.StoredWorkflow.table.c.id),
            whereclause=model.StoredWorkflow.table.c.user_id == user_id,
            from_obj=[model.StoredWorkflow.table])

        trends = dict()
        for workflow in all_workflows_user_month.execute():
            workflow_day = int(workflow.date.strftime("%-d")) - 1
            workflow_month = int(workflow.date.strftime("%-m"))
            workflow_month_name = workflow.date.strftime("%B")
            workflow_year = workflow.date.strftime("%Y")
            key = str(workflow_month_name + workflow_year)

            try:
                trends[key][workflow_day] += 1
            except KeyError:
                workflow_year = int(workflow_year)
                wday, day_range = calendar.monthrange(workflow_year,
                                                      workflow_month)
                trends[key] = [0] * day_range
                trends[key][workflow_day] += 1

        workflows = []
        for row in q.execute():
            workflows.append(
                (row.date.strftime("%Y-%m"), row.total_workflows,
                 row.date.strftime("%B"), row.date.strftime("%Y")))
        return trans.fill_template(
            '/webapps/reports/workflows_user_per_month.mako',
            email=util.sanitize_text(email),
            order=order,
            arrow=arrow,
            sort_id=sort_id,
            trends=trends,
            workflows=workflows,
            message=message)
Exemplo n.º 3
0
    def user_disk_usage(self, trans, **kwd):
        message = escape(util.restore_text(kwd.get('message', '')))
        specs = sorter('disk_usage', kwd)
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow

        if order == "desc":
            _order = True
        else:
            _order = False

        user_cutoff = int(kwd.get('user_cutoff', 60))
        # disk_usage isn't indexed
        users = sorted(trans.sa_session.query(galaxy.model.User).all(),
                       key=operator.attrgetter(str(sort_id)),
                       reverse=_order)
        if user_cutoff:
            users = users[:user_cutoff]
        return trans.fill_template(
            '/webapps/reports/users_user_disk_usage.mako',
            order=order,
            arrow=arrow,
            sort_id=sort_id,
            users=users,
            user_cutoff=user_cutoff,
            message=message)
Exemplo n.º 4
0
 def user_per_month( self, trans, **kwd ):
     params = util.Params( kwd )
     message = ''
     specs = sorter( 'date', kwd )
     sort_id = specs.sort_id
     order = specs.order
     arrow = specs.arrow
     _order = specs.exc_order
     email = util.restore_text( params.get( 'email', '' ) )
     user_id = trans.security.decode_id( params.get( 'id', '' ) )
     q = sa.select( ( self.select_month( model.StoredWorkflow.table.c.create_time ).label( 'date' ),
                      sa.func.count( model.StoredWorkflow.table.c.id ).label( 'total_workflows' ) ),
                    whereclause=model.StoredWorkflow.table.c.user_id == user_id,
                    from_obj=[ model.StoredWorkflow.table ],
                    group_by=self.group_by_month( model.StoredWorkflow.table.c.create_time ),
                    order_by=[ _order ] )
     workflows = []
     for row in q.execute():
         workflows.append( ( row.date.strftime( "%Y-%m" ),
                             row.total_workflows,
                             row.date.strftime( "%B" ),
                             row.date.strftime( "%Y" ) ) )
     return trans.fill_template( '/webapps/reports/workflows_user_per_month.mako',
                                 email=util.sanitize_text( email ),
                                 order=order,
                                 arrow=arrow,
                                 sort_id=sort_id,
                                 workflows=workflows,
                                 message=message )
Exemplo n.º 5
0
 def per_user(self, trans, **kwd):
     message = ''
     specs = sorter('user_email', kwd)
     sort_id = specs.sort_id
     order = specs.order
     arrow = specs.arrow
     _order = specs.exc_order
     workflows = []
     q = sa.select(
         (model.User.table.c.email.label('user_email'),
          sa.func.count(
              model.StoredWorkflow.table.c.id).label('total_workflows')),
         from_obj=[
             sa.outerjoin(model.StoredWorkflow.table, model.User.table)
         ],
         group_by=['user_email'],
         order_by=[_order])
     for row in q.execute():
         workflows.append((row.user_email, row.total_workflows))
     return trans.fill_template('/webapps/reports/workflows_per_user.mako',
                                order=order,
                                arrow=arrow,
                                sort_id=sort_id,
                                workflows=workflows,
                                message=message)
Exemplo n.º 6
0
    def registered_users_per_month(self, trans, **kwd):
        message = escape(util.restore_text(kwd.get('message', '')))
        specs = sorter('date', kwd)
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow
        _order = specs.exc_order

        q = sa.select((self.select_month(galaxy.model.User.table.c.create_time).label('date'),
                       sa.func.count(galaxy.model.User.table.c.id).label('num_users')),
                      from_obj=[galaxy.model.User.table],
                      group_by=self.group_by_month(galaxy.model.User.table.c.create_time),
                      order_by=[_order])
        users = []
        for row in q.execute():
            users.append((row.date.strftime("%Y-%m"),
                          row.num_users,
                          row.date.strftime("%B"),
                          row.date.strftime("%Y")))
        return trans.fill_template('/webapps/reports/registered_users_per_month.mako',
                                   order=order,
                                   arrow=arrow,
                                   sort_id=sort_id,
                                   users=users,
                                   message=message)
Exemplo n.º 7
0
    def user_disk_usage(self, trans, **kwd):
        message = escape(util.restore_text(kwd.get("message", "")))
        specs = sorter("disk_usage", kwd)
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow

        if order == "desc":
            _order = True
        else:
            _order = False

        user_cutoff = int(kwd.get("user_cutoff", 60))
        # disk_usage isn't indexed
        users = sorted(
            trans.sa_session.query(galaxy.model.User).all(), key=operator.attrgetter(str(sort_id)), reverse=_order
        )
        if user_cutoff:
            users = users[:user_cutoff]
        return trans.fill_template(
            "/webapps/reports/users_user_disk_usage.mako",
            order=order,
            arrow=arrow,
            sort_id=sort_id,
            users=users,
            user_cutoff=user_cutoff,
            message=message,
        )
Exemplo n.º 8
0
 def user_per_month(self, trans, **kwd):
     params = util.Params(kwd)
     message = ''
     specs = sorter('date', kwd)
     sort_id = specs.sort_id
     order = specs.order
     arrow = specs.arrow
     _order = specs.exc_order
     email = util.restore_text(params.get('email', ''))
     user_id = trans.security.decode_id(params.get('id', ''))
     q = sa.select(
         (self.select_month(
             model.StoredWorkflow.table.c.create_time).label('date'),
          sa.func.count(
              model.StoredWorkflow.table.c.id).label('total_workflows')),
         whereclause=model.StoredWorkflow.table.c.user_id == user_id,
         from_obj=[model.StoredWorkflow.table],
         group_by=self.group_by_month(
             model.StoredWorkflow.table.c.create_time),
         order_by=[_order])
     workflows = []
     for row in q.execute():
         workflows.append(
             (row.date.strftime("%Y-%m"), row.total_workflows,
              row.date.strftime("%B"), row.date.strftime("%Y")))
     return trans.fill_template(
         '/webapps/reports/workflows_user_per_month.mako',
         email=util.sanitize_text(email),
         order=order,
         arrow=arrow,
         sort_id=sort_id,
         workflows=workflows,
         message=message)
Exemplo n.º 9
0
 def per_month_all(self, trans, **kwd):
     message = ''
     specs = sorter('date', kwd)
     sort_id = specs.sort_id
     order = specs.order
     arrow = specs.arrow
     _order = specs.exc_order
     q = sa.select(
         (self.select_month(
             model.StoredWorkflow.table.c.create_time).label('date'),
          sa.func.count(
              model.StoredWorkflow.table.c.id).label('total_workflows')),
         from_obj=[
             sa.outerjoin(model.StoredWorkflow.table, model.User.table)
         ],
         group_by=self.group_by_month(
             model.StoredWorkflow.table.c.create_time),
         order_by=[_order])
     workflows = []
     for row in q.execute():
         workflows.append(
             (row.date.strftime("%Y-%m"), row.total_workflows,
              row.date.strftime("%B"), row.date.strftime("%Y")))
     return trans.fill_template(
         '/webapps/reports/workflows_per_month_all.mako',
         order=order,
         arrow=arrow,
         sort_id=sort_id,
         workflows=workflows,
         message=message)
Exemplo n.º 10
0
    def user_per_month( self, trans, **kwd ):
        params = util.Params( kwd )
        message = ''
        specs = sorter( 'date', kwd )
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow
        _order = specs.exc_order
        email = util.restore_text( params.get( 'email', '' ) )
        user_id = trans.security.decode_id( params.get( 'id', '' ) )

        q = sa.select( ( self.select_month( model.StoredWorkflow.table.c.create_time ).label( 'date' ),
                         sa.func.count( model.StoredWorkflow.table.c.id ).label( 'total_workflows' ) ),
                       whereclause=model.StoredWorkflow.table.c.user_id == user_id,
                       from_obj=[ model.StoredWorkflow.table ],
                       group_by=self.group_by_month( model.StoredWorkflow.table.c.create_time ),
                       order_by=[ _order ] )

        all_workflows_user_month = sa.select( ( self.select_day( model.StoredWorkflow.table.c.create_time ).label( 'date' ),
                                               model.StoredWorkflow.table.c.id ),
                                             whereclause=model.StoredWorkflow.table.c.user_id == user_id,
                                             from_obj=[ model.StoredWorkflow.table ] )

        trends = dict()
        for workflow in all_workflows_user_month.execute():
            workflow_day = int(workflow.date.strftime("%-d")) - 1
            workflow_month = int(workflow.date.strftime("%-m"))
            workflow_month_name = workflow.date.strftime("%B")
            workflow_year = workflow.date.strftime("%Y")
            key = str( workflow_month_name + workflow_year)

            try:
                trends[key][workflow_day] += 1
            except KeyError:
                workflow_year = int(workflow_year)
                wday, day_range = calendar.monthrange(workflow_year, workflow_month)
                trends[key] = [0] * day_range
                trends[key][workflow_day] += 1

        workflows = []
        for row in q.execute():
            workflows.append( ( row.date.strftime( "%Y-%m" ),
                                row.total_workflows,
                                row.date.strftime( "%B" ),
                                row.date.strftime( "%Y" ) ) )
        return trans.fill_template( '/webapps/reports/workflows_user_per_month.mako',
                                    email=util.sanitize_text( email ),
                                    order=order,
                                    arrow=arrow,
                                    sort_id=sort_id,
                                    trends=trends,
                                    workflows=workflows,
                                    message=message )
Exemplo n.º 11
0
    def last_access_date(self, trans, **kwd):
        message = escape(util.restore_text(kwd.get('message', '')))
        specs = sorter('one', kwd)
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow

        def name_to_num(name):
            num = None

            if name is not None and name.lower() == 'zero':
                num = 0
            else:
                num = 1

            return num

        if order == "desc":
            _order = True
        else:
            _order = False

        days_not_logged_in = kwd.get('days_not_logged_in', 90)
        if not days_not_logged_in:
            days_not_logged_in = 0
        cutoff_time = datetime.utcnow() - timedelta(
            days=int(days_not_logged_in))
        users = []
        for user in trans.sa_session.query( galaxy.model.User ) \
                                    .filter( galaxy.model.User.table.c.deleted == false() ) \
                                    .order_by( galaxy.model.User.table.c.email ):
            if user.galaxy_sessions:
                last_galaxy_session = user.galaxy_sessions[0]
                if last_galaxy_session.update_time < cutoff_time:
                    users.append(
                        (user.email,
                         last_galaxy_session.update_time.strftime("%Y-%m-%d")))
            else:
                # The user has never logged in
                users.append((user.email, "never logged in"))
        users = sorted(users,
                       key=operator.itemgetter(name_to_num(sort_id)),
                       reverse=_order)
        return trans.fill_template(
            '/webapps/reports/users_last_access_date.mako',
            order=order,
            arrow=arrow,
            sort_id=sort_id,
            days_not_logged_in=days_not_logged_in,
            users=users,
            message=message)
Exemplo n.º 12
0
    def last_access_date(self, trans, **kwd):
        message = escape(util.restore_text(kwd.get("message", "")))
        specs = sorter("one", kwd)
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow

        def name_to_num(name):
            num = None

            if name != None and name.lower() == "zero":
                num = 0
            else:
                num = 1

            return num

        if order == "desc":
            _order = True
        else:
            _order = False

        days_not_logged_in = kwd.get("days_not_logged_in", 90)
        if not days_not_logged_in:
            days_not_logged_in = 0
        cutoff_time = datetime.utcnow() - timedelta(days=int(days_not_logged_in))
        users = []
        for user in (
            trans.sa_session.query(galaxy.model.User)
            .filter(galaxy.model.User.table.c.deleted == False)
            .order_by(galaxy.model.User.table.c.email)
        ):
            if user.galaxy_sessions:
                last_galaxy_session = user.galaxy_sessions[0]
                if last_galaxy_session.update_time < cutoff_time:
                    users.append((user.email, last_galaxy_session.update_time.strftime("%Y-%m-%d")))
            else:
                # The user has never logged in
                users.append((user.email, "never logged in"))
        users = sorted(users, key=operator.itemgetter(name_to_num(sort_id)), reverse=_order)
        return trans.fill_template(
            "/webapps/reports/users_last_access_date.mako",
            order=order,
            arrow=arrow,
            sort_id=sort_id,
            days_not_logged_in=days_not_logged_in,
            users=users,
            message=message,
        )
Exemplo n.º 13
0
 def per_user( self, trans, **kwd ):
     message = ''
     specs = sorter( 'user_email', kwd )
     sort_id = specs.sort_id
     order = specs.order
     arrow = specs.arrow
     _order = specs.exc_order
     workflows = []
     q = sa.select( ( model.User.table.c.email.label( 'user_email' ),
                      sa.func.count( model.StoredWorkflow.table.c.id ).label( 'total_workflows' ) ),
                    from_obj=[ sa.outerjoin( model.StoredWorkflow.table, model.User.table ) ],
                    group_by=[ 'user_email' ],
                    order_by=[ _order ] )
     for row in q.execute():
         workflows.append( ( row.user_email,
                             row.total_workflows ) )
     return trans.fill_template( '/webapps/reports/workflows_per_user.mako',
                                 order=order,
                                 arrow=arrow,
                                 sort_id=sort_id,
                                 workflows=workflows,
                                 message=message )
Exemplo n.º 14
0
 def per_month_all( self, trans, **kwd ):
     message = ''
     specs = sorter( 'date', kwd )
     sort_id = specs.sort_id
     order = specs.order
     arrow = specs.arrow
     _order = specs.exc_order
     q = sa.select( ( self.select_month( model.StoredWorkflow.table.c.create_time ).label( 'date' ), sa.func.count( model.StoredWorkflow.table.c.id ).label( 'total_workflows' ) ),
                    from_obj=[ sa.outerjoin( model.StoredWorkflow.table, model.User.table ) ],
                    group_by=self.group_by_month( model.StoredWorkflow.table.c.create_time ),
                    order_by=[ _order ] )
     workflows = []
     for row in q.execute():
         workflows.append( ( row.date.strftime( "%Y-%m" ),
                             row.total_workflows,
                             row.date.strftime( "%B" ),
                             row.date.strftime( "%Y" ) ) )
     return trans.fill_template( '/webapps/reports/workflows_per_month_all.mako',
                                 order=order,
                                 arrow=arrow,
                                 sort_id=sort_id,
                                 workflows=workflows,
                                 message=message )
Exemplo n.º 15
0
    def per_workflow(self, trans, **kwd):
        message = ''
        PageSpec = namedtuple('PageSpec',
                              ['entries', 'offset', 'page', 'pages_found'])

        specs = sorter('workflow_name', kwd)
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow
        _order = specs.exc_order
        time_period = kwd.get('spark_time')
        time_period, _time_period = get_spark_time(time_period)
        spark_limit = 30
        offset = 0
        limit = 10

        if "entries" in kwd:
            entries = int(kwd.get('entries'))
        else:
            entries = 10
        limit = entries * 4

        if "offset" in kwd:
            offset = int(kwd.get('offset'))
        else:
            offset = 0

        if "page" in kwd:
            page = int(kwd.get('page'))
        else:
            page = 1

        # In case we don't know which is the monitor user we will query for all jobs

        q = sa.select(
            (model.Workflow.table.c.id.label('workflow_id'),
             sa.func.min(model.Workflow.table.c.name).label('workflow_name'),
             sa.func.count(
                 model.WorkflowInvocation.table.c.id).label('total_runs')),
            from_obj=[model.Workflow.table, model.WorkflowInvocation.table],
            whereclause=sa.and_(model.WorkflowInvocation.table.c.workflow_id ==
                                model.Workflow.table.c.id),
            group_by=[model.Workflow.table.c.id],
            order_by=[_order],
            offset=offset,
            limit=limit)

        all_runs_per_workflow = sa.select(
            (model.Workflow.table.c.id.label('workflow_id'),
             model.Workflow.table.c.name.label('workflow_name'),
             self.select_day(
                 model.WorkflowInvocation.table.c.create_time).label('date')),
            from_obj=[model.Workflow.table, model.WorkflowInvocation.table],
            whereclause=sa.and_(model.WorkflowInvocation.table.c.workflow_id ==
                                model.Workflow.table.c.id))

        currday = date.today()
        trends = dict()
        for run in all_runs_per_workflow.execute():
            curr_tool = re.sub(r'\W+', '', str(run.workflow_id))
            try:
                day = currday - run.date
            except TypeError:
                day = currday - datetime.date(run.date)

            day = day.days
            container = floor(day / _time_period)
            container = int(container)
            try:
                if container < spark_limit:
                    trends[curr_tool][container] += 1
            except KeyError:
                trends[curr_tool] = [0] * spark_limit
                if container < spark_limit:
                    trends[curr_tool][container] += 1

        runs = []
        for row in q.execute():
            runs.append((row.workflow_name, row.total_runs, row.workflow_id))

        pages_found = ceil(len(runs) / float(entries))
        page_specs = PageSpec(entries, offset, page, pages_found)

        return trans.fill_template(
            '/webapps/reports/workflows_per_workflow.mako',
            order=order,
            arrow=arrow,
            sort_id=sort_id,
            spark_limit=spark_limit,
            time_period=time_period,
            trends=trends,
            runs=runs,
            message=message,
            page_specs=page_specs)
Exemplo n.º 16
0
    def per_month_all( self, trans, **kwd ):
        message = ''
        PageSpec = namedtuple('PageSpec', ['entries', 'offset', 'page', 'pages_found'])

        specs = sorter( 'date', kwd )
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow
        _order = specs.exc_order
        offset = 0
        limit = 10

        if "entries" in kwd:
            entries = int(kwd.get( 'entries' ))
        else:
            entries = 10
        limit = entries * 4

        if "offset" in kwd:
            offset = int(kwd.get( 'offset' ))
        else:
            offset = 0

        if "page" in kwd:
            page = int(kwd.get( 'page' ))
        else:
            page = 1

        q = sa.select( ( self.select_month( model.StoredWorkflow.table.c.create_time ).label( 'date' ),
                        sa.func.count( model.StoredWorkflow.table.c.id ).label( 'total_workflows' ) ),
                       from_obj=[ sa.outerjoin( model.StoredWorkflow.table, model.User.table ) ],
                       group_by=self.group_by_month( model.StoredWorkflow.table.c.create_time ),
                       order_by=[ _order ],
                       offset=offset,
                       limit=limit )

        all_workflows = sa.select( ( self.select_day( model.StoredWorkflow.table.c.create_time ).label( 'date' ),
                     model.StoredWorkflow.table.c.id ) )

        trends = dict()
        for workflow in all_workflows.execute():
            workflow_day = int(workflow.date.strftime("%-d")) - 1
            workflow_month = int(workflow.date.strftime("%-m"))
            workflow_month_name = workflow.date.strftime("%B")
            workflow_year = workflow.date.strftime("%Y")
            key = str( workflow_month_name + workflow_year)

            try:
                trends[key][workflow_day] += 1
            except KeyError:
                workflow_year = int(workflow_year)
                wday, day_range = calendar.monthrange(workflow_year, workflow_month)
                trends[key] = [0] * day_range
                trends[key][workflow_day] += 1

        workflows = []
        for row in q.execute():
            month_name = row.date.strftime("%B")
            year = int(row.date.strftime("%Y"))

            workflows.append( ( row.date.strftime( "%Y-%m" ),
                                row.total_workflows,
                                month_name,
                                year ) )

        pages_found = ceil(len(workflows) / float(entries))
        page_specs = PageSpec(entries, offset, page, pages_found)

        return trans.fill_template( '/webapps/reports/workflows_per_month_all.mako',
                                    order=order,
                                    arrow=arrow,
                                    sort_id=sort_id,
                                    trends=trends,
                                    workflows=workflows,
                                    message=message,
                                    page_specs=page_specs )
Exemplo n.º 17
0
    def per_user( self, trans, **kwd ):
        message = ''
        PageSpec = namedtuple('PageSpec', ['entries', 'offset', 'page', 'pages_found'])

        specs = sorter( 'user_email', kwd )
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow
        _order = specs.exc_order
        time_period = kwd.get('spark_time')
        time_period, _time_period = get_spark_time( time_period )
        spark_limit = 30
        offset = 0
        limit = 10

        if "entries" in kwd:
            entries = int(kwd.get( 'entries' ))
        else:
            entries = 10
        limit = entries * 4

        if "offset" in kwd:
            offset = int(kwd.get( 'offset' ))
        else:
            offset = 0

        if "page" in kwd:
            page = int(kwd.get( 'page' ))
        else:
            page = 1

        workflows = []
        q = sa.select( ( model.User.table.c.email.label( 'user_email' ),
                         sa.func.count( model.StoredWorkflow.table.c.id ).label( 'total_workflows' ) ),
                       from_obj=[ sa.outerjoin( model.StoredWorkflow.table, model.User.table ) ],
                       group_by=[ 'user_email' ],
                       order_by=[ _order ],
                       offset=offset,
                       limit=limit )

        all_workflows_per_user = sa.select( ( model.User.table.c.email.label( 'user_email' ),
                                             self.select_day( model.StoredWorkflow.table.c.create_time ).label('date'),
                                             model.StoredWorkflow.table.c.id ),
                                           from_obj=[ sa.outerjoin( model.StoredWorkflow.table,
                                                                   model.User.table ) ] )
        currday = datetime.today()
        trends = dict()
        for workflow in all_workflows_per_user.execute():
            curr_user = re.sub(r'\W+', '', workflow.user_email)
            try:
                day = currday - workflow.date
            except TypeError:
                day = datetime.date(currday) - datetime.date(workflow.date)

            day = day.days
            container = floor(day / _time_period)
            container = int(container)
            try:
                if container < spark_limit:
                    trends[curr_user][container] += 1
            except KeyError:
                trends[curr_user] = [0] * spark_limit
                if container < spark_limit:
                    trends[curr_user][container] += 1

        for row in q.execute():
            workflows.append( ( row.user_email,
                                row.total_workflows ) )

        pages_found = ceil(len(workflows) / float(entries))
        page_specs = PageSpec(entries, offset, page, pages_found)

        return trans.fill_template( '/webapps/reports/workflows_per_user.mako',
                                    order=order,
                                    arrow=arrow,
                                    sort_id=sort_id,
                                    spark_limit=spark_limit,
                                    trends=trends,
                                    time_period=time_period,
                                    workflows=workflows,
                                    message=message,
                                    page_specs=page_specs )
Exemplo n.º 18
0
    def per_month_all(self, trans, **kwd):
        message = ''
        PageSpec = namedtuple('PageSpec',
                              ['entries', 'offset', 'page', 'pages_found'])

        specs = sorter('date', kwd)
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow
        _order = specs.exc_order
        offset = 0
        limit = 10

        if "entries" in kwd:
            entries = int(kwd.get('entries'))
        else:
            entries = 10
        limit = entries * 4

        if "offset" in kwd:
            offset = int(kwd.get('offset'))
        else:
            offset = 0

        if "page" in kwd:
            page = int(kwd.get('page'))
        else:
            page = 1

        q = sa.select(
            (self.select_month(
                model.StoredWorkflow.table.c.create_time).label('date'),
             sa.func.count(
                 model.StoredWorkflow.table.c.id).label('total_workflows')),
            from_obj=[
                sa.outerjoin(model.StoredWorkflow.table, model.User.table)
            ],
            group_by=self.group_by_month(
                model.StoredWorkflow.table.c.create_time),
            order_by=[_order],
            offset=offset,
            limit=limit)

        all_workflows = sa.select((self.select_day(
            model.StoredWorkflow.table.c.create_time).label('date'),
                                   model.StoredWorkflow.table.c.id))

        trends = dict()
        for workflow in all_workflows.execute():
            workflow_day = int(workflow.date.strftime("%-d")) - 1
            workflow_month = int(workflow.date.strftime("%-m"))
            workflow_month_name = workflow.date.strftime("%B")
            workflow_year = workflow.date.strftime("%Y")
            key = str(workflow_month_name + workflow_year)

            try:
                trends[key][workflow_day] += 1
            except KeyError:
                workflow_year = int(workflow_year)
                wday, day_range = calendar.monthrange(workflow_year,
                                                      workflow_month)
                trends[key] = [0] * day_range
                trends[key][workflow_day] += 1

        workflows = []
        for row in q.execute():
            month_name = row.date.strftime("%B")
            year = int(row.date.strftime("%Y"))

            workflows.append((row.date.strftime("%Y-%m"), row.total_workflows,
                              month_name, year))

        pages_found = ceil(len(workflows) / float(entries))
        page_specs = PageSpec(entries, offset, page, pages_found)

        return trans.fill_template(
            '/webapps/reports/workflows_per_month_all.mako',
            order=order,
            arrow=arrow,
            sort_id=sort_id,
            trends=trends,
            workflows=workflows,
            message=message,
            page_specs=page_specs)
Exemplo n.º 19
0
    def per_workflow( self, trans, **kwd ):
        message = ''
        PageSpec = namedtuple('PageSpec', ['entries', 'offset', 'page', 'pages_found'])

        specs = sorter( 'workflow_name', kwd )
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow
        _order = specs.exc_order
        time_period = kwd.get('spark_time')
        time_period, _time_period = get_spark_time( time_period )
        spark_limit = 30
        offset = 0
        limit = 10

        if "entries" in kwd:
            entries = int(kwd.get( 'entries' ))
        else:
            entries = 10
        limit = entries * 4

        if "offset" in kwd:
            offset = int(kwd.get( 'offset' ))
        else:
            offset = 0

        if "page" in kwd:
            page = int(kwd.get( 'page' ))
        else:
            page = 1

        # In case we don't know which is the monitor user we will query for all jobs

        q = sa.select( ( model.Workflow.table.c.id.label( 'workflow_id' ),
                        sa.func.min(model.Workflow.table.c.name).label( 'workflow_name' ),
                       sa.func.count( model.WorkflowInvocation.table.c.id ).label( 'total_runs' ) ),
                      from_obj=[ model.Workflow.table,
                                model.WorkflowInvocation.table ],
                      whereclause=sa.and_( model.WorkflowInvocation.table.c.workflow_id == model.Workflow.table.c.id ),
                      group_by=[  model.Workflow.table.c.id ],
                      order_by=[ _order ],
                       offset=offset,
                       limit=limit )

        all_runs_per_workflow = sa.select( ( model.Workflow.table.c.id.label( 'workflow_id' ),
                                            model.Workflow.table.c.name.label( 'workflow_name' ),
                                            self.select_day( model.WorkflowInvocation.table.c.create_time ).label( 'date' ) ),
                                          from_obj=[ model.Workflow.table,
                                                    model.WorkflowInvocation.table ],
                                          whereclause=sa.and_( model.WorkflowInvocation.table.c.workflow_id == model.Workflow.table.c.id ) )

        currday = date.today()
        trends = dict()
        for run in all_runs_per_workflow.execute():
            curr_tool = re.sub(r'\W+', '', str(run.workflow_id))
            try:
                day = currday - run.date
            except TypeError:
                day = currday - datetime.date(run.date)

            day = day.days
            container = floor(day / _time_period)
            container = int(container)
            try:
                if container < spark_limit:
                    trends[curr_tool][container] += 1
            except KeyError:
                trends[curr_tool] = [0] * spark_limit
                if container < spark_limit:
                    trends[curr_tool][container] += 1

        runs = []
        for row in q.execute():
            runs.append( ( row.workflow_name,
                           row.total_runs,
                           row.workflow_id) )

        pages_found = ceil(len(runs) / float(entries))
        page_specs = PageSpec(entries, offset, page, pages_found)

        return trans.fill_template( '/webapps/reports/workflows_per_workflow.mako',
                                    order=order,
                                    arrow=arrow,
                                    sort_id=sort_id,
                                    spark_limit=spark_limit,
                                    time_period=time_period,
                                    trends=trends,
                                    runs=runs,
                                    message=message,
                                    page_specs=page_specs)
Exemplo n.º 20
0
    def per_user(self, trans, **kwd):
        message = ''
        PageSpec = namedtuple('PageSpec',
                              ['entries', 'offset', 'page', 'pages_found'])

        specs = sorter('user_email', kwd)
        sort_id = specs.sort_id
        order = specs.order
        arrow = specs.arrow
        _order = specs.exc_order
        time_period = kwd.get('spark_time')
        time_period, _time_period = get_spark_time(time_period)
        spark_limit = 30
        offset = 0
        limit = 10

        if "entries" in kwd:
            entries = int(kwd.get('entries'))
        else:
            entries = 10
        limit = entries * 4

        if "offset" in kwd:
            offset = int(kwd.get('offset'))
        else:
            offset = 0

        if "page" in kwd:
            page = int(kwd.get('page'))
        else:
            page = 1

        workflows = []
        q = sa.select(
            (model.User.table.c.email.label('user_email'),
             sa.func.count(
                 model.StoredWorkflow.table.c.id).label('total_workflows')),
            from_obj=[
                sa.outerjoin(model.StoredWorkflow.table, model.User.table)
            ],
            group_by=['user_email'],
            order_by=[_order],
            offset=offset,
            limit=limit)

        all_workflows_per_user = sa.select(
            (model.User.table.c.email.label('user_email'),
             self.select_day(
                 model.StoredWorkflow.table.c.create_time).label('date'),
             model.StoredWorkflow.table.c.id),
            from_obj=[
                sa.outerjoin(model.StoredWorkflow.table, model.User.table)
            ])
        currday = datetime.today()
        trends = dict()
        for workflow in all_workflows_per_user.execute():
            curr_user = re.sub(r'\W+', '', workflow.user_email)
            try:
                day = currday - workflow.date
            except TypeError:
                day = datetime.date(currday) - datetime.date(workflow.date)

            day = day.days
            container = floor(day / _time_period)
            container = int(container)
            try:
                if container < spark_limit:
                    trends[curr_user][container] += 1
            except KeyError:
                trends[curr_user] = [0] * spark_limit
                if container < spark_limit:
                    trends[curr_user][container] += 1

        for row in q.execute():
            workflows.append((row.user_email, row.total_workflows))

        pages_found = ceil(len(workflows) / float(entries))
        page_specs = PageSpec(entries, offset, page, pages_found)

        return trans.fill_template('/webapps/reports/workflows_per_user.mako',
                                   order=order,
                                   arrow=arrow,
                                   sort_id=sort_id,
                                   spark_limit=spark_limit,
                                   trends=trends,
                                   time_period=time_period,
                                   workflows=workflows,
                                   message=message,
                                   page_specs=page_specs)