Skip to content

Commit

Permalink
updated contextsize to parentssize, improved algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
rmeloca committed Oct 7, 2017
1 parent 5a3e0c4 commit 79ebb3c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 10 deletions.
71 changes: 62 additions & 9 deletions ecosystemDataManager/ecosystemDataManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,30 @@ def calculateGlobalRegularityMean(self):
print("[" + str(evaluated) + "/" + str(size) + "]", version, "\t", "{" + str(len(version.getDependencies())) + "}", "\t", localRegularityRate, "->", globalRegularityMean)
evaluated += 1

def calculateParentsSize(self, versionIndex, start = True):
if start:
self.visited = []
elif versionIndex in self.visited:
return 0
else:
self.visited.append(versionIndex)
versionsHasContextSize = self.get("VersionsHasContextSize")
if versionsHasContextSize[versionIndex]:
return versionsHasContextSize[versionIndex]
versionsHasOcurrences = self.get("VersionsHasOcurrences")
parentsIndexes = versionsHasOcurrences[versionIndex]
parentsSize = len(parentsIndexes)
for parentIndex in parentsIndexes:
parentsSize += self.calculateParentsSize(parentIndex, False)
versionsHasContextSize[versionIndex] = parentsSize
return parentsSize

def calculateContextSize(self):
packages = self.getPackages()
evaluated = 0
size = len(packages)
for package in packages:
for version in package.getVersions():
contextSize = version.calculateContextSize()
print("[" + str(evaluated) + "/" + str(size) + "]", version, "\t", contextSize)
evaluated += 1
versionsHasOcurrences = self.get("VersionsHasOcurrences")
size = len(versionsHasOcurrences)
for i in range(len(versionsHasOcurrences)):
contextSize = self.calculateParentsSize(i)
print("[" + str(i) + "/" + str(size) + "]", contextSize)

def calculateGlobalRegularityMetrics(self):
packages = self.getPackages()
Expand Down Expand Up @@ -271,7 +286,7 @@ def getMostPopularLicenses(self, size = None):
for version in versionsHasLicenses:
for license in version:
try:
distribution[license] = distribution[license] + 1
distribution[license] += 1
except Exception as e:
distribution[license] = 1
mostPopularLicenses = sorted(distribution.items(), key=lambda x: x[1], reverse = True)
Expand Down Expand Up @@ -324,6 +339,41 @@ def proportion(self):
print("iregularDependencies", iregularDependencies)
print("proportion", iregularDependencies / dependenciesSize)

def groupsProportion(self):
versionsHasLicenses = self.get("LicensesHasGroup")
versionsHasDatetime = self.get("VersionsHasDatetime")
distribution = {}
distribution["-1"] = 0
for i in range(len(versionsHasLicenses)):
version = versionsHasLicenses[i]
datetime = versionsHasDatetime[i]
if not datetime:
continue
if not version:
distribution["-1"] += 1
for group in version:
try:
distribution[group] += 1
except Exception as e:
distribution[group] = 1
return distribution

def licensesProportion(self):
versionsHasLicenses = self.get("VersionsHasLicenses")
versionsHasDatetime = self.get("VersionsHasDatetime")
distribution = {}
for i in range(len(versionsHasLicenses)):
version = versionsHasLicenses[i]
datetime = versionsHasDatetime[i]
if not datetime:
continue
size = len(version)
try:
distribution[size] += 1
except Exception as e:
distribution[size] = 1
return distribution

def getMostPopularIregularPackages(self, size = None):
iregularPackages = [package for package in self.getMostPopularPackages() if package.isIregular()]
if size:
Expand Down Expand Up @@ -354,6 +404,9 @@ def getGlobalRegularityRates(self):
def getGlobalRegularityMeans(self):
return self.get("VersionsHasGlobalRegularityMean")

def getLicensesPerVersion(self):
return self.get("VersionsHasLicenses")

def __str__(self):
return self.ecosystem + " at " + self.home

Expand Down
2 changes: 1 addition & 1 deletion ecosystemDataManager/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def calculateGlobalRegularityRate(self, start = True):
return globalRegularityRate

def calculateContextSize(self):
contextSize = len(self.getContext())
contextSize = len(self.getParents())
self.set("VersionsHasContextSize", contextSize)
return contextSize

Expand Down

0 comments on commit 79ebb3c

Please sign in to comment.