Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parameterize the languages #6

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions data_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

class DataFilter:

def __init__(self, file_extensions: List[str], path_prefix: str, keyword: str):
self.file_extensions = file_extensions
def __init__(self, languages: List[str], path_prefix: str, keyword: str):
self.languages = languages
self.path_prefix = path_prefix
self.keyword = keyword

def matches_file_extensions(self, path: str) -> bool:
for ext in self.file_extensions:
if path.endswith(ext):
for ext in self.languages:
if path.endswith(f".{ext.lower()}"):
return True
return False

Expand Down
44 changes: 21 additions & 23 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@


class App:
def __init__(self, file_extensions: List[str], path_prefix: str, keyword: str):
def __init__(self, languages: List[str], path_prefix: str, keyword: str):
self.client = GithubClient()
self.data_filter = DataFilter(file_extensions=file_extensions,
self.data_filter = DataFilter(languages=languages,
path_prefix=path_prefix, keyword=keyword)
self.commit_cache = SingleFileCache(location=COMMIT_CACHE_FILE)
self.repo_cache = MultiFileCache(location=REPO_CACHE_FILE)
Expand All @@ -45,13 +45,12 @@ def get_repository_by_commit(self, repository, commit):


def main(args):
file_extensions = [
".java",
".groovy"
languages = [
"groovy"
]

app = App(
file_extensions=file_extensions,
languages=languages,
path_prefix="instrumentation/",
keyword="test"
)
Expand All @@ -67,30 +66,29 @@ def main(args):
commit=commit
)
count = count_by_file_extension(files=repo_files["files"],
file_extensions=file_extensions)
languages=languages)
if count:
result[snapshot] = {
"date": snapshot,
"java": count[".java"],
"groovy": count[".groovy"]
}
result[snapshot]["date"] = snapshot
for language in languages:
result[snapshot][language] = count[language]
except Exception as e:
print(f"Error for {snapshot}, {e}")

dates = []
java_counts = []
groovy_counts = []

language_counts = {}

for item in result.values():
date = item["date"][:10]
java_count = item["java"]
groovy_count = item["groovy"]
dates.append(date)
java_counts.append(java_count)
groovy_counts.append(groovy_count)

plt.plot(dates, java_counts, label='Java')
plt.plot(dates, groovy_counts, label='Groovy')
dates.append(item["date"][:10])
for language in languages:
try:
language_counts[language].append(item[language])
except KeyError:
language_counts[language] = [item[language]]

for lang, counts in language_counts.items():
plt.plot(dates, counts, label=lang.capitalize())

plt.xlabel('Date')
plt.ylabel('Count')
plt.title('Test Classes by Lang in Instrumentation Directory')
Expand Down
10 changes: 5 additions & 5 deletions tests/test_data_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class ParseDataTestCase(unittest.TestCase):

def __init__(self, *args, **kwargs):
self.file_extensions = [
".java",
".groovy"
self.languages = [
"java",
"groovy"
]
super(ParseDataTestCase, self).__init__(*args, **kwargs)

Expand Down Expand Up @@ -84,7 +84,7 @@ def test_filters_payload_to_expected_files_based_on_criteria(self):
"""
data = json.loads(test_json)

data_filter = DataFilter(file_extensions=self.file_extensions,
data_filter = DataFilter(languages=self.languages,
path_prefix="instrumentation/", keyword="test")

test = data_filter.parse_data(payload=data)
Expand All @@ -111,7 +111,7 @@ def test_given_url_with_different_case_than_keyword_still_filters_correctly(self
"""
data = json.loads(payload)

data_filter = DataFilter(file_extensions=self.file_extensions,
data_filter = DataFilter(languages=self.languages,
path_prefix="instrumentation/", keyword="test")

test = data_filter.parse_data(payload=data)
Expand Down
16 changes: 8 additions & 8 deletions tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ def test_count_by_file_extension(self):
"test6.txt"
]

extensions = [
".java",
".groovy",
".txt"
languages = [
"java",
"groovy",
"txt"
]

result = count_by_file_extension(files, extensions)
self.assertEqual(3, result['.java'])
self.assertEqual(2, result['.groovy'])
self.assertEqual(1, result['.txt'])
result = count_by_file_extension(files, languages)
self.assertEqual(3, result['java'])
self.assertEqual(2, result['groovy'])
self.assertEqual(1, result['txt'])

7 changes: 4 additions & 3 deletions utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ def get_dates_between(start_date_str, end_date, interval):
return date_list


def count_by_file_extension(files: List[str], file_extensions: List[str]) -> dict:
def count_by_file_extension(files: List[str], languages: List[str]) -> dict:
file_counts = defaultdict(int)
for file in files:
for ext in file_extensions:
if file.endswith(ext):
for ext in languages:
extension = f".{ext.lower()}"
if file.endswith(extension):
file_counts[ext] += 1
return file_counts