Skip to content

Commit

Permalink
Add the oldest changests by affiliation study
Browse files Browse the repository at this point in the history
This allows to have the first 10 oldest changesets ordered by
affiliation. The difference with the rest of the studies is that
this one includes affiliation information.
  • Loading branch information
dicortazar committed Feb 25, 2016
1 parent cdfdbdf commit 9568489
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion vizgrimoire/analysis/gerrit_studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# Daniel Izquierdo Cortazar <dizquierdo@bitergia.com>

from sets import Set
import pandas

from vizgrimoire.analysis.analyses import Analyses

Expand Down Expand Up @@ -99,7 +100,7 @@ class MostActiveChangesetsWaiting4Reviewer(Analyses):
id = "list_most_active_changesets_waiting4reviewer"
name = "List of the most active changesets waiting for a reviewer action"
desc = "List of the most active changesets waiting for a reviewer action"

def create_report(self, data_source, destdir):
if data_source != SCR: return
self.result(data_source, destdir)
Expand Down Expand Up @@ -209,6 +210,80 @@ def result(self, data_source = None, destdir = None):

return data


class OldestChangesetsByAffiliation(Analyses):

""" This class provides the oldest changesets without activity
ordered by affiliation and by the last upload.
"""

id = "oldest_changesets_by_affiliation"
name = "The oldest changesets by affiliation"
desc = "The oldest changesets by affiliation and by the last upload"

def create_report(self, data_source, destdir):
if data_source != SCR: return
self.result(data_source, destdir)

def result(self, data_source = None, destdir = None):

fields = Set([])
tables = Set([])
filters = Set([])

fields.add("tr.url as project_name")
fields.add("pro.name as author_name")
fields.add("org.name as organization")
fields.add("i.issue as gerrit_issue_id")
fields.add("i.summary as summary")
fields.add("i.submitted_on as first_upload")
fields.add("t.last_upload as last_upload")

tables.add("issues i")
tables.add("trackers tr")
tables.add("people_uidentities puid")
tables.add(self.db.identities_db + ".enrollments enr")
tables.add(self.db.identities_db + ".organizations org")
tables.add(self.db.identities_db + ".profiles pro")
tables.add("(select issue_id, max(changed_on) as last_upload from changes where field='status' and new_value='UPLOADED' group by issue_id) t")

filters.add("t.issue_id = i.id")
filters.add("i.id not in (select distinct(issue_id) from changes where field='Code-Review')")
filters.add("i.status<>'Abandoned'")
filters.add("i.status<>'Merged'")
filters.add("tr.id=i.tracker_id")
filters.add("i.submitted_by=puid.people_id")
filters.add("puid.uuid = enr.uuid")
filters.add("i.submitted_on >= enr.start")
filters.add("i.submitted_on < enr.end")
filters.add("enr.organization_id = org.id")
filters.add("puid.uuid = pro.uuid")
filters.add("i.summary not like '%WIP%'")

query = " select " + self.db._get_fields_query(fields)
query = query + " from " + self.db._get_tables_query(tables)
query = query + " where " + self.db._get_filters_query(filters)
query = query + " order by org.name, t.last_upload"

data = self.db.ExecuteQuery(query)

# TODO: Hardcoded creation of file
createJSON(data, destdir + "/scr-oldest_changesets_by_affiliation.json")

#Filtering the data to have only 10 entries per organization at most
data_df = pandas.DataFrame(data, columns=["gerrit_issue_id", "project_name", "organization", "last_upload", "first_upload", "summary", "author_name"])
organizations = pandas.unique(data_df.organization)
dataframes = []
for organization in organizations:
dataframes.append(data_df[data_df["organization"]==organization][1:10])

filter_orgs = pandas.concat(dataframes)
filter_orgs = filter_orgs.to_dict(orient="list")
createJSON(filter_orgs, destdir + "/scr-oldest_changesets_by_affiliation.json")

return filter_orgs


if __name__ == '__main__':

filters = MetricFilters("month", "'2011-04-01'", "'2016-01-01'")
Expand All @@ -217,6 +292,9 @@ def result(self, data_source = None, destdir = None):
oldest_changesets = OldestChangesets(dbcon, filters)
print oldest_changesets.result()

oldest_changesets = OldestChangesetsByAffiliation(dbcon, filters)
oldest_changesets.result(destdir = "./")

most_active = MostActiveChangesetsWaiting4Reviewer(dbcon, filters)
most_active.result()

0 comments on commit 9568489

Please sign in to comment.