示例#1
0
    def mergeData(self, repoName: str, trafficType: str):
        """Merge traffic type for a repo with the traffic cache

		Args:
			repoName (str): name of the repo to get traffic info for
			trafficType (str): type of traffic. views | clones
		"""
        if repoName not in self.data:
            printf.logPrint(f"{repoName} does not exist - creating",
                            LogType.WARNING)
            self.data[repoName] = {}
        if trafficType not in self.data[repoName]:
            printf.logPrint(f"{trafficType} does not exist - creating",
                            LogType.WARNING)
            userRepoTrafficType = [{
                "timestamp": "2000-01-01T00:00:00Z",
                "uniques": 0
            }]
        else:
            userRepoTrafficType = self.data[repoName][trafficType]

        rawTraffic = getRepoTraffic(repoName, trafficType)
        days = (getRepoTraffic(repoName, trafficType)[trafficType]
                if trafficType in rawTraffic else [])
        for day in days:
            if getDatetime(userRepoTrafficType[-1]["timestamp"]) < getDatetime(
                    day["timestamp"]):
                userRepoTrafficType.append({
                    "timestamp": day["timestamp"],
                    "uniques": day["uniques"]
                })

        self.data[repoName][trafficType] = userRepoTrafficType
def getListOfAliveForks(
	repoData: dict[Any, Any], lifespan: int, enableNewer: bool = True
) -> tuple[list[Any], list[Any]]:
	"""Get list of forked repos that are alive and newer than the source repo."""
	forkedRepos = getListOfForks(repoData["owner"]["login"], repoData["name"], lifespan=lifespan)
	aliveRepos = []
	for forkedRepo in forkedRepos:
		isAlive = sourceAlive(forkedRepo, lifespan)
		isNewer = getDatetime(forkedRepo["pushedAt"]) > getDatetime(repoData["pushedAt"])
		if (isAlive and isNewer) or (isAlive and not enableNewer):
			aliveRepos.append(forkedRepo)
	return aliveRepos, forkedRepos
def getListOfAliveForks(
        repoData: dict[Any, Any],
        lifespan: int,
        enableNewer: bool = True) -> tuple[list[Any], list[Any]]:
    """Get list of forked repos that are alive and newer than the source repo."""
    forkedRepos = getListOfRepos(repoData["full_name"])
    aliveRepos = []
    for forkedRepo in forkedRepos:
        forkedRepoPushedAt = getDatetime(forkedRepo["pushed_at"])
        isAlive = forkedRepoPushedAt + datetime.timedelta(
            weeks=lifespan) > datetime.datetime.now()
        isNewer = forkedRepoPushedAt > getDatetime(repoData["pushed_at"])
        if (isAlive and isNewer) or (isAlive and not enableNewer):
            aliveRepos.append(forkedRepo)
    return aliveRepos, forkedRepos
def sourceAlive(repoData: dict[Any, Any], lifespan: int) -> bool:
    """Is source repo alive?"""
    if "pushed_at" in repoData:
        pushedAt = repoData["pushed_at"]
    else:
        pushedAt = repoData["pushedAt"]
    return getDatetime(pushedAt) + datetime.timedelta(
        weeks=lifespan) > datetime.datetime.now()
def sourceAlive(repoData: dict[Any, Any], lifespan: int) -> bool:
	"""Is source repo alive?"""
	return getDatetime(repoData["pushedAt"]) > (
		datetime.datetime.now() - datetime.timedelta(weeks=lifespan)
	)