Skip to content

Commit f71cab1

Browse files
committed
new methods
- addFilesByWildCard() - removed file variable from init - use addFile() instead - getInsights() for share score insights WIP
1 parent 5573004 commit f71cab1

3 files changed

Lines changed: 37 additions & 20 deletions

File tree

demo.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,18 @@
66
from dotenv import load_dotenv
77
load_dotenv()
88

9-
program_files = [
10-
"testfiles/test_python.py",
11-
"testfiles/test_python3.py",
12-
"testfiles/test_python2.py"
13-
]
14-
15-
# program_files = [
16-
# "submission/Q1-Animesh.vb",
17-
# "submission/Q1-Priyankan.vb",
18-
# ]
199
language = "python"
2010
userid = os.environ["USER_ID"]
2111

2212

23-
moss = plagcheck.check(program_files, language, userid)
13+
moss = plagcheck.check(language, userid)
14+
15+
moss.addFilesByWildCard("testfiles/test_python*.py")
16+
17+
# or moss.addFile("testfiles/test_python.py")
2418

25-
# cheat.addBaseCode("submission/a01.py")
26-
# cheat.addBaseCode("submission/test_student.py")
2719
moss.submit()
2820

2921
print(moss.getHomePage())
30-
pprint.pprint(moss.getResults())
22+
pprint.pprint(moss.getResults())
23+
pprint.pprint(moss.getInsights())

plagcheck/plagcheck.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import urllib.request
44
from concurrent.futures import ThreadPoolExecutor
55
from typing import List, Tuple
6-
6+
import collections
77
import mosspy
88
from bs4 import BeautifulSoup as bs
99

@@ -48,10 +48,9 @@ class check:
4848
- Moss User ID (str)
4949
"""
5050

51-
def __init__(self, files: list, lang: str, user_id: str):
51+
def __init__(self, lang: str, user_id: str):
5252

5353
self.__user_id = user_id
54-
self.files = files
5554
languages = mosspy.Moss.languages
5655
if lang not in languages:
5756
raise ValueError(f"{lang} is not a supported language {languages}")
@@ -104,14 +103,18 @@ def __get_line_numbers(self, url: str) -> List[List[str]]:
104103
list_of_line_nos.append(matched_lines)
105104
return list_of_line_nos
106105

106+
def addFilesByWildCard(self, file):
107+
self.__moss.addFilesByWildcard(file)
108+
109+
def addFile(self, file):
110+
self.__moss.addFile(file)
111+
107112
def addBaseCode(self, base_file: str):
108113
"""Add basefile"""
109114
self.__moss.addBaseFile(base_file)
110115

111116
def submit(self):
112117
"""Submit files to the Moss Server"""
113-
for item in self.files:
114-
self.__moss.addFile(item)
115118
url = self.__moss.send()
116119

117120
self.home_url = url
@@ -125,3 +128,22 @@ def getResults(self) -> Tuple[str, Results]:
125128
self.moss_results = self.__extract_info()
126129

127130
return self.moss_results
131+
132+
def getInsights(self):
133+
"""Share Score Insights WIP"""
134+
similar_code_files = []
135+
for result in self.moss_results:
136+
similar_code_files.append(result['file1'])
137+
similar_code_files.append(result['file2'])
138+
139+
# count of files which are similar
140+
share_score = collections.Counter(similar_code_files)
141+
142+
# code which has been similar to most of the files
143+
distributor_score = max(share_score.values())
144+
145+
for key, value in share_score.items():
146+
if value == distributor_score:
147+
distributor = key
148+
149+
return dict(share_score)

plagcheck/plagcheck_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ def test_check():
77
program_files = ["testfiles/test_python.py", "testfiles/test_python3.py"]
88
language = "python"
99
userid = "1"
10-
temp = plagcheck.check(program_files, language, userid)
10+
temp = plagcheck.check(language, userid)
11+
temp.addFile("testfiles/test_python.py")
12+
temp.addFile("testfiles/test_python3.py")
1113
temp.submit()
1214
results = temp.getResults()
1315

0 commit comments

Comments
 (0)