|
a/OSSEval/OSProject/models.py |
|
b/OSSEval/OSProject/models.py |
|
|
1 |
from datetime import date, datetime
|
|
|
2 |
from urlparse import urlparse
|
|
|
3 |
|
1 |
from django.db import models
|
4 |
from django.db import models
|
2 |
#from views import search_html, instance_list_html
|
5 |
|
3 |
from ohloh import OhlohProxy
|
6 |
from ohloh import OhlohProxy
|
4 |
from flossmole import FSF, FC, GC, GH
|
7 |
from flossmole import FSF, FC, GC, GH
|
5 |
from utils import Forges
|
8 |
from utils import Forges
|
6 |
|
9 |
|
7 |
class OSProject(models.Model):
|
10 |
class OSProject(models.Model):
|
|
... |
|
... |
9 |
Must be the same name of the Django app
|
12 |
Must be the same name of the Django app
|
10 |
"""
|
13 |
"""
|
11 |
name = models.CharField(max_length=200)
|
14 |
name = models.CharField(max_length=200)
|
12 |
instance = models.OneToOneField('analysis.Instance', related_name='actual_instance', primary_key=True)
|
15 |
instance = models.OneToOneField('analysis.Instance', related_name='actual_instance', primary_key=True)
|
13 |
|
16 |
|
14 |
def __unicode__(self):
|
17 |
def __str__(self):
|
15 |
return self.name + " - " + self.instance.name
|
18 |
return self.name + " - " + self.instance.name
|
16 |
|
19 |
|
17 |
def getProjectInfo(self):
|
20 |
def getInstanceInfo(self):
|
18 |
osprojectforge_info = {}
|
21 |
'''
|
|
|
22 |
Part of the required interface
|
|
|
23 |
i is a dictionary; each source information is withing the source name key, e.g.
|
|
|
24 |
i['FM']
|
|
|
25 |
i['OHLOH']
|
|
|
26 |
i['FSF']
|
|
|
27 |
i['GC']
|
|
|
28 |
i['GH']
|
|
|
29 |
...
|
|
|
30 |
Some information is extracted from specific sources and made available at root level; e.g.
|
|
|
31 |
i['days'] number of days since the project has been registered; it is calculated using i['FM']['date_added'] or i['OHLOH']['created_at']
|
|
|
32 |
...
|
|
|
33 |
'''
|
|
|
34 |
i = {}
|
19 |
for ospf in self.osprojectforge_set.all():
|
35 |
for ospf in self.osprojectforge_set.all():
|
20 |
osprojectforge_info[ospf.forge.name] = ospf.getProjectInfo()
|
36 |
i[ospf.forge.name] = ospf.getProjectInfo()
|
21 |
return osprojectforge_info
|
37 |
# From now on you find heuristics that try to reasonably define a single value where you have several sources of information
|
|
|
38 |
# e.g. project is created 1/1/2012 according to Github and 4/2/2007 according to FSF; the heuristic will choose the remotest date
|
|
|
39 |
|
|
|
40 |
# we need a name to search on search engines
|
|
|
41 |
if self.instance.name_for_search <> "":
|
|
|
42 |
i['name'] = self.instance.name_for_search
|
|
|
43 |
else:
|
|
|
44 |
i['name'] = self.name
|
|
|
45 |
|
|
|
46 |
# some searches on search engines have to be restricted to project site; let's try to guess it
|
|
|
47 |
# the order is given by a heuristic based on data reliability
|
|
|
48 |
i['homepage'] = ""
|
|
|
49 |
try: i['homepage'] = i['FSF']['real_url']
|
|
|
50 |
except: pass
|
|
|
51 |
try: i['homepage'] = i['GH']['homepage']
|
|
|
52 |
except: pass
|
|
|
53 |
try: i['homepage'] = i['FM']['url_homepage']
|
|
|
54 |
except: pass
|
|
|
55 |
try: i['homepage'] = i['OHLOH']['homepage_url']
|
|
|
56 |
except: pass
|
|
|
57 |
|
|
|
58 |
if i['homepage'] <> "":
|
|
|
59 |
try:
|
|
|
60 |
i['siteforsearchengine'] = urlparse(i['homepage']).netloc
|
|
|
61 |
if i['siteforsearchengine'][:4] == "www.":
|
|
|
62 |
i['siteforsearchengine'] = i['siteforsearchengine'][4:]
|
|
|
63 |
except: i['siteforsearchengine'] = ""
|
|
|
64 |
|
|
|
65 |
# default to -1 e.g. no value; the oldest creation dates wins; GC and GH have no info; FSF released_on seems to have the same semantic
|
|
|
66 |
i['days'] = -1
|
|
|
67 |
try:
|
|
|
68 |
i['OHLOH']['days'] = (datetime.today() - datetime.strptime(i['OHLOH']['created_at'], '%Y-%m-%dT%H:%M:%SZ')).days
|
|
|
69 |
if i['OHLOH']['days'] > i['days']: i['days'] = i['OHLOH']['days']
|
|
|
70 |
except: pass
|
|
|
71 |
try:
|
|
|
72 |
i['FM']['days'] = (datetime.today() - datetime.strptime(i['FM']['date_added'], '%Y-%m-%d %H:%M:%S\n')).days
|
|
|
73 |
if i['FM']['days'] > i['days']: i['days'] = i['FM']['days']
|
|
|
74 |
except: pass
|
|
|
75 |
try:
|
|
|
76 |
i['FSF']['released_on'] = (date.today() - i['FSF']['released_on']).days
|
|
|
77 |
if i['FSF']['days'] > i['days']: i['days'] = i['FSF']['days']
|
|
|
78 |
except: pass
|
|
|
79 |
|
|
|
80 |
return i
|
|
|
81 |
|
22 |
|
82 |
|
23 |
class Forge(models.Model):
|
83 |
class Forge(models.Model):
|
24 |
name = models.CharField(max_length=50)
|
84 |
name = models.CharField(max_length=50)
|
25 |
url = models.CharField(max_length=200)
|
85 |
url = models.CharField(max_length=200)
|
26 |
os_projects = models.ManyToManyField(OSProject, through='OSProjectForge', blank=True)
|
86 |
os_projects = models.ManyToManyField(OSProject, through='OSProjectForge', blank=True)
|
27 |
def __unicode__(self):
|
87 |
def __str__(self):
|
28 |
return self.name + " - " + self.url
|
88 |
return self.name + " - " + self.url
|
29 |
|
89 |
|
30 |
class OSProjectForge(models.Model):
|
90 |
class OSProjectForge(models.Model):
|
31 |
name = models.CharField(max_length=200)
|
91 |
name = models.CharField(max_length=200)
|
32 |
forge = models.ForeignKey(Forge)
|
92 |
forge = models.ForeignKey(Forge)
|
33 |
os_project = models.ForeignKey(OSProject)
|
93 |
os_project = models.ForeignKey(OSProject)
|
34 |
identifier_in_forge = models.CharField(max_length=200)
|
94 |
identifier_in_forge = models.CharField(max_length=200)
|
35 |
datasource_id = models.IntegerField()
|
95 |
datasource_id = models.IntegerField()
|
36 |
def __unicode__(self):
|
96 |
def __str__(self):
|
37 |
return self.name + " - " + self.forge.name
|
97 |
return self.name + " - " + self.forge.name
|
38 |
def getProjectInfo(self):
|
98 |
def getProjectInfo(self):
|
39 |
if self.forge.id == Forges.OHLOH:
|
99 |
if self.forge.id == Forges.OHLOH:
|
40 |
osprojectforge_info = OhlohProxy.getProjectInfo(self.identifier_in_forge)
|
100 |
osprojectforge_info = OhlohProxy.getProjectInfo(self.identifier_in_forge)
|
41 |
if self.forge.id == Forges.FC:
|
101 |
if self.forge.id == Forges.FC:
|